1
+ name : PR Validation
2
+
3
+ on :
4
+ pull_request :
5
+ branches : [develop, main]
6
+ types : [opened, synchronize]
7
+
8
+ jobs :
9
+ validate-version :
10
+ name : Validate Version Update
11
+ runs-on : ubuntu-latest
12
+
13
+ steps :
14
+ - uses : actions/checkout@v4
15
+ with :
16
+ fetch-depth : 0
17
+
18
+ - name : Check which branch we're merging to
19
+ id : target
20
+ run : |
21
+ echo "base_branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT
22
+ echo "head_branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT
23
+ echo "Merging from ${{ github.head_ref }} to ${{ github.base_ref }}"
24
+
25
+ # Validation for feature -> develop PRs
26
+ - name : Validate feature to develop
27
+ if : github.base_ref == 'develop' && startsWith(github.head_ref, 'feature/')
28
+ run : |
29
+ echo "## Validating feature → develop PR"
30
+
31
+ # Get version from base branch (develop)
32
+ git fetch origin develop
33
+ BASE_VERSION=$(git show origin/develop:Info.plist | grep -A1 "CFBundleShortVersionString" | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
34
+ echo "Develop branch version: $BASE_VERSION"
35
+
36
+ # Get version from PR branch
37
+ PR_VERSION=$(grep -A1 "CFBundleShortVersionString" Info.plist | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
38
+ echo "PR branch version: $PR_VERSION"
39
+
40
+ # Check if version was updated
41
+ if [ "$BASE_VERSION" = "$PR_VERSION" ]; then
42
+ echo "❌ Error: Version not updated in Info.plist"
43
+ echo "Please update the version number when merging features to develop"
44
+ echo ""
45
+ echo "Current version: $BASE_VERSION"
46
+ echo "Expected: A higher version number"
47
+ exit 1
48
+ fi
49
+
50
+ # Validate version format (should be x.y.z)
51
+ if ! echo "$PR_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
52
+ echo "❌ Error: Invalid version format"
53
+ echo "Version should be in format: x.y.z (e.g., 1.2.3)"
54
+ echo "Found: $PR_VERSION"
55
+ exit 1
56
+ fi
57
+
58
+ echo "✅ Version updated: $BASE_VERSION → $PR_VERSION"
59
+
60
+ # Validation for develop -> main PRs
61
+ - name : Validate develop to main
62
+ if : github.base_ref == 'main' && github.head_ref == 'develop'
63
+ run : |
64
+ echo "## Validating develop → main PR"
65
+
66
+ # Check if CHANGELOG.md was updated
67
+ if ! git diff origin/main --name-only | grep -q "CHANGELOG.md"; then
68
+ echo "❌ Error: CHANGELOG.md not updated"
69
+ echo "Please update CHANGELOG.md with release notes before merging to main"
70
+ exit 1
71
+ fi
72
+
73
+ echo "✅ CHANGELOG.md has been updated"
74
+
75
+ # Get current version
76
+ VERSION=$(grep -A1 "CFBundleShortVersionString" Info.plist | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
77
+ echo "Release version: $VERSION"
78
+
79
+ # Check if this version already exists as a tag
80
+ if git rev-parse "v$VERSION" >/dev/null 2>&1; then
81
+ echo "⚠️ Warning: Version v$VERSION already exists as a tag"
82
+ echo "The release workflow will skip creating a new release"
83
+ fi
84
+
85
+ # Validation for hotfix -> main PRs
86
+ - name : Validate hotfix to main
87
+ if : github.base_ref == 'main' && startsWith(github.head_ref, 'hotfix/')
88
+ run : |
89
+ echo "## Validating hotfix → main PR"
90
+
91
+ # Get version from main branch
92
+ git fetch origin main
93
+ MAIN_VERSION=$(git show origin/main:Info.plist | grep -A1 "CFBundleShortVersionString" | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
94
+ echo "Main branch version: $MAIN_VERSION"
95
+
96
+ # Get version from PR branch
97
+ PR_VERSION=$(grep -A1 "CFBundleShortVersionString" Info.plist | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
98
+ echo "Hotfix version: $PR_VERSION"
99
+
100
+ # Check if version was updated
101
+ if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then
102
+ echo "❌ Error: Version not updated in Info.plist"
103
+ echo "Hotfixes must increment the version number"
104
+ exit 1
105
+ fi
106
+
107
+ # Check CHANGELOG update
108
+ if ! git diff origin/main --name-only | grep -q "CHANGELOG.md"; then
109
+ echo "❌ Error: CHANGELOG.md not updated"
110
+ echo "Please document the hotfix in CHANGELOG.md"
111
+ exit 1
112
+ fi
113
+
114
+ echo "✅ Hotfix validation passed"
115
+
116
+ check-conventional-commits :
117
+ name : Check Commit Messages
118
+ runs-on : ubuntu-latest
119
+
120
+ steps :
121
+ - uses : actions/checkout@v4
122
+ with :
123
+ fetch-depth : 0
124
+
125
+ - name : Check commit format
126
+ run : |
127
+ echo "## Checking commit message format"
128
+
129
+ # Get commits in this PR
130
+ COMMITS=$(git log --format="%s" origin/${{ github.base_ref }}..HEAD)
131
+
132
+ # Check if commits follow conventional format
133
+ INVALID_COMMITS=""
134
+ while IFS= read -r commit; do
135
+ if ! echo "$commit" | grep -qE '^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .+' && \
136
+ ! echo "$commit" | grep -qE '^Merge '; then
137
+ INVALID_COMMITS="${INVALID_COMMITS}❌ $commit\n"
138
+ fi
139
+ done <<< "$COMMITS"
140
+
141
+ if [ -n "$INVALID_COMMITS" ]; then
142
+ echo "⚠️ Warning: Some commits don't follow Conventional Commits format:"
143
+ echo -e "$INVALID_COMMITS"
144
+ echo ""
145
+ echo "Expected format: type(scope): description"
146
+ echo "Valid types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert"
147
+ echo ""
148
+ echo "This is a warning only - not blocking the PR"
149
+ else
150
+ echo "✅ All commits follow Conventional Commits format"
151
+ fi
0 commit comments