From f9b6173f5e12138544f262a84e249c225a38163d Mon Sep 17 00:00:00 2001 From: Michal Dorner Date: Thu, 21 May 2020 01:37:33 +0200 Subject: [PATCH] Fixes - making action pass self-test (#3) * 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 --- .github/workflows/test.yml | 15 ++++++++++++--- __tests__/main.test.ts | 10 ++++++++++ action.yml | 2 +- dist/index.js | 2 +- src/main.ts | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ebc1295..4f7501c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: "build-test" on: # rebuild any PRs and main branch changes pull_request: + types: + - opened + - synchronize branches: - master @@ -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__/**/* \ No newline at end of file + - __tests__/**/* + any: + - "**/*" + - name: filter-test + if: steps.filter.outputs.any != 'true' + run: exit 1 diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index ff5322c..9e0d18a 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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() + }) }) diff --git a/action.yml b/action.yml index 043361d..f54dac1 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,7 @@ description: 'Enables conditional execution of workflow job steps considering wh author: 'Michal Dorner ' 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' diff --git a/dist/index.js b/dist/index.js index 36e5981..97b6790 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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'); diff --git a/src/main.ts b/src/main.ts index a3beac2..d3854ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import Filter from './filter' async function run(): Promise { 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') {