Skip to content

Commit

Permalink
Change detection via git + rename githubToken to token (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorny authored May 26, 2020
1 parent a2e5f9f commit 1cbb925
Show file tree
Hide file tree
Showing 9 changed files with 1,315 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
error:
- not_existing_path/**/*
any:
- "**/*"
39 changes: 29 additions & 10 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,43 @@ jobs:
npm install
npm run all
test:
test-inline:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
id: filter
with:
filters: '.github/filters.yml'
- uses: ./
id: inlineFilter
with:
filters: |
src:
- src/**/*
tests:
- __tests__/**/*
error:
- not_existing_path/**/*
any:
- "**/*"
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.inlineFilter.outputs.any != 'true'
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1

test-external:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
id: filter
with:
filters: '.github/filters.yml'
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1

test-without-token:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
id: filter
with:
token: ''
filters: '.github/filters.yml'
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Corresponding output variable will be created to indicate if there's a changed f
Output variables can be later used in the `if` clause to conditionally run specific steps.

### Inputs
- **`githubToken`**: GitHub Access Token - defaults to `${{ github.token }}`
- **`token`**: GitHub Access Token - defaults to `${{ github.token }}`
- **`filters`**: Path to the configuration file or directly embedded string in YAML format. Filter configuration is a dictionary, where keys specifies rule names and values are lists of file path patterns.

### Outputs
Expand Down Expand Up @@ -78,10 +78,11 @@ jobs:
## How it works
1. Required inputs are checked (`githubToken` & `filters`)
2. Provided access token is used to fetch list of changed files.
3. For each filter rule it checks if there is any matching file
4. Output variables are set
1. Required inputs are checked (`filters`)
2. If token was provided, it's used to fetch list of changed files from Github API.
3. If token was not provided, base branch is fetched and changed files are detected using `git diff-index` command.
4. For each filter rule it checks if there is any matching file
5. Output variables are set

## Difference from related projects:

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: 'Pull request changed files filter'
description: 'Enables conditional execution of workflow job steps considering which files are modified by a pull request.'
author: 'Michal Dorner <dorner.michal@gmail.com>'
inputs:
githubToken:
token:
description: 'GitHub Access Token'
required: true
required: false
default: ${{ github.token }}
filters:
description: 'Path to the configuration file or YAML string with filters definition'
Expand Down
Loading

0 comments on commit 1cbb925

Please sign in to comment.