Get a list of files that differ between the specified commit and Git ref.
Checkout your repo with a fetch-depth
of 0
. Then it's as simple as:
# ...
steps:
- id: diff
uses: 'selfagency/diffmasterflex@v1'
# ...
sha
: The SHA of the commit to compare against. Defaults to HEAD of the branch that triggered the workflow.ref
: Ther ref to compare against. Defaults toorigin/main
.
diff
: A list of filenames.changed
: Whether any changes were detected.
jobs:
diff:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: 'actions/checkout@v2'
with:
fetch-depth: 0
- name: Diff against `master`
id: diff
uses: 'selfagency/diffmasterflex@v1'
with:
ref: 'origin/master'
- name: Check for changes
id: changes
if: ${{ steps.diff.outputs.changed == 'true' }}
run:
DIFF="${{ steps.diff.outputs.diff }}"
if [[ $DIFF =~ "backend" ]]; then
BACKEND="true"
else
BACKEND="false"
fi
if [[ $DIFF =~ "frontend" ]]; then
FRONTEND="true"
else
FRONTEND="false"
fi
echo "backend=${BACKEND}" >> "${GITHUB_OUTPUT}"
echo "frontend=${FRONTEND}" >> "${GITHUB_OUTPUT}"
- name: Test backend
if: ${{ steps.changes.outputs.backend == 'true' }}
run: 'npm run test:backend'
- name: Test frontend
if: ${{ steps.changes.outputs.fronted == 'true }}
run: 'npm run test:frontend'