forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_marketing_version.sh
61 lines (51 loc) · 2.09 KB
/
check_marketing_version.sh
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
#!/bin/bash
# Check if MARKETING_VERSION has changed
# The cut -d ' ' -f3 takes the output from grep command as input.
# For example, let's assume that the Common.xcconfig file contains the following line:
# MARKETING_VERSION = 100.2.44
# grep will return -> MARKETING_VERSION = 100.2.44
# The cut command will then extract the third field from the input, using a space (' ') as the delimiter.
# Output: 100.2.44
#!/bin/bash
# Get the current branch's MARKETING_VERSION
CURRENT_VERSION=$(grep 'MARKETING_VERSION' Client/Configuration/Common.xcconfig | cut -d ' ' -f3)
if [ -n "$CIRCLECI" ]; then
# CircleCI: Compare against the previous commit on the same branch
echo "Running on CircleCI, checking against $CIRCLE_BRANCH~1"
# Check if there is a previous commit available
if git rev-parse "$CIRCLE_BRANCH~1" >/dev/null 2>&1; then
OLD_VERSION=$(git show "$CIRCLE_BRANCH~1:Client/Configuration/Common.xcconfig" | grep 'MARKETING_VERSION' | cut -d ' ' -f3)
else
echo "No previous commit found on $CIRCLE_BRANCH. Assuming the current version."
OLD_VERSION=$CURRENT_VERSION
fi
elif [ -n "$GITHUB_ACTIONS" ]; then
# GitHub Actions: Compare against the main branch
echo "Running on GitHub Actions, checking against the main branch"
# Fetch the main branch
git fetch origin main || { echo "Failed to fetch main branch"; exit 1; }
# Get the MARKETING_VERSION from the main branch
OLD_VERSION=$(git show origin/main:Client/Configuration/Common.xcconfig | grep 'MARKETING_VERSION' | cut -d ' ' -f3)
if [ $? -ne 0 ]; then
echo "Failed to retrieve MARKETING_VERSION from main branch"
exit 1
fi
else
echo "Not running in a CI environment. Exiting..."
exit 0
fi
# Compare versions
if [ "$CURRENT_VERSION" = "$OLD_VERSION" ]; then
echo "MARKETING_VERSION has not changed. Exiting..."
# Detect CI environment and exit appropriately
if [ -n "$CIRCLECI" ]; then
circleci-agent step halt
elif [ -n "$GITHUB_ACTIONS" ]; then
echo "skipnext=true" >> $GITHUB_OUTPUT
else
exit 0
fi
else
echo "MARKETING_VERSION has changed from $OLD_VERSION to $CURRENT_VERSION"
exit 0
fi