Repair lock entries that record their own SHA as the ref (#198) · github/gh-actions-lock@dacafb7 · GitHub
Skip to content

Commit dacafb7

Browse files
authored
Repair lock entries that record their own SHA as the ref (#198)
1 parent ec26bdc commit dacafb7

34 files changed

Lines changed: 2034 additions & 116 deletions

‎README.md‎

Lines changed: 16 additions & 5 deletions

‎RELEASING.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ and currently
5858
[accepts only lockfile schema `v0.0.2`](https://github.com/dependabot/dependabot-core/blob/main/github_actions/lib/dependabot/github_actions/constants.rb).
5959
Add schema support there before this CLI emits a new version. Unrelated releases
6060
do not need a Dependabot bump.
61+
62+
The findings JSON fields can stay the same while behavior changes, which still
63+
needs this decision. Unreleased changes of that kind:
64+
65+
- A lockfile entry keyed by a full SHA whose `ref` is that same SHA no longer
66+
fails loading with exit 2. Read-only modes report it as a `not-pinned` error
67+
and exit 1; a fix run re-records its tag or branch and exits 0, or fails
68+
when no tag or branch contains the commit; a run given workflow paths warns
69+
about another workflow's such entry and exits 0.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,28 @@ func parityOK(req *http.Request) (*http.Response, error) {
263263
return httpmock.JSONResponse(map[string]any{"data": data})(req)
264264
}
265265

266+
// parityOKWithIDs answers like parityOK, with each repository's databaseId
267+
// taken from ids (by repository name), as the API returns it; a repair
268+
// candidate's identity proof needs it.
269+
func parityOKWithIDs(ids map[string]int) httpmock.Responder {
270+
return func(req *http.Request) (*http.Response, error) {
271+
resp, err := parityOK(req)
272+
if err != nil {
273+
return nil, err
274+
}
275+
var body map[string]map[string]map[string]any
276+
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
277+
return nil, err
278+
}
279+
for _, repo := range body["data"] {
280+
nwo, _ := repo["nameWithOwner"].(string)
281+
_, name, _ := strings.Cut(nwo, "/")
282+
repo["databaseId"] = ids[name]
283+
}
284+
return httpmock.JSONResponse(body)(req)
285+
}
286+
}
287+
266288
// parityFallback answers parity queries the test did not stub as intact,
267289
// since fresh pins fail closed on an inconclusive check.
268290
type parityFallback struct{ rt http.RoundTripper }

‎cmd/gh-actions-lock/format/terminal.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ func PresentResults(out *ui.UI, report *checks.Report, valid bool, willRemediate
3030
if f.Category == checks.FreshTag {
3131
continue
3232
}
33+
if f.Severity == checks.SeverityError {
34+
out.TermError("%s", f.Detail)
35+
if f.Remediation != "" {
36+
out.TermDetail(" %s", f.Remediation)
37+
}
38+
continue
39+
}
3340
out.TermWarn("%s", f.Detail)
3441
if f.DocURL != "" {
3542
out.TermDetail("see: %s", out.TermLink(f.DocURL, f.DocURL))

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ type lockRecovery func(lockPath string, parseErr error) (recovered bool, err err
2121

2222
// newLockRecovery builds the recovery policy: always fail, naming the
2323
// problem. A bad entry usually means a hand edit, and deleting the lockfile
24-
// or fixing it automatically would lose the pins it records.
24+
// or fixing it automatically would lose the pins it records. When the
25+
// committed file is itself bad, version control can't help, so the
26+
// guidance also names the way to lock afresh.
2527
func newLockRecovery() lockRecovery {
2628
return func(lockPath string, parseErr error) (bool, error) {
27-
return false, fmt.Errorf("%w; if you edited %s by hand, restore it from version control", parseErr, filepath.Base(lockPath))
29+
name := filepath.Base(lockPath)
30+
return false, fmt.Errorf("%w; if you edited %s by hand, restore it from version control; otherwise move it aside and run `gh actions-lock` to lock your workflows again", parseErr, name)
2831
}
2932
}

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

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)