-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
58 lines (51 loc) · 1.81 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Conditional Container Builder with Fallback
description: Build if trigger conditions are met, else use fallback image
branding:
icon: package
color: blue
inputs:
### Required
# Nothing!
### Typical / recommended
triggers:
description: Paths used to trigger an event; e.g. ('./backend/' './frontend/); always trigger if omitted
### Usually a bad idea / not recommended
diff_branch:
description: Branch to diff against, defaults to the default branch
default: ${{ github.event.repository.default_branch }}
outputs:
triggered:
description: Boolean result of triggers
value: ${{ steps.diff.outputs.triggered }}
runs:
using: composite
steps:
# Check if a build is required (steps.build.outputs.triggered=true|false)
- uses: actions/checkout@v4
- name: Diff for changes
shell: bash
id: diff
run: |
# Always fire if triggers are omitted
if [ -z "${{ inputs.triggers }}" ]; then
echo "Always fire when triggers are omitted!"
echo "triggered=true" >> $GITHUB_OUTPUT
exit 0
fi
# Build if changed files (git diff) match triggers
TRIGGERS=${{ inputs.triggers }}
git fetch origin ${{ inputs.diff_branch }}
while read -r check; do
for t in "${TRIGGERS[@]}"; do
if [[ "${check}" =~ "${t}" ]]; then
# Output triggered=true for next steps
echo "Build triggered based on git diff"
echo -e "${t}\n --> ${check}"
echo "triggered=true" >> $GITHUB_OUTPUT
exit 0
fi
done
done < <(git diff origin/${{ inputs.diff_branch }} --name-only)
# If at this point, no trigger has fired
echo "Triggers have not fired"
echo "triggered=false" >> $GITHUB_OUTPUT