-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
47 lines (42 loc) · 1.61 KB
/
action.yaml
File metadata and controls
47 lines (42 loc) · 1.61 KB
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
---
name: detect-changes
description: Detect changed files by providing a list of glob patterns
inputs:
patterns:
description: A list of glob patterns to detect changes in. Defaults to ['*'].
default: "['*']"
outputs:
detected:
description: Returns if any changed files were matched by the provided glob patterns.
value: ${{ steps.check.outputs.DETECTED }}
runs:
using: composite
steps:
- name: Check for changed files
id: check
env:
PATTERNS: ${{ inputs.patterns }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
shell: bash
run: |
set -euo pipefail
if [ "$GITHUB_EVENT_NAME" != 'pull_request' ]; then
# This is a short-circuit for when not run on a PR.
# It saves having to make the job conditions even more complicated.
echo "Not running on a PR. Hard-coding result:"
echo "DETECTED=true" | tee -a "$GITHUB_OUTPUT"
exit 0
fi
# TODO (@NickLarsenNZ): validate the YAML list. mikefarah-yq doesn't do this.
# This is cursed... we use `.[] | .` to remove quotes and any yaml formatting.
readarray -t GLOBS < <(echo -n "$PATTERNS" | yq '.[] | .')
DETECTED="false"
for GLOB in "${GLOBS[@]}"; do
if ! git diff --exit-code --name-only "${BASE_SHA}.." -- "$GLOB"; then
# When git diff exist with an error, that means there was a diff
# for the glob.
DETECTED="true"
fi
done
echo "DETECTED=$DETECTED" | tee -a "$GITHUB_OUTPUT"