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

V4 #229

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .github/filterignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.ts
**/*.nothing
18 changes: 17 additions & 1 deletion .github/filters.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
error:
- not_existing_path/**/*
any:
- "**/*"
- "**/*"
anyignore:
-
paths: "**/*"
paths_ignore:
- "**/*.md"
anyignorenull:
-
paths: "**/*"
paths_ignore:
- "**local.ts"
- "**local.md"
anyignoreall:
-
paths: "**/*"
paths_ignore:
- "**/*.no"
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: |
npm install
npm ci
npm run all

self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./
id: filter
with:
Expand Down
162 changes: 155 additions & 7 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: |
npm install
npm run all

test-inline:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./
id: filter
with:
Expand All @@ -37,7 +37,7 @@ jobs:
test-external:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./
id: filter
with:
Expand All @@ -49,7 +49,7 @@ jobs:
test-without-token:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./
id: filter
with:
Expand All @@ -62,7 +62,7 @@ jobs:
test-wd-without-token:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: somewhere
- uses: ./somewhere
Expand All @@ -78,7 +78,7 @@ jobs:
test-local-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: echo "NEW FILE" > local
- run: git add local
- uses: ./
Expand All @@ -98,7 +98,7 @@ jobs:
test-change-type:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: configure GIT user
run: git config user.email "[email protected]" && git config user.name "John Doe"
- name: modify working tree
Expand Down Expand Up @@ -135,3 +135,151 @@ jobs:
|| steps.filter.outputs.modified_files != 'LICENSE'
|| steps.filter.outputs.deleted_files != 'README.md'
run: exit 1

test-baseref-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
id: filter
with:
base: ${{ github.base_ref }}
ref: ${{ github.sha }}
filters: |
error:
- not_existing_path/**/*
any:
- "**/*"
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1
- name: changes-test
if: contains(fromJSON(steps.filter.outputs.changes), 'error') || !contains(fromJSON(steps.filter.outputs.changes), 'any')
run: exit 1

test-custom-nostatus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
base=${{ github.base_ref }}
compare=${{ github.sha }}
git fetch origin $base:$base
echo 'customchanges<<EOF' >> $GITHUB_ENV
git diff --name-only $base..$compare >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- uses: ./
id: filter
with:
files: ${{ env.customchanges }}
filters: |
error:
- not_existing_path/**/*
any:
- "**/*"
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1
- name: changes-test
if: contains(fromJSON(steps.filter.outputs.changes), 'error') || !contains(fromJSON(steps.filter.outputs.changes), 'any')
run: exit 1

test-custom-withstatus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
base=${{ github.base_ref }}
compare=${{ github.sha }}
git fetch origin $base:$base
echo 'customchanges<<EOF' >> $GITHUB_ENV
git diff --name-status $base..$compare >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- uses: ./
id: filter
with:
files: ${{ env.customchanges }}
filters: |
error:
- not_existing_path/**/*
any:
- "**/*"
- name: filter-test
if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true'
run: exit 1
- name: changes-test
if: contains(fromJSON(steps.filter.outputs.changes), 'error') || !contains(fromJSON(steps.filter.outputs.changes), 'any')
run: exit 1
- name: print context
run: |
echo "${{ tojson(steps.filter) }}"

test-ignore-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
echo "NEW FILE" > local.ts
echo "IGNORE FILE" > local.md
- run: git add local.ts local.md
- uses: ./
id: filter
with:
base: HEAD
filters: '.github/filters.yml'
- name: print context
run: |
echo "${{ tojson(steps.filter) }}"
- name: filter-test
if: steps.filter.outputs.any != 'true'
run: exit 1
- name: ignore-test
if: steps.filter.outputs.anyignore_count != 1
run: exit 1
- name: ignore_testnull
if: steps.filter.outputs.anyignorenull == true
run: exit 1
- name: ignore_testall
if: steps.filter.outputs.anyignoreall_count != 2
run: |
exit 1

test-global-ignore:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
echo "NEW FILE" > local.ts
echo "IGNORE FILE" > local.md
- run: git add local.ts local.md
- uses: ./
id: filter
with:
base: HEAD
filters: |
error:
- not_existing_path/**/*
any:
- "**/*"
anyignore:
-
paths: "**/*"
paths_ignore:
- "**local.md"
global-ignore: .github/filterignore
- name: print context
run: |
echo "${{ tojson(steps.filter) }}"
- name: filter-test
if: steps.filter.outputs.any_count != 1
run: exit 1
- name: ignore-test
if: steps.filter.outputs.anyignore == true
run: exit 1
- name: ignore_testnull
if: steps.filter.outputs.error == true
run: exit 1
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# .npmrc
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v4.0.0
- Uses node20 & checkouts v4

