tangled
alpha
login
or
join now
evan.jarrett.net
/
core
forked from
tangled.org/core
0
fork
atom
Monorepo for Tangled — https://tangled.org
0
fork
atom
overview
issues
pulls
pipelines
add TANGLED_REPO_HANDLE
evan.jarrett.net
2 months ago
eeddc679
8d7c41f4
verified
This commit was signed with the committer's
known signature
.
evan.jarrett.net
SSH Key Fingerprint:
SHA256:bznk0uVPp7XFOl67P0uTM1pCjf2A4ojeP/lsUE7uauQ=
+19
-9
3 changed files
expand all
collapse all
unified
split
spindle
models
pipeline_env.go
pipeline_env_test.go
server.go
+11
-1
spindle/models/pipeline_env.go
···
1
1
package models
2
2
3
3
import (
4
4
+
"context"
4
5
"strings"
5
6
6
7
"github.com/go-git/go-git/v5/plumbing"
7
8
"tangled.org/core/api/tangled"
9
9
+
"tangled.org/core/idresolver"
8
10
"tangled.org/core/workflow"
9
11
)
10
12
11
13
// PipelineEnvVars extracts environment variables from pipeline trigger metadata.
12
14
// These are framework-provided variables that are injected into workflow steps.
13
13
-
func PipelineEnvVars(tr *tangled.Pipeline_TriggerMetadata, pipelineId PipelineId, devMode bool) map[string]string {
15
15
+
// The resolver is used to resolve the handle from the DID.
16
16
+
func PipelineEnvVars(tr *tangled.Pipeline_TriggerMetadata, pipelineId PipelineId, devMode bool, res *idresolver.Resolver) map[string]string {
14
17
if tr == nil {
15
18
return nil
16
19
}
···
29
32
env["TANGLED_REPO_NAME"] = tr.Repo.Repo
30
33
env["TANGLED_REPO_DEFAULT_BRANCH"] = tr.Repo.DefaultBranch
31
34
env["TANGLED_REPO_URL"] = BuildRepoURL(tr.Repo, devMode)
35
35
+
36
36
+
// Resolve handle from DID
37
37
+
if res != nil {
38
38
+
if ident, err := res.ResolveIdent(context.Background(), tr.Repo.Did); err == nil && !ident.Handle.IsInvalidHandle() {
39
39
+
env["TANGLED_REPO_HANDLE"] = ident.Handle.String()
40
40
+
}
41
41
+
}
32
42
}
33
43
34
44
switch workflow.TriggerKind(tr.Kind) {
+7
-7
spindle/models/pipeline_env_test.go
···
26
26
Knot: "example.com",
27
27
Rkey: "123123",
28
28
}
29
29
-
env := PipelineEnvVars(tr, id, false)
29
29
+
env := PipelineEnvVars(tr, id, false, nil)
30
30
31
31
// Check standard CI variable
32
32
if env["CI"] != "true" {
···
88
88
Knot: "example.com",
89
89
Rkey: "123123",
90
90
}
91
91
-
env := PipelineEnvVars(tr, id, false)
91
91
+
env := PipelineEnvVars(tr, id, false, nil)
92
92
93
93
if env["TANGLED_REF"] != "refs/tags/v1.2.3" {
94
94
t.Errorf("Expected TANGLED_REF='refs/tags/v1.2.3', got '%s'", env["TANGLED_REF"])
···
120
120
Knot: "example.com",
121
121
Rkey: "123123",
122
122
}
123
123
-
env := PipelineEnvVars(tr, id, false)
123
123
+
env := PipelineEnvVars(tr, id, false, nil)
124
124
125
125
// Check ref variables for PR
126
126
if env["TANGLED_REF"] != "refs/heads/feature-branch" {
···
175
175
Knot: "example.com",
176
176
Rkey: "123123",
177
177
}
178
178
-
env := PipelineEnvVars(tr, id, false)
178
178
+
env := PipelineEnvVars(tr, id, false, nil)
179
179
180
180
// Check manual input variables
181
181
if env["TANGLED_INPUT_VERSION"] != "1.0.0" {
···
211
211
Knot: "example.com",
212
212
Rkey: "123123",
213
213
}
214
214
-
env := PipelineEnvVars(tr, id, true)
214
214
+
env := PipelineEnvVars(tr, id, true, nil)
215
215
216
216
// Dev mode should use http:// and replace localhost with host.docker.internal
217
217
expectedURL := "http://host.docker.internal:3000/did:plc:user123/my-repo"
···
225
225
Knot: "example.com",
226
226
Rkey: "123123",
227
227
}
228
228
-
env := PipelineEnvVars(nil, id, false)
228
228
+
env := PipelineEnvVars(nil, id, false, nil)
229
229
230
230
if env != nil {
231
231
t.Error("Expected nil env for nil trigger")
···
246
246
Knot: "example.com",
247
247
Rkey: "123123",
248
248
}
249
249
-
env := PipelineEnvVars(tr, id, false)
249
249
+
env := PipelineEnvVars(tr, id, false, nil)
250
250
251
251
// Should still have repo variables
252
252
if env["TANGLED_REPO_KNOT"] != "example.com" {
+1
-1
spindle/server.go
···
321
321
workflows := make(map[models.Engine][]models.Workflow)
322
322
323
323
// Build pipeline environment variables once for all workflows
324
324
-
pipelineEnv := models.PipelineEnvVars(tpl.TriggerMetadata, pipelineId, s.cfg.Server.Dev)
324
324
+
pipelineEnv := models.PipelineEnvVars(tpl.TriggerMetadata, pipelineId, s.cfg.Server.Dev, s.res)
325
325
326
326
for _, w := range tpl.Workflows {
327
327
if w != nil {