Skip to content

Commit 2f20204

Browse files
nodeselectorCopilot
andcommitted
Return RefError from uses parsers by default
ParseActionRef and ParseReusableWorkflowRef now return (nil, *RefError) for a repository-shaped uses: value whose ref is invalid, instead of nil. Drop the separate Strict variants. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1c2b0ee commit 2f20204

7 files changed

Lines changed: 39 additions & 56 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ canonicalized to lowercase) or a short tag or branch name. A dependency's
124124
- When the pin key's `REF` is a name, `ref` must equal it exactly (names are
125125
case-sensitive). When the pin key's `REF` is a commit SHA, `ref` records the
126126
tag or branch that commit was found on.
127-
- Consumers resolve `ref` only by exact lookup of `refs/tags/<ref>` or
127+
- `ref` is resolved only by exact lookup of `refs/tags/<ref>` or
128128
`refs/heads/<ref>`, never as a revision expression.
129129

130130
The Go API exposes these as typed values (`PinRef`, `RefName`, `CommitID`)
131-
rather than strings. `ParseActionRefStrict` and
132-
`ParseReusableWorkflowRefStrict` return an error for a `uses:` value whose ref
133-
is invalid, so callers can fail closed instead of skipping it.
131+
rather than strings. `ParseActionRef` and `ParseReusableWorkflowRef` return a
132+
`*RefError` for a `uses:` value whose ref is invalid; treat it as an error
133+
rather than skipping the value.
134134

135135
The `hostname` field is optional in v0.0.3. An omitted `hostname` binds the
136136
pin to the home host: the tenant (`<tenant>.ghe.com`) on a GHE.com

‎go/pkg/lockfile/doc.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
// Dependencies maps resolve every pinned action for a workflow.
66
//
77
// [ParseActionRef] parses a single workflow `uses:` string into its
8-
// owner/repo/ref components, returning nil for anything that is not a
9-
// repository action. [ParseReusableWorkflowRef] is its mirror for the
8+
// owner/repo/ref components, returning (nil, nil) for anything that is not a
9+
// repository action and a *[RefError] for a repository action whose ref is
10+
// invalid. [ParseReusableWorkflowRef] is its mirror for the
1011
// reusable-workflow shape (owner/repo/.github/workflows/name.yml@ref);
1112
// [IsLocalReusableWorkflow] handles the local ./.github/workflows/... shape.
12-
// Their Strict variants return an error when the ref is invalid, so callers can
13-
// fail closed instead of skipping the value.
1413
//
1514
// The text after "@" is parsed exactly once, by [ParsePinRef], into a
1615
// [PinRef]: either a full commit SHA ([CommitID]) or a validated tag or branch

‎go/pkg/lockfile/pinref_test.go‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var validRefNames = []string{
2424
"release@2024",
2525
"a@b",
2626
"HEAD",
27-
"v6.1.0-1-g373d742f768e", // describe-shaped; policy belongs to consumers
28-
"pull/1/head",
27+
"release-2024.1-rc.3",
28+
"users/alice/topic",
2929
"11bd71901bbe5b1630ceea73d27597364c9af68", // 39 hex
3030
"11bd71901bbe5b1630ceea73d27597364c9af6833", // 41 hex
3131
"Main",
@@ -271,8 +271,8 @@ func TestRefName_YAMLRoundTrip(t *testing.T) {
271271
assert.NotContains(t, string(out), "ref:")
272272
}
273273

274-
func TestParseActionRefStrict(t *testing.T) {
275-
a, err := ParseActionRefStrict("actions/checkout@v4")
274+
func TestParseActionRef_InvalidRef(t *testing.T) {
275+
a, err := ParseActionRef("actions/checkout@v4")
276276
require.NoError(t, err)
277277
require.NotNil(t, a)
278278
assert.Equal(t, RefKindName, a.Ref.Kind())
@@ -285,30 +285,29 @@ func TestParseActionRefStrict(t *testing.T) {
285285
"actions/checkout@",
286286
"actions/cache/save@-x",
287287
} {
288-
a, err := ParseActionRefStrict(in)
288+
a, err := ParseActionRef(in)
289289
assert.Nilf(t, a, "%q", in)
290290
var re *RefError
291291
assert.Truef(t, errors.As(err, &re), "%q: %v", in, err)
292-
assert.Nilf(t, ParseActionRef(in), "%q", in)
293292
}
294293

295294
for _, in := range []string{"./local", "docker://alpine", "actions/checkout", "a/b@${{ x }}", "o/r/.github/workflows/ci.yml@main~1"} {
296-
a, err := ParseActionRefStrict(in)
295+
a, err := ParseActionRef(in)
297296
assert.Nilf(t, a, "%q", in)
298297
assert.NoErrorf(t, err, "%q", in)
299298
}
300299
}
301300

302-
func TestParseReusableWorkflowRefStrict(t *testing.T) {
303-
r, err := ParseReusableWorkflowRefStrict("o/r/.github/workflows/ci.yml@v1")
301+
func TestParseReusableWorkflowRef_InvalidRef(t *testing.T) {
302+
r, err := ParseReusableWorkflowRef("o/r/.github/workflows/ci.yml@v1")
304303
require.NoError(t, err)
305304
require.NotNil(t, r)
306305

307-
r, err = ParseReusableWorkflowRefStrict("o/r/.github/workflows/ci.yml@main~1")
306+
r, err = ParseReusableWorkflowRef("o/r/.github/workflows/ci.yml@main~1")
308307
assert.Nil(t, r)
309308
assert.ErrorIs(t, err, ErrRefInvalidName)
310309

311-
r, err = ParseReusableWorkflowRefStrict("o/r@main~1")
310+
r, err = ParseReusableWorkflowRef("o/r@main~1")
312311
assert.Nil(t, r)
313312
assert.NoError(t, err)
314313
}
@@ -437,13 +436,13 @@ func FuzzParsePin(f *testing.F) {
437436
})
438437
}
439438

440-
func FuzzParseActionRefStrict(f *testing.F) {
439+
func FuzzParseActionRef(f *testing.F) {
441440
f.Add("actions/checkout@v4")
442441
f.Add("actions/cache/save@v4")
443442
f.Add("o/r/.github/workflows/ci.yml@main")
444443
f.Add("a/b@main~1")
445444
f.Fuzz(func(t *testing.T, s string) {
446-
a, err := ParseActionRefStrict(s)
445+
a, err := ParseActionRef(s)
447446
if err != nil {
448447
require.Nil(t, a)
449448
return

‎go/pkg/lockfile/schema_gen.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)