Advise --relock for composite-held exact tags behind their commit (#221) · github/gh-actions-lock@5a1469a · GitHub
Skip to content

Commit 5a1469a

Browse files
Advise --relock for composite-held exact tags behind their commit (#221)
Since --relock rebuilds composite closures from live manifests, it locks a composite-held exact tag at the tag's commit. Drop the advice that it only helps once the composite advances, and test the repair end to end. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a0a7edc commit 5a1469a

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 5 deletions

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,10 +2967,11 @@ func TestParity_RelockRepairsExactTagBehind(t *testing.T) {
29672967
}
29682968
}
29692969

2970-
// TestParity_ExactTagBehindInCompositeNamesHolder: a composite's exact-tag
2971-
// entry locked behind its tag blocks, and the advice names the composite.
2972-
// --relock can't repair it while the composite is unchanged.
2973-
func TestParity_ExactTagBehindInCompositeNamesHolder(t *testing.T) {
2970+
// TestParity_ExactTagBehindInCompositeRelocks: a composite's exact-tag
2971+
// entry locked behind its tag blocks. --relock rebuilds the composite's
2972+
// closure from its manifest, so it locks the tag's commit, and the result
2973+
// verifies.
2974+
func TestParity_ExactTagBehindInCompositeRelocks(t *testing.T) {
29742975
const rootSHA = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
29752976
reg := exactTagBehindRegistry(t, rootSHA)
29762977
path := writeTempWorkflow(t, "name: ci\non: push\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - uses: octo/root@v1\n")
@@ -2979,22 +2980,26 @@ func TestParity_ExactTagBehindInCompositeNamesHolder(t *testing.T) {
29792980
" uses:\n - 'actions/checkout@v7.0.1'\n" +
29802981
" 'actions/checkout@v7.0.1':\n ref: 'v7.0.1'\n commit: 'sha1-" + parityTestSHA + "'\n owner_id: 1\n repo_id: 1\n" +
29812982
"workflows:\n '.github/workflows/workflow.yml':\n - 'octo/root@v1'\n"
2982-
require.NoError(t, os.WriteFile(filepath.Join(".github", "workflows", "actions.lock"), []byte(lock), 0o600))
2983+
lockPath := filepath.Join(".github", "workflows", "actions.lock")
2984+
require.NoError(t, os.WriteFile(lockPath, []byte(lock), 0o600))
29832985

29842986
p, err := runParity(t, reg, "--verify", path)
29852987
require.ErrorIs(t, err, errSilent)
29862988
require.Len(t, p.Findings, 1, "%+v", p.Findings)
29872989
assert.Equal(t, "tag-commit-mismatch", p.Findings[0].Category)
2988-
assert.Equal(t, "upgrade or replace octo/root@v1; `gh actions-lock --relock` helps only if octo/root@v1 itself advances", p.Findings[0].Remediation)
2990+
assert.Equal(t, "run `gh actions-lock --relock` to lock the tag's commit", p.Findings[0].Remediation)
29892991

2990-
// The composite didn't move, so --relock keeps its recorded entry:
2991-
// the run blocks, writes nothing, and points only at the composite.
29922992
_, stderr, err := runCommandWithHTTP(t, reg, "--relock", "--no-interactive", path)
2993-
require.ErrorIs(t, err, errSilent, stderr)
2994-
assert.Contains(t, stderr, "upgrade octo/root@v1 to a version that locks actions/checkout@v7.0.1 at the tag's commit")
2995-
after, rerr := os.ReadFile(filepath.Join(".github", "workflows", "actions.lock"))
2993+
require.NoError(t, err, stderr)
2994+
after, rerr := os.ReadFile(lockPath)
29962995
require.NoError(t, rerr)
2997-
assert.Equal(t, lock, string(after), "nothing is written")
2996+
assert.Contains(t, string(after), "'actions/checkout@v7.0.1':\n ref: 'v7.0.1'\n commit: 'sha1-"+parityTestMoved+"'", "the tag's commit is written")
2997+
assert.NotContains(t, string(after), parityTestSHA, "the older commit is not")
2998+
assert.Contains(t, string(after), "sha1-"+rootSHA, "the composite keeps its commit")
2999+
3000+
p, err = runParity(t, reg, "--verify", path)
3001+
require.NoError(t, err, "the relocked lock verifies")
3002+
assert.True(t, p.Valid, "%+v", p.Findings)
29983003
}
29993004

30003005
// TestParity_ExactTagBehindSeededCompositeChildBlocks: a new composite

‎internal/pipeline/checks/misleading.go‎

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)