Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for Actions AllowList #180

Merged
merged 9 commits into from
Oct 8, 2020
3 changes: 3 additions & 0 deletions .github/allowed-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ module.exports = [
'actions/cache@v2',
'actions/checkout@v2',
'actions/github-script@0.9.0',
'actions/github-script@v2.0.0',
'actions/github-script@v2',
'actions/github-script@v3',
'actions/labeler@v2',
'actions/setup-node@v1',
'actions/setup-ruby@v1',
'actions/stale@v3',
'andymckay/labeler@1.0.2',
'dawidd6/action-delete-branch@v3',
'docker://chinthakagodawita/autoupdate-action:v1',
'github/codeql-action/analyze@v1',
Expand All @@ -22,6 +24,7 @@ module.exports = [
'juliangruber/approve-pull-request-action@v1',
'juliangruber/find-pull-request-action@v1',
'juliangruber/read-file-action@v1',
'konradpabjan/actions-add-new-issue-to-column@v1.1',
'pascalgn/automerge-action@135f0bdb927d9807b5446f7ca9ecc2c51de03c4a',
'peter-evans/create-issue-from-file@v2',
'peter-evans/create-pull-request@v2',
Expand Down
24 changes: 15 additions & 9 deletions tests/unit/actions-workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ function actionsUsedInWorkflow (workflow) {
.map(key => get(workflow, key))
}

const allUsedActions = chain(workflows)
.map(actionsUsedInWorkflow)
.flatten()
.uniq()
.sort()
.value()

describe('GitHub Actions workflows', () => {
test('only use allowed actions from ./github/allow-actions.json', async () => {
const allUsedActions = chain(workflows)
.map(actionsUsedInWorkflow)
.flatten()
.uniq()
.sort()
.value()
test('all used actions are allowed in .github/allowed-actions.j', () => {
zeke marked this conversation as resolved.
Show resolved Hide resolved
expect(allUsedActions.length).toBeGreaterThan(0)
const unusedActions = difference(allowedActions, allUsedActions)
expect(unusedActions).toEqual([])
})

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