Skip to content

Commit b9ddf6a

Browse files
MarcHagenzgosalvez
andauthored
[feat/bugfix] Allow docker checks (#51)
* Fix README.md links * Add valid/invalid docker uses * Remove SHA1 package (keep it simple) * camelCase for all functions * Short check * Add docker sha256 check * Put regex in const * Resolves merge conflict --------- Co-authored-by: Zennon Gosalvez <[email protected]>
1 parent 2833a07 commit b9ddf6a

File tree

9 files changed

+33
-37
lines changed

9 files changed

+33
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
```
4646

4747
## Contributing
48-
See [the contributing guide](.github/CONTRIBUTING) for detailed instructions on how to get started with our project.
48+
See [the contributing guide](.github/CONTRIBUTING.md) for detailed instructions on how to get started with our project.
4949

5050
## License
51-
The scripts and documentation in this project are released under the [MIT License](LICENSE)
51+
The scripts and documentation in this project are released under the [MIT License](LICENSE.md)

dist/index.js

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

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

dist/licenses.txt

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"dependencies": {
2222
"@actions/core": "^1.10.0",
2323
"@actions/glob": "^0.4.0",
24-
"sha1-regex": "^1.0.0",
2524
"yaml": "^2.2.1"
2625
},
2726
"devDependencies": {

src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ const core = require('@actions/core');
22
const fs = require('fs');
33
const glob = require('@actions/glob');
44
const path = require('path');
5-
const sha1 = require('sha1-regex');
65
const yaml = require('yaml');
76

7+
const sha1 = /\b[a-f0-9]{40}\b/i;
8+
const sha256 = /\b[A-Fa-f0-9]{64}\b/i;
9+
810
async function run() {
911
try {
1012
const allowlist = core.getInput('allowlist');
11-
const isDryRun = core.getInput('dry_run') === 'true' ? true : false;
13+
const isDryRun = core.getInput('dry_run') === 'true';
1214
const workflowsPath = process.env['ZG_WORKFLOWS_PATH'] || '.github/workflows';
1315
const globber = await glob.create([workflowsPath + '/*.yaml', workflowsPath + '/*.yml'].join('\n'));
1416
let actionHasError = false;
@@ -31,7 +33,7 @@ async function run() {
3133
const steps = jobs[job]['steps'];
3234

3335
if (assertUsesVersion(uses)) {
34-
if (!assertUsesSHA(uses) && !assertUsesAllowlist(uses, allowlist)) {
36+
if (!assertUsesSha(uses) && !assertUsesAllowlist(uses, allowlist)) {
3537
actionHasError = true;
3638
fileHasError = true;
3739

@@ -41,7 +43,7 @@ async function run() {
4143
for (const step of steps) {
4244
const uses = step['uses'];
4345

44-
if (assertUsesVersion(uses) && !assertUsesSHA(uses) && !assertUsesAllowlist(uses, allowlist)) {
46+
if (assertUsesVersion(uses) && !assertUsesSha(uses) && !assertUsesAllowlist(uses, allowlist)) {
4547
actionHasError = true;
4648
fileHasError = true;
4749

@@ -74,7 +76,11 @@ function assertUsesVersion(uses) {
7476
return typeof uses === 'string' && uses.includes('@');
7577
}
7678

77-
function assertUsesSHA(uses) {
79+
function assertUsesSha(uses) {
80+
if (uses.startsWith('docker://')) {
81+
return sha256.test(uses.substr(uses.indexOf('sha256:') + 7));
82+
}
83+
7884
return sha1.test(uses.substr(uses.indexOf('@') + 1));
7985
}
8086

test/stub/pass/valid.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ jobs:
88
allowlistedstub:
99
steps:
1010
- uses: aws-actions/amazon-ecr-login@v1
11-
- uses: docker/login-action@v1
11+
- uses: docker/login-action@v1
12+
dockerstub:
13+
steps:
14+
- uses: docker://rhysd/actionlint@sha256:5f957b2a08d223e48133e1a914ed046bea12e578fe2f6ae4de47fdbe691a2468

test/stub/unpinned/file.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ jobs:
22
stub:
33
steps:
44
- uses: actions/checkout@v1
5+
dockerstub:
6+
steps:
7+
- uses: docker://rhysd/actionlint:latest
8+
- uses: docker://rhysd/actionlint:1.6.22

0 commit comments

Comments
 (0)