-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (40 loc) · 1.43 KB
/
validate-pr.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
name: Validate PR
on:
pull_request:
branches:
- main
jobs:
validate-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Ensure the entire history is fetched
- name: Fetch main branch
run: git fetch origin main
- name: Check for required file changes
id: file_changes
run: |
# Get the list of files changed in the PR
files=$(git diff --name-only origin/main...HEAD)
# Initialize variables
changelog_changed=false
packagejson_changed=false
# Check if the required files are in the list of changed files
for file in $files; do
if [ "$file" == "CHANGELOG.md" ]; then
changelog_changed=true
fi
if [ "$file" == "package.json" ]; then
packagejson_changed=true
fi
done
# Set output variables
echo "::set-output name=changelog_changed::$changelog_changed"
echo "::set-output name=packagejson_changed::$packagejson_changed"
- name: Ensure required files are changed
if: steps.file_changes.outputs.changelog_changed == 'false' || steps.file_changes.outputs.packagejson_changed == 'false'
run: |
echo "ERROR: Both CHANGELOG.md and package.json must be modified in this PR."
exit 1