-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodemagic.yaml
More file actions
94 lines (75 loc) · 3.22 KB
/
codemagic.yaml
File metadata and controls
94 lines (75 loc) · 3.22 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
workflows:
build-and-upload-aab:
name: Build & Upload AAB
max_build_duration: 60
instance_type: mac_mini_m2
environment:
android_signing:
- keystore_reference # Replace with your keystore ID
groups:
- test
scripts:
- name: Set Android SDK location
script: |
echo "sdk.dir=$ANDROID_SDK_ROOT" > "$CM_BUILD_DIR/local.properties"
- name: Build signed release AAB
script: |
./gradlew bundleRelease
- name: Read Changelog from `CHANGELOG.md` and Send to Slack
script: |
cd $CM_BUILD_DIR
# Read the contents of the CHANGELOG.md file
if [ -f "CHANGELOG.md" ]; then
CHANGELOG_CONTENT=$(cat CHANGELOG.md)
else
CHANGELOG_CONTENT="No changelog found. Please add the latest changes to CHANGELOG.md."
fi
# Clean up the changelog content: Remove Markdown headers (lines starting with #)
CLEANED_CHANGELOG=$(echo "$CHANGELOG_CONTENT" | sed '/^#/d' | sed 's/```//g')
# Extract versionCode and versionName from the app/build.gradle.kts file
if [ -f "app/build.gradle.kts" ]; then
VERSION_CODE=$(grep -m 1 "versionCode" app/build.gradle.kts | cut -d '=' -f 2 | tr -d ' ' | tr -d ';')
VERSION_NAME=$(grep -m 1 "versionName" app/build.gradle.kts | cut -d '=' -f 2 | tr -d ' ' | tr -d '"')
fi
# Fallback if values weren't found
if [ -z "$VERSION_CODE" ]; then VERSION_CODE="N/A"; fi
if [ -z "$VERSION_NAME" ]; then VERSION_NAME="N/A"; fi
echo "Version Code: $VERSION_CODE"
echo "Version Name: $VERSION_NAME"
# Check if values are found, if not, print an error
if [ -z "$VERSION_CODE" ]; then
echo "Error: versionCode not found!"
exit 1
fi
if [ -z "$VERSION_NAME" ]; then
echo "Error: versionName not found!"
exit 1
fi
# Fetch the .aab file path
AAB_FILE_PATH="app/build/outputs/bundle/release/app-release.aab"
# Construct the download link (replace with your actual hosting link)
DOWNLOAD_LINK="https://your-download-link.com/$AAB_FILE_PATH"
# Prepare the Slack message
SLACK_MESSAGE="Build Success! :white_check_mark:
Version: $VERSION_NAME (Code: $VERSION_CODE)
Download the AAB here: $DOWNLOAD_LINK
Changelog:
\`\`\`
$CLEANED_CHANGELOG
\`\`\`"
# If SLACK_WEBHOOK_URL is not set, exit the script
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "Error: SLACK_WEBHOOK_URL is not set!"
exit 1
fi
# Send the message to Slack
curl -X POST -H 'Content-type: application/json' \
--data '{"text": "'"$SLACK_MESSAGE"'"}' \
$SLACK_WEBHOOK_URL
if [ $? -ne 0 ]; then
echo "Error: Slack notification failed!"
exit 2
fi
echo "Slack message sent successfully!"
artifacts:
- app/build/outputs/**/*.aab