Skip to content

Commit fd8a8f8

Browse files
authored
feat: gha-workflow-validator node24 update, and major version tags (#1460)
* feat: gha-workflow-validator node24 update, and major version tags * reduce tag ref validation to warning
1 parent 49849dc commit fd8a8f8

11 files changed

Lines changed: 208 additions & 78 deletions

File tree

.changeset/dirty-suns-eat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gha-workflow-validator": major
3+
---
4+
5+
initial release - update to flag node20 actions, and when tag refs should be
6+
used

actions/gha-workflow-validator/action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ inputs:
99
evaluate-mode:
1010
description: "Set to true to never fail the action."
1111
required: false
12-
default: false
12+
default: "false"
1313
root-directory:
1414
description: "Root directory of the repository."
1515
required: false
1616
default: ${{ github.workspace }}
1717
diff-only:
1818
description: "Only validate line changes. Not existing workflows."
1919
required: false
20-
default: false
20+
default: "false"
2121

2222
# validator options
2323
validate-runners:
2424
description: "Validate the runners in the workflow are approved for use."
2525
required: false
26-
default: true
26+
default: "true"
2727
validate-action-refs:
2828
description: "Validate action references use a SHA reference."
2929
required: false
30-
default: true
30+
default: "true"
3131
validate-action-node-versions:
3232
description: "Validate actions referenced are using node 20."
3333
required: false
34-
default: true
34+
default: "true"
3535
validate-actions-cache-version:
3636
description: "Validate actions/cache is using the proper version."
3737
required: false
38-
default: true
38+
default: "true"
3939

4040
# validation behaviour options
4141
include-all-action-definitions:
4242
description:
4343
"Include all action.yml files in the repository, not just the ones in
4444
.github/actions. Useful for action monorepos."
4545
required: false
46-
default: false
46+
default: "false"

actions/gha-workflow-validator/dist/index.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28773,9 +28773,9 @@ It currently validates: Actions References, Actions Runner Types
2877328773
<details>
2877428774
<summary>Action References (sha-ref, version-comment, node-version) </summary>
2877528775

28776-
This validation is required to ensure that the action references use immutable SHAs, have a version comment, and are not using node16 or earlier.
28776+
This validation is required to ensure that 3rd-party action references use immutable SHAs, have a version comment, and are using node24.
2877728777

28778-
The proper format for referencing a Github Action external to the repository is as follows:
28778+
The proper format for referencing a 3rd-party Github Action as follows:
2877928779

2878028780
\`<owner>/<repo>/<optional path>@<commit SHA> # <version tag relating to the SHA>\`
2878128781

@@ -28789,6 +28789,14 @@ organization/monorepo/path/to/directory@5874ff7211cf5a5a2670bb010fbff914eaaae138
2878928789
\`\`\`
2879028790
</details>
2879128791

28792+
28793+
#### Trusted actions should use a major version, if available.
28794+
28795+
* This means the action is owned by github, actions, or smartcontractkit, and if available you should use the major version tag instead of a SHA reference.
28796+
* For example:
28797+
* \`actions/checkout@v5\` instead of \`actions/checkout@<sha> # v5.0.0\`
28798+
* \`smartcontractkit/.github/actions/setup-golang@setup-golang/v1\` instead of \`smartcontractkit/.github/actions/setup-golang@<sha> # setup-golang/v1\`
28799+
2879228800
##### <ref> is not a valid SHA
2879328801

2879428802
* Please reference a specific commit. This is because tags are mutable and pose a security risk
@@ -28802,7 +28810,7 @@ organization/monorepo/path/to/directory@5874ff7211cf5a5a2670bb010fbff914eaaae138
2880228810

2880328811
##### Action is using node...
2880428812

28805-
* The action added is supposed to be run using a version that is not \`node20\`. This might create issues due to Github deprecating actions using \`node16\` and earlier.
28813+
* The action added is supposed to be run using a version that is not \`node24\`. This might create issues due to Github deprecating actions using \`node20\` and earlier.
2880628814

2880728815
</details>
2880828816

@@ -29203,7 +29211,7 @@ var core7 = __toESM(require_core());
2920329211

2920429212
// actions/gha-workflow-validator/src/validations/action-reference-validations.ts
2920529213
var core5 = __toESM(require_core());
29206-
var OLDEST_ALLOWABLE_NODE_VERSION = 20;
29214+
var OLDEST_ALLOWABLE_NODE_VERSION = 24;
2920729215
var ActionRefValidation = class {
2920829216
constructor(octokit, options) {
2920929217
this.octokit = octokit;
@@ -29232,9 +29240,16 @@ async function validateActionReference(octokit, options, actionRef) {
2923229240
return [];
2923329241
}
2923429242
const validationErrors = [];
29243+
const trustedActionTagRefValidation = validateTrustedActionTagRef(actionRef);
2923529244
const shaRefValidation = validateShaRef(actionRef);
2923629245
const versionCommentValidation = validateVersionCommentExists(actionRef);
29237-
const node20ActionValidation = options.validateNodeVersion ? await validateNodeActionVersion(octokit, actionRef) : void 0;
29246+
const node24ActionValidation = options.validateNodeVersion ? await validateNodeActionVersion(octokit, actionRef) : void 0;
29247+
if (trustedActionTagRefValidation) {
29248+
core5.debug(
29249+
`Trusted Tag Ref Validation failed for ${actionRef.owner}/${actionRef.repo}${actionRef.repoPath}@${actionRef.ref}`
29250+
);
29251+
validationErrors.push(trustedActionTagRefValidation);
29252+
}
2923829253
if (!actionRef.trusted && shaRefValidation) {
2923929254
core5.debug(
2924029255
`SHA Ref Validation Failed for ${actionRef.owner}/${actionRef.repo}${actionRef.repoPath}@${actionRef.ref} - ${shaRefValidation.message}`
@@ -29247,15 +29262,30 @@ async function validateActionReference(octokit, options, actionRef) {
2924729262
);
2924829263
validationErrors.push(versionCommentValidation);
2924929264
}
29250-
if (node20ActionValidation) {
29265+
if (node24ActionValidation) {
2925129266
core5.debug(
29252-
`Node 20 Validation Failed for ${actionRef.owner}/${actionRef.repo}${actionRef.repoPath}@${actionRef.ref} - ${node20ActionValidation.message}`
29267+
`Node 24 Validation Failed for ${actionRef.owner}/${actionRef.repo}${actionRef.repoPath}@${actionRef.ref} - ${node24ActionValidation.message}`
2925329268
);
29254-
validationErrors.push(node20ActionValidation);
29269+
validationErrors.push(node24ActionValidation);
2925529270
}
2925629271
return validationErrors;
2925729272
}
29273+
function validateTrustedActionTagRef(actionReference) {
29274+
if (!actionReference.trusted) {
29275+
return;
29276+
}
29277+
const sha1Regex = /^[0-9a-f]{40}$/;
29278+
const sha256Regex = /^[0-9a-f]{256}$/;
29279+
const isUsingShaRef = sha1Regex.test(actionReference.ref) || sha256Regex.test(actionReference.ref);
29280+
if (!isUsingShaRef) return;
29281+
return {
29282+
message: `Trusted actions should use a major version tag, if available.`,
29283+
type: "trusted-tag-ref" /* TRUSTED_TAG_REF */,
29284+
severity: "warning"
29285+
};
29286+
}
2925829287
function validateShaRef(actionReference) {
29288+
if (actionReference.trusted) return;
2925929289
const sha1Regex = /^[0-9a-f]{40}$/;
2926029290
if (sha1Regex.test(actionReference.ref)) return;
2926129291
const sha256Regex = /^[0-9a-f]{256}$/;
@@ -29267,7 +29297,7 @@ function validateShaRef(actionReference) {
2926729297
};
2926829298
}
2926929299
function validateVersionCommentExists(actionReference) {
29270-
if (actionReference.comment) return;
29300+
if (actionReference.trusted || actionReference.comment) return;
2927129301
return {
2927229302
message: `No version comment found`,
2927329303
type: "version-comment" /* VERSION_COMMENT */,
@@ -29296,7 +29326,7 @@ async function validateNodeActionVersion(octokit, actionRef) {
2929629326
const nodeVersionParsed = parseInt(matches[1], 10);
2929729327
if (nodeVersionParsed < OLDEST_ALLOWABLE_NODE_VERSION) {
2929829328
return {
29299-
message: `Action is using node${nodeVersionParsed}`,
29329+
message: `Action is using node${nodeVersionParsed}. Versions older than node${OLDEST_ALLOWABLE_NODE_VERSION} are being deprecated. Use a newer version of the action if possible.`,
2930029330
type: "node-version" /* NODE_VERSION */,
2930129331
severity: "warning"
2930229332
};
@@ -29548,15 +29578,15 @@ var ActionsCacheVersionValidation = class {
2954829578
if (!ref) {
2954929579
return [];
2955029580
}
29551-
const isRefUpToDate = ref === "v4" || ref === "v3" || ref === "v4.2.0" || ref === "v3.4.0";
29581+
const isRefUpToDate = ref.startsWith("v5");
2955229582
if (isRefUpToDate) {
2955329583
return [];
2955429584
}
2955529585
return [
2955629586
{
2955729587
type: "actions-cache" /* ACTIONS_CACHE */,
2955829588
severity: line.operation === "add" ? "error" : "warning",
29559-
message: `This version (${ref}) of actions/cache is being deprecated. Please update to v4.`
29589+
message: `This version (${ref}) of actions/cache is being deprecated. Please update to v5`
2956029590
}
2956129591
];
2956229592
}

actions/gha-workflow-validator/src/__tests__/__snapshots__/action-reference-validation.test.ts.snap

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
exports[`ActionRefValidation > should invalidate action reference (sha-ref / no comment) 1`] = `
44
[
55
{
6-
"message": "No version comment found",
6+
"message": "Trusted actions should use a major version tag, if available.",
77
"severity": "warning",
8-
"type": "version-comment",
8+
"type": "trusted-tag-ref",
99
},
1010
]
1111
`;
@@ -23,7 +23,7 @@ exports[`ActionRefValidation > should invalidate single action reference (all er
2323
"type": "version-comment",
2424
},
2525
{
26-
"message": "Action is using node16",
26+
"message": "Action is using node16. Versions older than node24 are being deprecated. Use a newer version of the action if possible.",
2727
"severity": "warning",
2828
"type": "node-version",
2929
},
@@ -37,6 +37,11 @@ exports[`ActionRefValidation > should invalidate single action reference (bad sh
3737
"severity": "error",
3838
"type": "sha-ref",
3939
},
40+
{
41+
"message": "Action is using node20. Versions older than node24 are being deprecated. Use a newer version of the action if possible.",
42+
"severity": "warning",
43+
"type": "node-version",
44+
},
4045
]
4146
`;
4247

@@ -47,17 +52,35 @@ exports[`ActionRefValidation > should invalidate single action reference (no ver
4752
"severity": "warning",
4853
"type": "version-comment",
4954
},
55+
{
56+
"message": "Action is using node20. Versions older than node24 are being deprecated. Use a newer version of the action if possible.",
57+
"severity": "warning",
58+
"type": "node-version",
59+
},
5060
]
5161
`;
5262

5363
exports[`ActionRefValidation > should invalidate single action reference (node16) 1`] = `
5464
[
5565
{
56-
"message": "Action is using node16",
66+
"message": "Trusted actions should use a major version tag, if available.",
67+
"severity": "warning",
68+
"type": "trusted-tag-ref",
69+
},
70+
{
71+
"message": "Action is using node16. Versions older than node24 are being deprecated. Use a newer version of the action if possible.",
5772
"severity": "warning",
5873
"type": "node-version",
5974
},
6075
]
6176
`;
6277

63-
exports[`ActionRefValidation > should validate single action reference (node24) 1`] = `[]`;
78+
exports[`ActionRefValidation > should validate single action reference (node24) 1`] = `
79+
[
80+
{
81+
"message": "Trusted actions should use a major version tag, if available.",
82+
"severity": "warning",
83+
"type": "trusted-tag-ref",
84+
},
85+
]
86+
`;

0 commit comments

Comments
 (0)