## v3.0.0
- [Adds customfiles, paths-ignore, globalignore, and validate input. Update packages, minify build.](https://github.com/dorny/paths-filter/pull/##)

## v2.10.2
- [Fix getLocalRef() returns wrong ref](https://github.com/dorny/paths-filter/pull/91)

Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ don't allow this because they don't work on a level of individual jobs or steps.
- Workflow triggered by **[pull_request](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request)**
or **[pull_request_target](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target)** event
- Changes are detected against the pull request base branch
- Uses GitHub REST API to fetch a list of modified files
- Uses GitHub REST API to fetch a list of modified files, if base or ref are not provided.
- **Feature branches:**
- Workflow triggered by **[push](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push)**
or any other **[event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows)**
Expand All @@ -40,6 +40,8 @@ don't allow this because they don't work on a level of individual jobs or steps.
- Workflow triggered by any event when `base` input parameter is set to `HEAD`
- Changes are detected against the current HEAD
- Untracked files are ignored
- **Input Files**
- Input list of string to `customfiles` input parameter and get the filtered results. In case you want to generate list of files elsewhere.

## Example

Expand Down Expand Up @@ -70,11 +72,11 @@ For more scenarios see [examples](#examples) section.

## What's New

- Add `ref` input parameter
- Add `list-files: csv` format
- Configure matrix job to run for each folder with changes using `changes` output
- Improved listing of matching files with `list-files: shell` and `list-files: escape` options
- Paths expressions are now evaluated using [picomatch](https://github.com/micromatch/picomatch) library
- Add customfiles input. Input a string formatted the way git diff outputs, to do your own diffs when you want.
- Add paths-ignore to each filter rule, which will exclude files matching those patterns.
- Add globalignore input as a filename, formatted like a .gitignore. Always excludes files matching those globs.
- Input is validated with more explicit errors if filters are not correctly formatted.
- Performance improvements: Minifies the build for a smaller package. Runs a single instance of picomatch with an array of string where possible.

For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob/master/CHANGELOG.md)

Expand All @@ -93,6 +95,8 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
# indicate if there's a changed file matching any of the rules.
# Optionally, there can be a second output variable
# set to list of all files matching the filter.
# Optionally, filters can be an object including path, meaning the rule, and paths_ignore,
# being a an array of rules to ignore.
# Filters can be provided inline as a string (containing valid YAML document),
# or as a relative path to a file (e.g.: .github/filters.yaml).
# Filters syntax is documented by example - see examples section.
Expand All @@ -107,14 +111,12 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
# introduced by the current branch are considered.
# All files are considered as added if there is no common ancestor with
# base branch or no previous commit.
# This option is ignored if action is triggered by pull_request event.
# Default: repository default branch (e.g. master)
base: ''

# Git reference (e.g. branch name) from which the changes will be detected.
# Useful when workflow can be triggered only on the default branch (e.g. repository_dispatch event)
# but you want to get changes on a different branch.
# This option is ignored if action is triggered by pull_request event.
# default: ${{ github.ref }}
ref:

Expand Down Expand Up @@ -150,6 +152,15 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
# changes using git commands.
# Default: ${{ github.token }}
token: ''

# Optionally provide a list of files you have generated elsewhere.
# Performs the glob matching against these files instead. Negates
# all other inputs less filters & list-files.
customfiles: ''

# Optionally provide a filename in your directory to globally ignore patterns.
# File must be formatted as a newline separated list of glob patterns, like a .gitignore.
global-ignore: ''
```

## Outputs
Expand Down Expand Up @@ -202,7 +213,7 @@ jobs:
</details>

<details>
<summary>Execute <b>job</b> in a workflow only if some file in a subfolder is changed</summary>
<summary>Execute <b>job</b> in a workflow only if some file in a subfolder is changed. Note excluding frontend's readme.</summary>

```yml
jobs:
Expand All @@ -222,7 +233,10 @@ jobs:
backend:
- 'backend/**'
frontend:
- 'frontend/**'
-
paths: ['frontend/**']
paths_ignore:
- 'frontend/README.md'

# JOB to build and test backend code
backend:
Expand Down
Loading