Skip to content

Commit

Permalink
Add working-directory input (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd authored May 31, 2023
1 parent 9665dd9 commit 019de5a
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Header #########################################################################################

# Author: Florian Bernd
# Source: https://github.com/zysharp/templates
# Source: https://github.com/zyactions/templates

### Common Settings ################################################################################

Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Header #########################################################################################

# Author: Florian Bernd
# Source: https://github.com/zysharp/templates
# Source: https://github.com/zyactions/templates

### Git Line Endings ###############################################################################

Expand Down
4 changes: 4 additions & 0 deletions .github/actions/wrapper/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Test Wrapper

inputs:
working-directory:
type: string
required: false
pattern:
type: string
required: true
Expand Down Expand Up @@ -30,6 +33,7 @@ runs:
id: glob
uses: ./.
with:
working-directory: ${{ inputs.working-directory }}
pattern: ${{ inputs.pattern }}
values: ${{ inputs.values }}
pipe: ${{ inputs.pipe }}
Expand Down
23 changes: 11 additions & 12 deletions .github/actions/wrapper/shellquote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ set -e

separator=$1
if [[ -z $separator ]]; then
separator="\n"
separator="\n"
fi

first=true

while IFS= read -r line;
do
if [[ $line == '' ]]; then
continue
fi
while IFS= read -r line; do
if [[ $line == '' ]]; then
continue
fi

if [ "$first" = false ]; then
printf "$separator"
fi
first=false
if [ "$first" = false ]; then
printf "$separator"
fi
first=false

quoted=${line//\'/\'\\\'\'}
printf "'%s'" "$quoted"
quoted=${line//\'/\'\\\'\'}
printf "'%s'" "$quoted"
done

echo ''
168 changes: 103 additions & 65 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,127 +12,165 @@ concurrency:
cancel-in-progress: true

jobs:
test:
name: Test
test-fs:
name: Test (in = fs, os = ${{ matrix.platform }}, sub = ${{ matrix.subdirectory }}, pipe = ${{ matrix.return-pipe }})
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
platform : [ubuntu-latest, macos-latest, windows-latest]
subdirectory: [false, true]
return-pipe : [false, true]
env:
EXPECTED: "'test/a.txt' 'test/c.txt'"
EXPECTED_FS: ${{ matrix.platform == 'windows-latest' && '''test\a.txt'' ''test\c.txt''' || '''test/a.txt'' ''test/c.txt''' }}
PATTERN: ${{ matrix.subdirectory && '[ac].txt' || 'test/[ac].txt' }}
WORKDIR: ${{ matrix.subdirectory && 'test' || '' }}
EXPECTED: >-
${{
matrix.subdirectory && '''a.txt'' ''c.txt''' ||
(
matrix.platform == 'windows-latest' && '''test\a.txt'' ''test\c.txt''' || '''test/a.txt'' ''test/c.txt'''
)
}}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: 'TEST: File System Input'
id: glob-fs
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
- name: FAILED
if: steps.glob-fs.outputs.matches != env.EXPECTED_FS
run: |
echo "Matches:"
echo "${{ steps.glob-fs.outputs.matches }}"
exit 1
- name: 'TEST: Value Input'
id: glob-values
- name: TEST
id: glob
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
values: |-
test/a.txt
test/b.txt
test/c.txt
- name: FAILED
if: steps.glob-values.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob-values.outputs.matches }}"
exit 1
working-directory: ${{ env.WORKDIR }}
pattern: ${{ env.PATTERN }}
return-pipe: ${{ matrix.return-pipe }}

- name: 'TEST: Pipe Input'
id: glob-pipe
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
pipe: >-
ls -1d test/*
- name: FAILED
if: steps.glob-pipe.outputs.matches != env.EXPECTED
if: matrix.return-pipe == false && steps.glob.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob-pipe.outputs.matches }}"
echo "${{ steps.glob.outputs.matches }}"
exit 1
- name: 'TEST: File System Input (Pipe)'
id: glob-fs-pipe
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
return-pipe: true
- name: Evaluate
id: glob-fs-pipe-result
if: matrix.return-pipe
id: glob-result
shell: bash
run: |
result=$(${{ steps.glob-fs-pipe.outputs.pipe }})
result=$(${{ steps.glob.outputs.pipe }})
echo "matches<<EOF" >> $GITHUB_OUTPUT
echo "$result" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: FAILED
if: steps.glob-fs-pipe-result.outputs.matches != env.EXPECTED_FS
if: matrix.return-pipe && steps.glob-result.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob-fs-pipe-result.outputs.matches }}"
echo "${{ steps.glob-result.outputs.matches }}"
exit 1
- name: 'TEST: Value Input (Pipe)'
id: glob-values-pipe
test-values:
name: Test (in = values, os = ${{ matrix.platform }}, pipe = ${{ matrix.return-pipe }})
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform : [ubuntu-latest, macos-latest, windows-latest]
return-pipe : [false, true]
env:
PATTERN: 'test/[ac].txt'
EXPECTED: "'test/a.txt' 'test/c.txt'"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: TEST
id: glob
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
return-pipe: true
pattern: ${{ env.PATTERN }}
values: |-
test/a.txt
test/b.txt
test/c.txt
return-pipe: ${{ matrix.return-pipe }}
- name: FAILED
if: matrix.return-pipe == false && steps.glob.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob.outputs.matches }}"
exit 1
- name: Evaluate
id: glob-values-pipe-result
if: matrix.return-pipe
id: glob-result
shell: bash
run: |
result=$(${{ steps.glob-values-pipe.outputs.pipe }})
result=$(${{ steps.glob.outputs.pipe }})
echo "matches<<EOF" >> $GITHUB_OUTPUT
echo "$result" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: FAILED
if: steps.glob-values-pipe-result.outputs.matches != env.EXPECTED
if: matrix.return-pipe && steps.glob-result.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob-values-pipe-result.outputs.matches }}"
echo "${{ steps.glob-result.outputs.matches }}"
exit 1
- name: 'TEST: Pipe Input (Pipe)'
id: glob-pipe-pipe
test-pipe:
name: Test (in = pipe, os = ${{ matrix.platform }}, sub = ${{ matrix.subdirectory }}, pipe = ${{ matrix.return-pipe }})
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform : [ubuntu-latest, macos-latest, windows-latest]
subdirectory: [false, true]
return-pipe : [false, true]
env:
PATTERN: 'test/[acdf].txt'
WORKDIR: ${{ matrix.subdirectory && 'test/sub' || '' }}
EXPECTED: ${{ matrix.subdirectory && '''test/d.txt'' ''test/f.txt''' || '''test/a.txt'' ''test/c.txt''' }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: TEST
id: glob
uses: ./.github/actions/wrapper
with:
pattern: 'test/[ac].txt'
return-pipe: true
working-directory: ${{ env.WORKDIR }}
pattern: ${{ env.PATTERN }}
pipe: >-
ls -1d test/*
return-pipe: ${{ matrix.return-pipe }}
- name: FAILED
if: matrix.return-pipe == false && steps.glob.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob.outputs.matches }}"
exit 1
- name: Evaluate
id: glob-pipe-pipe-result
if: matrix.return-pipe
id: glob-result
shell: bash
run: |
result=$(${{ steps.glob-pipe-pipe.outputs.pipe }})
result=$(${{ steps.glob.outputs.pipe }})
echo "matches<<EOF" >> $GITHUB_OUTPUT
echo "$result" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: FAILED
if: steps.glob-pipe-pipe-result.outputs.matches != env.EXPECTED
if: matrix.return-pipe && steps.glob-result.outputs.matches != env.EXPECTED
run: |
echo "Matches:"
echo "${{ steps.glob-pipe-pipe-result.outputs.matches }}"
echo "${{ steps.glob-result.outputs.matches }}"
exit 1
results:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Test Results
needs: [test-fs, test-values, test-pipe]
steps:
- run: exit 1
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 ZyActions
Copyright (c) 2022 Florian Bernd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A GitHub Action for matching `glob` patterns.
## Features

- Matches filenames and pathes using [glob patterns][glob-cheat-sheet]
- ... in the live file system
- ... in the file system
- ... from a user-supplied input
- ... from an input pipe
- Fast execution
Expand All @@ -21,7 +21,7 @@ A GitHub Action for matching `glob` patterns.

## Usage

### Match Files in the Life File System
### Match Files in the File System

```yaml
steps:
Expand Down Expand Up @@ -109,6 +109,16 @@ The `return-pipe` option can also be combined with the `pipe` input to insert a

## Inputs

### `working-directory`

The working-directory for the action.

Defaults to the repository root directory (`github.workspace`).

When working on the file system, patterns and matches are considered relative to the specified working directory. If the `pipe` input is used, the pipe command will be executed in the current `working-directory`. This input has no effect if the `values` input is set.

The working directory will as well be included in the `pipe` output, if `return-pipe` is enabled.

### `pattern`

One or more file, path, or placeholder patterns that describe which items to match.
Expand All @@ -123,7 +133,7 @@ Check out the [glob pattern cheat sheet][glob-cheat-sheet] for reference. Multi

An optional list of values to be matched (separated by line breaks).

The action operates on the life file system if neither the `values`-, nor the `pipe`-input is set.
The action operates on the file system if neither the `values`-, nor the `pipe`-input is set.

> **Note**: This input must be used mutually exclusive with the `pipe` input.

Expand All @@ -133,12 +143,21 @@ An optional pipe input from which the input values are to be read.

This must be set to a valid shell command line (bash) that can be used for piping. The command must output to `stdout` and separate the individual values by line breaks.

The action operates on the life file system if neither the `values`-, nor the `pipe`-input is set.
The action operates on the file system if neither the `values`-, nor the `pipe`-input is set.

> **Warning**
>
> The command passed to this input will be evaluated and should not come from untrusted sources.

> **Note**:
>
> The pipe command is executed in the current `working-directory` by default. If the pipe command is to be executed in another working directory, make sure to properly insert a directory change command.
>
> Example pipe command:
> ```bash
> (cd '/my/absolute/workdir' && ls -1)
> ```

> **Note**: This input must be used mutually exclusive with the `values` input.

### `return-pipe`
Expand Down
Loading

0 comments on commit 019de5a

Please sign in to comment.