Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit c90c9a0

Browse files
author
Neal
authored
Merge pull request #12 from go-vela/bug/hardcode
Resolve not hardcoding source system environment variables
2 parents d39222c + 5d8e37e commit c90c9a0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

compiler/native/environment.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ package native
66

77
import (
88
"fmt"
9+
"net/url"
910
"strings"
1011

1112
"github.com/go-vela/types/constants"
1213
"github.com/go-vela/types/library"
1314
"github.com/go-vela/types/yaml"
15+
16+
"github.com/sirupsen/logrus"
1417
)
1518

1619
// EnvironmentStages injects environment variables
@@ -71,6 +74,14 @@ func (c *client) EnvironmentSteps(s yaml.StepSlice) (yaml.StepSlice, error) {
7174
func environment(b *library.Build, r *library.Repo, u *library.User) map[string]string {
7275
workspace := fmt.Sprintf("/home/%s_%s_%d", r.GetOrg(), r.GetName(), b.GetNumber())
7376

77+
// TODO: (hack) consider making a metadata struct
78+
// that gets populated in server and then passed
79+
// from the server to the compiler.
80+
uri, err := url.Parse(r.GetLink())
81+
if err != nil {
82+
logrus.Errorf("unable to parse link for repo %s", r.GetFullName())
83+
}
84+
7485
env := map[string]string{
7586
// build specific environment variables
7687
"BUILD_BRANCH": b.GetBranch(),
@@ -97,14 +108,14 @@ func environment(b *library.Build, r *library.Repo, u *library.User) map[string]
97108
"VELA_ADDR": "TODO",
98109
"VELA_CHANNEL": "vela",
99110
"VELA_DATABASE": "postgres",
100-
"VELA_DISTRIBUTION": "linux",
111+
"VELA_DISTRIBUTION": "TODO",
101112
"VELA_HOST": "TODO",
102-
"VELA_NETRC_MACHINE": "github.com",
113+
"VELA_NETRC_MACHINE": uri.Host,
103114
"VELA_NETRC_PASSWORD": u.GetToken(),
104115
"VELA_NETRC_USERNAME": "x-oauth-basic",
105116
"VELA_QUEUE": "redis",
106-
"VELA_RUNTIME": "docker",
107-
"VELA_SOURCE": "https://github.com",
117+
"VELA_RUNTIME": "TODO",
118+
"VELA_SOURCE": fmt.Sprintf("%s://%s", uri.Scheme, uri.Host),
108119
"VELA_VERSION": "TODO",
109120
"VELA_WORKSPACE": workspace,
110121
"CI": "vela",

compiler/native/environment_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ func TestNative_environment(t *testing.T) {
185185
"VELA_ADDR": "TODO",
186186
"VELA_CHANNEL": "vela",
187187
"VELA_DATABASE": "postgres",
188-
"VELA_DISTRIBUTION": "linux",
188+
"VELA_DISTRIBUTION": "TODO",
189189
"VELA_HOST": "TODO",
190-
"VELA_NETRC_MACHINE": "github.com",
190+
"VELA_NETRC_MACHINE": "",
191191
"VELA_NETRC_PASSWORD": u.GetToken(),
192192
"VELA_NETRC_USERNAME": "x-oauth-basic",
193193
"VELA_QUEUE": "redis",
194-
"VELA_RUNTIME": "docker",
195-
"VELA_SOURCE": "https://github.com",
194+
"VELA_RUNTIME": "TODO",
195+
"VELA_SOURCE": "://",
196196
"VELA_VERSION": "TODO",
197197
"VELA_WORKSPACE": workspace,
198198
"CI": "vela",

0 commit comments

Comments
 (0)