I would like to make a GitHub workflow that runs some find-and-replace substitutions on new files that are committed to the repository.
I can't find where to start because I can't find a workflow trigger that seems to be able to detect when a new file is committed.
What set up could I use to run the substitutions?
CodePudding user response:
I would suggest you to use the dorny/paths-filter GitHub Actions to discover if a file is added in your PR, as example:
- uses: dorny/paths-filter@v2
id: filter
with:
# Enable listing of files matching each filter.
# Paths to files will be available in `${FILTER_NAME}_files` output variable.
# Paths will be escaped and space-delimited.
# Output is usable as command-line argument list in Linux shell
list-files: shell
# Changed file can be 'added', 'modified', or 'deleted'.
# By default, the type of change is not considered.
# Optionally, it's possible to specify it using nested
# dictionary, where the type of change composes the key.
# Multiple change types can be specified using `|` as the delimiter.
filters: |
added:
- added: '**'
Then run step only in case of added
- name: Do some stuff on added files
if: steps.filter.outputs.added == 'true'
run: |
for file in ${{ steps.filter.outputs.added_files }}; do
echo "${file} added"
done
See the outputs section for further doc