Skip to content

Commit 47807ea

Browse files
fix(manager/github-actions): disable updates for bare SHA pins without version comment (renovatebot#42398)
* fix(manager/github-actions): disable updates for naked SHA pins without version comment * docs(manager/github-actions): document disabled updates for bare SHA pins * test(manager/github-actions): use single toEqual for version comment assertions * docs(manager/github-actions): recommend version comment as primary fix for bare SHA pins * fix(manager/github-actions): add skipReason for naked SHA pins * docs(manager/github-actions): remove package rule example for re-enabling bare SHA updates Co-authored-by: Jamie Tanna <github@jamietanna.co.uk> --------- Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
1 parent e12cc46 commit 47807ea

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ exports[`modules/manager/github-actions/extract > extractPackageFile() > extract
4141
"datasource": "github-tags",
4242
"depName": "docker/setup-qemu-action",
4343
"depType": "action",
44+
"enabled": false,
4445
"replaceString": "docker/setup-qemu-action@c308fdd69d26ed66f4506ebd74b180abe5362145",
46+
"skipReason": "unversioned-reference",
4547
"versioning": "docker",
4648
},
4749
{

lib/modules/manager/github-actions/extract.spec.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,93 @@ describe('modules/manager/github-actions/extract', () => {
524524
});
525525
});
526526

527+
it('disables naked SHA pins without version comment', () => {
528+
const res = extractPackageFile(
529+
codeBlock`
530+
jobs:
531+
build:
532+
steps:
533+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
534+
`,
535+
'workflow.yml',
536+
);
537+
expect(res?.deps[0]).toMatchObject({
538+
depName: 'actions/checkout',
539+
currentDigest: 'c85c95e3d7251135ab7dc9ce3241c5835cc595a9',
540+
currentValue: undefined,
541+
enabled: false,
542+
skipReason: 'unversioned-reference',
543+
});
544+
});
545+
546+
it('disables naked short SHA pins without version comment', () => {
547+
const res = extractPackageFile(
548+
codeBlock`
549+
jobs:
550+
build:
551+
steps:
552+
- uses: actions/checkout@c85c95e
553+
`,
554+
'workflow.yml',
555+
);
556+
expect(res?.deps[0]).toMatchObject({
557+
depName: 'actions/checkout',
558+
currentDigestShort: 'c85c95e',
559+
currentValue: undefined,
560+
enabled: false,
561+
skipReason: 'unversioned-reference',
562+
});
563+
});
564+
565+
it('does not disable SHA pins with version comment', () => {
566+
const res = extractPackageFile(
567+
codeBlock`
568+
jobs:
569+
build:
570+
steps:
571+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v4
572+
`,
573+
'workflow.yml',
574+
);
575+
expect(res?.deps[0]).toEqual({
576+
depName: 'actions/checkout',
577+
commitMessageTopic: '{{{depName}}} action',
578+
versioning: 'docker',
579+
depType: 'action',
580+
replaceString:
581+
'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v4',
582+
autoReplaceStringTemplate:
583+
'{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # {{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}',
584+
currentValue: 'v4',
585+
currentDigest: 'c85c95e3d7251135ab7dc9ce3241c5835cc595a9',
586+
datasource: 'github-tags',
587+
});
588+
});
589+
590+
it('does not disable short SHA pins with version comment', () => {
591+
const res = extractPackageFile(
592+
codeBlock`
593+
jobs:
594+
build:
595+
steps:
596+
- uses: actions/checkout@c85c95e # v4
597+
`,
598+
'workflow.yml',
599+
);
600+
expect(res?.deps[0]).toEqual({
601+
depName: 'actions/checkout',
602+
commitMessageTopic: '{{{depName}}} action',
603+
versioning: 'docker',
604+
depType: 'action',
605+
replaceString: 'actions/checkout@c85c95e # v4',
606+
autoReplaceStringTemplate:
607+
'{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # {{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}',
608+
currentValue: 'v4',
609+
currentDigestShort: 'c85c95e',
610+
datasource: 'github-tags',
611+
});
612+
});
613+
527614
it('extracts actions with fqdn', () => {
528615
const res = extractPackageFile(
529616
codeBlock`

lib/modules/manager/github-actions/extract.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ function extractRepositoryAction(
130130
dep.currentValue = ref;
131131
}
132132

133+
if (!dep.currentValue) {
134+
dep.enabled = false;
135+
dep.skipReason = 'unversioned-reference';
136+
}
137+
133138
const isVersionLike =
134139
dep.currentValue && versionLikeRe.test(dep.currentValue);
135140
if (!dep.datasource && dep.currentValue && !isVersionLike) {

lib/modules/manager/github-actions/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ If you want to automatically pin action digests add the `helpers:pinGitHubAction
3939
}
4040
```
4141

42+
Actions pinned to a bare SHA without a version comment are disabled by default, because Renovate cannot determine which branch or tag the SHA belongs to.
43+
To enable updates, add a tag or branch name as a version comment, as shown above.
44+
4245
### Non-semver refs (branches and feature tags)
4346

4447
Renovate supports GitHub Actions that reference non-semver refs like branch names (`main`, `master`) or feature-oriented tags (`cargo-llvm-cov`).

0 commit comments

Comments
 (0)