forked from aymanaboghonim/elmentor-landing-page-clean
-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (81 loc) · 3.4 KB
/
pr-validation.yml
File metadata and controls
97 lines (81 loc) · 3.4 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: PR Validation
on:
pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check for prohibited branch merges
run: |
# Check if the PR is from a branch that should not be merged
if [ -f .github/.mergeignore ]; then
HEAD_BRANCH="${{ github.head_ref }}"
while IFS= read -r branch || [[ -n "$branch" ]]; do
# Skip comments
[[ "$branch" =~ ^#.*$ ]] && continue
# Skip empty lines
[[ -z "$branch" ]] && continue
if [[ "$HEAD_BRANCH" == "$branch" ]]; then
echo "⚠️ WARNING: Branch '$HEAD_BRANCH' is listed in .mergeignore file as a branch that should not be merged"
echo "::warning::This branch '$HEAD_BRANCH' should not be merged according to repository configuration"
fi
done < .github/.mergeignore
fi
- name: Check for merge conflicts
run: |
# Check if there would be merge conflicts with the target branch
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
echo "Checking for potential merge conflicts..."
git checkout ${{ github.base_ref }}
git pull
# Try to merge without committing
if git merge --no-commit --no-ff ${{ github.head_ref }}; then
echo "✅ No merge conflicts detected"
git merge --abort
exit 0
else
echo "⚠️ Potential merge conflicts detected!"
git merge --abort
# List files that would have conflicts
CONFLICTS=$(git diff --name-only --diff-filter=U)
echo "Files with potential conflicts:"
echo "$CONFLICTS"
# Don't fail the build, just warn
exit 0
fi
- name: Validate documentation links
if: success() || failure()
run: |
echo "Validating documentation links..."
# Check for broken relative links in markdown files
find . -name "*.md" -type f -exec grep -l "\[.*\](.*)" {} \; | while read file; do
echo "Checking links in $file"
grep -o "\[.*\](.*)" "$file" | grep -v "^http" | grep -v "^#" | while read link; do
# Extract the link path
path=$(echo "$link" | sed -n 's/.*(\(.*\))/\1/p')
# Skip anchors and URLs
if [[ "$path" == \#* || "$path" == http* ]]; then
continue
fi
# Check if the file exists
linkTarget=$(echo "$path" | sed 's/#.*//')
dir=$(dirname "$file")
if [[ "$linkTarget" == /* ]]; then
# Absolute path from repo root
if [[ ! -e ".${linkTarget}" ]]; then
echo "❌ Broken link in $file: $path"
fi
else
# Relative path
if [[ ! -e "$dir/$linkTarget" ]]; then
echo "❌ Broken link in $file: $path"
fi
fi
done
done