Keep lockfiles that record a tag containing @ loadable (#217) · github/gh-actions-lock@1370c18 · GitHub
Skip to content

Commit 1370c18

Browse files
Keep lockfiles that record a tag containing @ loadable (#217)
* Keep a full-SHA use whose tag contains @ An entry may record a tag such as predicate@2.0.0, which the Actions backend accepts as an entry ref, so loading a lockfile that records one must keep working. Only a `uses:` can't name it: reverse lookup now keeps such a use's SHA instead of rewriting it to the tag. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Cover a composite's SHA-pinned child that records a tag containing @ Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 748cba9 commit 1370c18

6 files changed

Lines changed: 58 additions & 5 deletions

File tree

‎cmd/gh-actions-lock/command_test.go‎

Lines changed: 25 additions & 0 deletions

‎internal/ghapi/refname.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func fullSHAShaped(s string) bool {
7272
}
7373

7474
// AcceptedRefName reports whether name is a ref name the Actions backend
75-
// accepts: a valid ref name that isn't shaped like `git describe` output and
76-
// has no @, which the backend's `uses:` grammar rejects.
75+
// accepts: a valid ref name that isn't shaped like `git describe` output.
7776
func AcceptedRefName(name string) bool {
78-
return ValidRefName(name) && !describeSuffix.MatchString(name) && !strings.Contains(name, "@")
77+
return ValidRefName(name) && !describeSuffix.MatchString(name)
7978
}

‎internal/ghapi/refname_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestAcceptedRefName(t *testing.T) {
3535
{"v1-G1234", true}, // uppercase G
3636
{"v1-g1234-rc", true},
3737
{"main~1", false},
38-
{"rel@1", false},
38+
{"predicate@2.0.0", true},
3939
}
4040
for _, tt := range tests {
4141
assert.Equal(t, tt.want, AcceptedRefName(tt.name), tt.name)

‎internal/lockfile/state_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,11 @@ func TestLoadStateCanonicalizesFullSHAs(t *testing.T) {
10921092
require.ErrorIs(t, err, ErrCorruptLockfile)
10931093
assert.ErrorContains(t, err, "spell one full SHA in different cases")
10941094
})
1095+
t.Run("keeps a recorded tag containing @", func(t *testing.T) {
1096+
store, err := load(t, "o/comp@v1", entry("o/comp@v1", "v1", upper, "o/child@"+child), entry("o/child@"+child, "predicate@2.0.0", child, ""))
1097+
require.NoError(t, err)
1098+
assert.Equal(t, "predicate@2.0.0", store.File().Dependencies["o/child@"+strings.ToLower(child)].Ref)
1099+
})
10951100
t.Run("rejects a ref containing @", func(t *testing.T) {
10961101
_, err := load(t, "o/comp@rel@1", entry("o/comp@rel@1", "rel@1", lower, ""))
10971102
require.ErrorIs(t, err, ErrCorruptLockfile)

‎internal/resolve/reverse_lookup.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ func (r *Resolver) ReverseLookup(ctx context.Context, deps []dep.Dependency) (ma
384384
newRef = branch
385385
}
386386
}
387-
if newRef == "" || newRef == d.Ref {
387+
// An entry may record a ref containing @, but `uses:` can't name
388+
// one, so such a use keeps its SHA.
389+
if newRef == "" || newRef == d.Ref || strings.Contains(newRef, "@") {
388390
continue
389391
}
390392
rewrites[d.NWO+"@"+d.Ref] = d.NWO + "@" + newRef

‎internal/resolve/reverse_lookup_test.go‎

Lines changed: 22 additions & 0 deletions

0 commit comments

Comments
 (0)