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

Proposing v3.0.0 with updates and new features #151

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: |
npm install
npm ci
npm run all

self-test:
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
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@v2
- 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@v2
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@v2
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@v2
- 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@v2
- 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 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
33 changes: 33 additions & 0 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,39 @@ describe('matching specific change status', () => {
const match = filter.match(files)
expect(match.src).toEqual(files)
})
test('matches path based on rules including using ignore', () => {
const yaml = `
ignore:
-
paths: ["config/**"]
paths_ignore:
- "**.md"
`
const filter = new Filter(yaml)
const files = modified(['config/settings.yml', 'config/settings.md', 'nothing/todo/with.this'])
const match = filter.match(files)
expect(match.ignore).toEqual(modified(['config/settings.yml']))
})
test('matches path based on rules including using global ignore', () => {
const yaml = `
ignore:
-
paths: ["**/*"]
paths_ignore:
- "**.md"
ignoreall:
-
paths: ["**/*"]
paths_ignore:
- "**.md"
- "**.yml"
`
const filter = new Filter(yaml, ['**.this'])
const files = modified(['config/settings.yml', 'config/settings.md', 'nothing/todo/with.this'])
const match = filter.match(files)
expect(match.ignore).toEqual(modified(['config/settings.yml']))
expect(match.ignoreall).toEqual([])
})
})

function modified(paths: string[]): File[] {
Expand Down
13 changes: 12 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ inputs:
Backslash escapes every potentially unsafe character.
required: true
default: none
files:
description: |
Custom input for files changed if you do your diff elsewhere.
Accepts a newline separated list of files, with optional leading status code, as per output of git diff --name-only or git diff --name-status
If no status supplied sets status to unmerged. Is set then only filers and list-files inputs are effective.
required: false
initial-fetch-depth:
description: |
How many commits are initially fetched from base branch.
Expand All @@ -44,11 +50,16 @@ inputs:
This option takes effect only when changes are detected using git against different base branch.
required: false
default: '100'
global-ignore:
description: |
Globally set ignore patterns on all filters via a file. Accepts a file path to a file with new line separate list.
Like a .gitignore but for your filtering.
required: false
outputs:
changes:
description: JSON array with names of all filters matching any of changed files
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
branding:
color: blue
Expand Down
Loading