Conditionally run actions based on files modified by PR, feature branch or pushed commits
Go to file
Tonye Jack 910e8b1235
Update README.md (#11)
* Update README.md

* Update version
2020-06-14 23:04:35 +02:00
__tests__ Fix globbing, update metadata, update ncc (#4) 2020-05-21 13:46:48 +02:00
.github Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
.vscode Implement fetching, filtering and tests 2020-05-21 00:31:16 +02:00
dist Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
src Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
.eslintignore Initial commit 2020-05-20 17:03:08 +02:00
.eslintrc.json Implement fetching, filtering and tests 2020-05-21 00:31:16 +02:00
.gitignore Initial commit 2020-05-20 17:03:08 +02:00
.prettierignore Initial commit 2020-05-20 17:03:08 +02:00
.prettierrc.json Implement fetching, filtering and tests 2020-05-21 00:31:16 +02:00
action.yml Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
jest.config.js Initial commit 2020-05-20 17:03:08 +02:00
LICENSE Initial commit 2020-05-20 17:03:08 +02:00
package-lock.json Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
package.json Change detection via git + rename githubToken to token (#9) 2020-05-26 17:16:09 +02:00
README.md Update README.md (#11) 2020-06-14 23:04:35 +02:00
tsconfig.json Initial commit 2020-05-20 17:03:08 +02:00

typescript-action status

Caution

: This action can only be used in a workflow triggered by pull_request event.

Pull request changed files filter

This Github Action enables conditional execution of workflow job steps considering which files are modified by a pull request.

It saves time and resources especially in monorepo setups, where you can run slow tasks (e.g. integration tests) only for changed components. Github workflows built-in path filters doesn't allow this because they doesn't work on a level of individual jobs or steps.

Usage

The action accepts filter rules in the YAML format. Each filter rule is a list of glob expressions. Corresponding output variable will be created to indicate if there's a changed file matching any of the rule glob expressions. Output variables can be later used in the if clause to conditionally run specific steps.

Inputs

  • 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

  • For each rule it sets output variable named by the rule to text:
    • 'true' - if any of changed files matches any of rule patterns
    • 'false' - if none of changed files matches any of rule patterns

Notes

  • minimatch dot option is set to true - therefore globbing will match also paths where file or folder name starts with a dot.

Sample workflow

name: Build verification

on:
  pull_request:
    types:
      - opened
      - synchronize
    branches:
      - master
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: dorny/pr-changed-files-filter@v1.1.0
      id: filter
      with:
        # inline YAML or path to separate file (e.g.: .github/filters.yaml)
        filters: |
          backend:
            - 'backend/**/*'
          frontend:
            - 'frontend/**/*'          

    # run only if 'backend' files were changed
    - name: backend unit tests
      if: steps.filter.outputs.backend == 'true'
      run: ...

    # run only if 'frontend' files were changed
    - name: frontend unit tests
      if: steps.filter.outputs.frontend == 'true'
      run: ...

    # run if 'backend' or 'frontend' files were changed
    - name: e2e tests
      if: steps.filter.outputs.backend == 'true' || steps.filter.outputs.frontend == 'true'
      run: ...

How it works

  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
  • Has Changed Path
    • detects changes from previous commit
    • you have to configure checkout action to fetch some number of previous commits
    • git diff is used for change detection
    • outputs only single true / false value if any of provided paths contains changes
  • Changed Files Exporter
    • outputs lists with paths of created, updated and deleted files
    • output is not directly usable in the if clause
  • Changed File Filter
    • allows change detection between any refs or commits
    • fetches whole history of your git repository
    • might have negative performance impact on big repositories (github by default fetches only single commit)