Skip to content

Commit 7eedad1

Browse files
committed
Fix CI job key matching reuse
1 parent efd97dd commit 7eedad1

5 files changed

Lines changed: 10 additions & 32 deletions

File tree

pkg/cmd/ci/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ func findLogsJobWithOptions(resp *civ1.GetRunStatusResponse, originalID, jobKey,
11281128
bestTier := 0
11291129
tierMatches := map[int][]jobCandidate{}
11301130
for _, c := range candidates {
1131-
if tier := matchJobKey(c.job.JobKey, jobKey); tier > 0 {
1131+
if tier := coreci.MatchJobKey(c.job.JobKey, jobKey); tier > 0 {
11321132
tierMatches[tier] = append(tierMatches[tier], c)
11331133
if bestTier == 0 || tier < bestTier {
11341134
bestTier = tier

pkg/cmd/ci/ssh.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/depot/cli/pkg/api"
13+
coreci "github.com/depot/cli/pkg/ci"
1314
"github.com/depot/cli/pkg/config"
1415
"github.com/depot/cli/pkg/helpers"
1516
civ1 "github.com/depot/cli/pkg/proto/depot/ci/v1"
@@ -211,7 +212,7 @@ func findJob(resp *civ1.GetRunStatusResponse, jobKey, originalID string) (*civ1.
211212
bestTier := 0
212213
tierMatches := map[int][]*civ1.JobStatus{}
213214
for _, j := range allJobs {
214-
if tier := matchJobKey(j.JobKey, jobKey); tier > 0 {
215+
if tier := coreci.MatchJobKey(j.JobKey, jobKey); tier > 0 {
215216
tierMatches[tier] = append(tierMatches[tier], j)
216217
if bestTier == 0 || tier < bestTier {
217218
bestTier = tier
@@ -277,28 +278,6 @@ func workflowErrorMessage(resp *civ1.GetRunStatusResponse) string {
277278
return ""
278279
}
279280

280-
// matchJobKey returns the match tier of userKey against the full jobKey.
281-
// Returns 0 for no match. Lower non-zero values are higher priority:
282-
//
283-
// 1 = exact match ("build" == "build")
284-
// 2 = suffix match ("_inline_0.yaml:build" ends with ":build")
285-
// 3 = segment match ("pr.yaml:bazel:build" contains ":bazel:" as a segment)
286-
func matchJobKey(jobKey, userKey string) int {
287-
if jobKey == userKey {
288-
return 1
289-
}
290-
if strings.HasSuffix(jobKey, ":"+userKey) {
291-
return 2
292-
}
293-
// Check if userKey appears as a complete colon-delimited segment anywhere
294-
// in the key. Handles reusable workflow keys like "pr.yaml:bazel:build"
295-
// where "bazel" is an intermediate segment.
296-
if strings.Contains(":"+jobKey+":", ":"+userKey+":") {
297-
return 3
298-
}
299-
return 0
300-
}
301-
302281
func printSSHInfo(sandboxID, sessionID, output string) error {
303282
if output == "json" {
304283
enc := json.NewEncoder(os.Stdout)

pkg/cmd/ci/ssh_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ci
33
import (
44
"testing"
55

6+
coreci "github.com/depot/cli/pkg/ci"
67
civ1 "github.com/depot/cli/pkg/proto/depot/ci/v1"
78
)
89

@@ -31,9 +32,9 @@ func TestMatchJobKey(t *testing.T) {
3132
}
3233

3334
for _, tt := range tests {
34-
got := matchJobKey(tt.jobKey, tt.userKey)
35+
got := coreci.MatchJobKey(tt.jobKey, tt.userKey)
3536
if got != tt.want {
36-
t.Errorf("matchJobKey(%q, %q) = %d, want %d", tt.jobKey, tt.userKey, got, tt.want)
37+
t.Errorf("MatchJobKey(%q, %q) = %d, want %d", tt.jobKey, tt.userKey, got, tt.want)
3738
}
3839
}
3940
}

pkg/proto/depot/testresults/v1/test_results.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/depot/testresults/v1/test_results.proto

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ enum TestResultStatus {
3737
}
3838

3939
message ReportTestResultsRequest {
40-
// Per-step identity key. Populated by the action from `key:` input, else
41-
// $GITHUB_ACTION, else "default". This scopes multiple reports within a
42-
// single owner. Must be non-empty.
40+
// Per-invocation identity key. This scopes multiple reports within a single
41+
// owner. Must be non-empty.
4342
string invocation_id = 1;
4443

4544
// One entry per JUnit XML file matched by the action's glob.

0 commit comments

Comments
 (0)