-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (41 loc) · 1.46 KB
/
changes.yaml
File metadata and controls
47 lines (41 loc) · 1.46 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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Changes
on:
workflow_call:
inputs:
paths:
description: |
Newline-separated list of path prefixes to check for changes against origin/main.
Example:
docker/
.github/workflows/docker.yaml
required: true
type: string
outputs:
changed:
description: "true if any file under the given paths changed on this branch compared to origin/main"
value: ${{ jobs.changes.outputs.changed }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changes.outputs.changed }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Check for changes
id: changes
run: |
mergeBase=$(git merge-base origin/main "${{ github.sha }}")
if [ "$mergeBase" = "${{ github.sha }}" ]; then
mergeBase=$(git rev-parse "${{ github.sha }}~1")
fi
pattern=$(echo "${{ inputs.paths }}" | sed '/^$/d' | sed 's|.*|^&|' | paste -sd'|')
if git diff --name-only "$mergeBase" "${{ github.sha }}" | grep -Eq "$pattern"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Report changes
run: echo "changed=${{ steps.changes.outputs.changed }}"