-
Notifications
You must be signed in to change notification settings - Fork 7
51 lines (42 loc) · 1.64 KB
/
pr_check.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
name: Pull Request Check
on:
pull_request:
types: [opened, synchronize]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check PR
run: |
# Get the list of added, modified, renamed, or deleted files
ADDED_FILES=$(git diff --name-only --diff-filter=A HEAD~1)
MODIFIED_FILES=$(git diff --name-only --diff-filter=M HEAD~1)
RENAMED_FILES=$(git diff --name-only --diff-filter=R HEAD~1)
DELETED_FILES=$(git diff --name-only --diff-filter=D HEAD~1)
# Concatenate all changes
ALL_CHANGES="$ADDED_FILES$MODIFIED_FILES$RENAMED_FILES$DELETED_FILES"
# Check that all changes are within the 'industries' directory
if echo "$ALL_CHANGES" | grep -qv "^industries/"; then
echo "Error: All changes should be within the 'industries' directory"
exit 1
fi
# Check that all changes are within the same app
APPS=$(echo "$ALL_CHANGES" | awk -F/ '{print $2"/"$3"/"$4}' | sort -u)
APP_COUNT=$(echo "$APPS" | wc -l)
if (( APP_COUNT > 1 )); then
echo "Error: More than one app has been changed"
exit 1
fi
# Check that config.json is not changed
if echo "$MODIFIED_FILES" | grep -q "config.json"; then
echo "Error: config.json should not be changed"
exit 1
fi
# Check that no files are added, deleted or renamed
if [[ -n "$ADDED_FILES" || -n "$DELETED_FILES" || -n "$RENAMED_FILES" ]]; then
echo "Error: No files should be added, deleted or renamed"
exit 1
fi