-
Notifications
You must be signed in to change notification settings - Fork 7
82 lines (74 loc) · 3.45 KB
/
version-guard.yml
File metadata and controls
82 lines (74 loc) · 3.45 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
# A workflow for validating that release branch versions match the version in code
name: Version Number Validation
# Triggers the workflow when we open/update a PR from a rel/* branch
on:
push:
branches:
- 'rel/*'
tags:
- '*'
jobs:
version-check:
name: Verify Version Number Matches Branch/Tag
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
# Extract version from branch name and strings.xml, then compare them
- name: Validate Version Match
id: validate_version_match
run: |
# Determine if this is a tag or branch push
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION_NAME="${GITHUB_REF#refs/tags/}"
echo "Detected tag push: $VERSION_NAME"
elif [[ "${GITHUB_REF}" == refs/heads/rel/* ]]; then
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
if [[ $BRANCH_NAME =~ ^rel/(.+)$ ]]; then
VERSION_NAME="${BASH_REMATCH[1]}"
echo "Detected rel/* branch push: $VERSION_NAME"
else
ERROR_MESSAGE="Error: branch name does not match expected pattern"
echo "$ERROR_MESSAGE"
echo "ERROR_MESSAGE=$ERROR_MESSAGE" >> $GITHUB_ENV
exit 1
fi
else
echo "Info: Not a rel/* branch or tag push. Exiting successfully."
exit 0
fi
# Extract version from strings.xml
STRINGS_VERSION=$(grep -o '<string name="klaviyo_sdk_version_override">[^<]*</string>' sdk/core/src/main/res/values/strings.xml | sed 's/.*>\([^<]*\)<.*/\1/')
echo "strings.xml version: $STRINGS_VERSION"
# Compare versions
if [ "$VERSION_NAME" = "$STRINGS_VERSION" ]; then
echo "✅ Version match confirmed: $VERSION_NAME"
else
ERROR_MESSAGE="❌ Version mismatch! Expected version: $VERSION_NAME, strings.xml version: $STRINGS_VERSION. Use ./bump_version.sh to update the version number in this branch/tag (or correct the branch/tag name)."
echo "$ERROR_MESSAGE"
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "STRINGS_VERSION=$STRINGS_VERSION" >> $GITHUB_ENV
echo "ERROR_MESSAGE=$ERROR_MESSAGE" >> $GITHUB_ENV
exit 1
fi
# Send Slack notification on failure
- name: Send Slack notification on failure
if: failure()
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "🚨 Release Version Mismatch Detected"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "🚨 Release Version Mismatch Detected\n"
- type: "section"
text:
type: "mrkdwn"
text: "*Repository:* ${{ github.repository }}\n*Ref:* `${{ github.ref_name }}`\n*Expected Version:* `${{ env.VERSION_NAME }}`\n*strings.xml Version:* `${{ env.STRINGS_VERSION }}`\n*Error:* `${{ env.ERROR_MESSAGE }}`\n*Action:* Please run `./bump_version.sh` to update the version number in this branch/tag (or correct the branch/tag name)."
- type: "section"
text:
type: "mrkdwn"
text: "*Workflow Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>"