-
Notifications
You must be signed in to change notification settings - Fork 1.3k
54 lines (48 loc) · 1.53 KB
/
protect-files.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
# Runs if there are changes to the paths: list.
# Starts a matrix job to check for modified files, then sets output based on the results.
# The input decides if the label job is ran, adding a label to the PR.
---
name: Protect files
on:
pull_request:
types:
- opened
- synchronize
- unlabeled
paths:
- "util/Migrator/DbScripts/**.sql"
jobs:
changed-files:
name: Check for file changes
runs-on: ubuntu-22.04
outputs:
changes: ${{steps.check-changes.outputs.changes_detected}}
strategy:
fail-fast: true
matrix:
include:
- name: Database Scripts
path: util/Migrator/DbScripts
label: "DB-migrations-changed"
steps:
- name: Check out repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 2
- name: Check for file changes
id: check-changes
run: |
MODIFIED_FILES=$(git diff --name-only --diff-filter=M HEAD~1)
for file in $MODIFIED_FILES
do
if [[ $file == *"${{ matrix.path }}"* ]]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
break
else echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
done
- name: Add label to pull request
if: contains(steps.check-changes.outputs.changes_detected, 'true')
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 # 1.0.4
with:
add-labels: ${{ matrix.label }}