Skip to content

Commit 01f53f2

Browse files
zeketjenkinson
andauthored
Fix tests for Actions AllowList (#180)
* fix tests for Actions AllowList * add more allowed actions * Update tests/unit/actions-workflows.js Co-authored-by: Tom Jenkinson <[email protected]> * Update allowed-actions.js Co-authored-by: Tom Jenkinson <[email protected]>
1 parent e0072d0 commit 01f53f2

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.github/allowed-actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = [
88
'actions/cache@v2',
99
'actions/checkout@v2',
1010
'actions/[email protected]',
11+
'actions/[email protected]',
1112
'actions/github-script@v2',
1213
'actions/github-script@v3',
1314
'actions/labeler@v2',
@@ -25,6 +26,8 @@ module.exports = [
2526
'pascalgn/automerge-action@135f0bdb927d9807b5446f7ca9ecc2c51de03c4a',
2627
'peter-evans/create-issue-from-file@v2',
2728
'peter-evans/create-pull-request@v2',
29+
'rachmari/[email protected]',
30+
'rachmari/[email protected]',
2831
'repo-sync/github-sync@v2',
2932
'repo-sync/pull-request@v2',
3033
'rtCamp/action-slack-notify@master',

tests/unit/actions-workflows.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ function actionsUsedInWorkflow (workflow) {
1919
.map(key => get(workflow, key))
2020
}
2121

22+
const allUsedActions = chain(workflows)
23+
.map(actionsUsedInWorkflow)
24+
.flatten()
25+
.uniq()
26+
.sort()
27+
.value()
28+
2229
describe('GitHub Actions workflows', () => {
23-
test('only use allowed actions from ./github/allow-actions.json', async () => {
24-
const allUsedActions = chain(workflows)
25-
.map(actionsUsedInWorkflow)
26-
.flatten()
27-
.uniq()
28-
.sort()
29-
.value()
30+
test('all used actions are allowed in .github/allowed-actions.js', () => {
31+
expect(allUsedActions.length).toBeGreaterThan(0)
32+
const unusedActions = difference(allowedActions, allUsedActions)
33+
expect(unusedActions).toEqual([])
34+
})
3035

36+
test('all allowed actions by .github/allowed-actions.js are used by at least one workflow', () => {
3137
expect(allowedActions.length).toBeGreaterThan(0)
32-
expect(allUsedActions.length).toBeGreaterThan(0)
33-
expect(difference(allowedActions, allUsedActions)).toEqual([])
38+
const disallowedActions = difference(allUsedActions, allowedActions)
39+
expect(disallowedActions).toEqual([])
3440
})
3541
})

0 commit comments

Comments
 (0)