Skip to content

Commit

Permalink
Fixes - making action pass self-test (#3)
Browse files Browse the repository at this point in the history
* Remove accidental string interpolation from action.yml

* Fix test workflow filters

* Improve self-test

* Add test case for matching any changed file

* Fix workflow test - step `name` was used instead of `id`

* Extend default pull_request trigger types

* Remove `edited` trigger to avoid executing workflow on non-code changes
  • Loading branch information
Michal Dorner authored and GitHub committed May 20, 2020
1 parent 94603ab commit f9b6173
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: "build-test"
on: # rebuild any PRs and main branch changes
pull_request:
types:
- opened
- synchronize
branches:
- master

Expand All @@ -17,10 +20,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./
id: filter
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
filter: |
githubToken: ${{ github.token }}
filters: |
src:
- src/**/*
tests:
- __tests__/**/*
- __tests__/**/*
any:
- "**/*"
- name: filter-test
if: steps.filter.outputs.any != 'true'
run: exit 1
10 changes: 10 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ describe('matching tests', () => {
const match = filter.match(['test/test.js'])
expect(match.src).toBeTruthy()
})

test('matches anything', () => {
const yaml = `
any:
- "**/*"
`
const filter = new Filter(yaml)
const match = filter.match(['test/test.js'])
expect(match.any).toBeTruthy()
})
})
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Enables conditional execution of workflow job steps considering wh
author: 'Michal Dorner <dorner.michal@gmail.com>'
inputs:
githubToken:
description: 'GitHub Access Token - use ${{ github.token }}'
description: 'GitHub Access Token'
required: true
filters:
description: 'YAML dictionary where keys specifies rule names and values are lists of (globbing) file path patterns'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4118,7 +4118,7 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = core.getInput('githubToken', { required: true });
const filterYaml = core.getInput('filter', { required: true });
const filterYaml = core.getInput('filters', { required: true });
const client = new github.GitHub(token);
if (github.context.eventName !== 'pull_request') {
core.setFailed('This action can be triggered only by pull_request event');
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Filter from './filter'
async function run(): Promise<void> {
try {
const token = core.getInput('githubToken', {required: true})
const filterYaml = core.getInput('filter', {required: true})
const filterYaml = core.getInput('filters', {required: true})
const client = new github.GitHub(token)

if (github.context.eventName !== 'pull_request') {
Expand Down

0 comments on commit f9b6173

Please sign in to comment.