Skip to content

Commit

Permalink
Merge pull request #1 from colpal/hoisting
Browse files Browse the repository at this point in the history
Add support for "hoisting" mode
  • Loading branch information
nafarlee authored Nov 30, 2023
2 parents b6021b4 + e2d40bc commit ef56cbc
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 46 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ module.exports = {
sourceType: 'module',
},
rules: {
'import/extensions': ['error', 'ignorePackages'],
},
};
43 changes: 42 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
main:
runs-on: ubuntu-latest
outputs:
matches: ${{ steps.for-each-4.outputs.matches }}
matches: ${{ steps.for-each.outputs.matches }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -44,6 +44,47 @@ jobs:
- name: Run colpal/actions-for-each
id: for-each-4
uses: ./
with:
root-patterns: '*/'
filter-patterns: '**/main.*'
- if: steps.for-each-4.outputs.matches != '["dist/"]'
run: exit 1

- name: Run colpal/actions-for-each
id: for-each-5
uses: ./
with:
root-patterns: |
./
**/
filter-patterns: '**/main.*'
- if: steps.for-each-5.outputs.matches != '["./","dist/"]'
run: exit 1

- name: Run colpal/actions-for-each
id: for-each-6
uses: ./
with:
root-patterns: |
**/*-b/
filter-patterns: '**/file.txt'
- if: steps.for-each-6.outputs.matches != '["fixtures/function-b/","fixtures/run-b/"]'
run: exit 1

- name: Run colpal/actions-for-each
id: for-each-7
uses: ./
with:
root-patterns: |
./
filter-patterns: |
**/flie.txt
- if: steps.for-each-7.outputs.matches != '[]'
run: exit 1

- name: Run colpal/actions-for-each
id: for-each
uses: ./
with:
patterns: 'fixtures/run-*'

Expand Down
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ steps:
# ["function-a/file.txt","function-b/file.txt"]
```

### Parallel
### Static Parallel

```yaml
jobs:
Expand Down Expand Up @@ -75,11 +75,51 @@ steps:
- id: for-each
uses: colpal/[email protected]
with:
# REQUIRED
# REQUIRED (if `root-patterns` is not specified)
# The pattern(s) to be used to find folders/files. More than one pattern
# may be supplied by putting each on its own line.
patterns: string
patterns: single-line string | multi-line string

# OPTIONAL (only valid if `root-patterns` is specified)
# DEFAULT = **
# The pattern(s) to be used to find files/folders to provide to
# `root-patterns` (see the description of `root-patterns` for more
# details)
filter-patterns: single-line string | multi-line string

# REQUIRED (if `patterns` is not specified)
# The pattern(s) to be used to "hoist" files/folders matched by
# `filter-patterns`. The process is as follows:
# 1. `filter-patterns` is applied to the filesystem to create a list
# of paths (similar to what `patterns` does when specified alone)
# 2. `root-patterns` is then applied to the paths from the previous
# step. Any paths that match will be added to the `matches` output.
# 3. `dirname` will be applied to all paths from step 2 that DID NOT
# match `root-patterns`, effectively removing the last segment of
# the path. For example:
# `folder-a/subfolder-a/file-a` becomes `folder-a/subfolder-a/`
# `folder-a/subfolder-a/` becomes `folder-a/`
# `folder-a/` becomes `./`
# `./` becomes `./`
# 4. Repeat steps 2 - 4 until the only unmatched paths are "./"
# 5. `matches` is set as an output of the action
root-patterns: single-line string | multi-line string
outputs:
# An JSON-formatted array of paths that matched the pattern(s)
matches: ${{ steps.for-each.outputs.matches }}
```
## Recipes
### Find all folders that contain certain files
```yaml
- uses: colpal/[email protected]
with:
root-patterns: |
./
**/
filter-patterns: |
**/main.sh
**/start.sh
```
9 changes: 8 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ description: Create "matrix" compliant file/folder lists using patterns
inputs:
patterns:
description: The pattern(s) with which to match files/folders
required: true
root-patterns:
description: >
The pattern(s) to which all files/folders matched by `filter-patterns`
will be hoisted
filter-patterns:
description: >
The pattern(s) that will be used to filter (but not match) files/folders
default: '**'
outputs:
matches:
description: The files/folders that matched the pattern
Expand Down
Loading

0 comments on commit ef56cbc

Please sign in to comment.