Skip to content

Commit bf60ca8

Browse files
author
Casper NY. Ong
committed
Attempt to add Discord Webhook Notifcation for CodeMagic CI/CD
1 parent 059a557 commit bf60ca8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

codemagic.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ workflows:
44
max_build_duration: 60
55
instance_type: mac_mini_m1
66
environment:
7+
groups:
8+
- discord_credentials
79
vars:
810
XCODE_WORKSPACE: "FrameExtractionTool.xcodeproj"
911
XCODE_SCHEME: "FrameExtractionTool"
@@ -46,10 +48,43 @@ workflows:
4648
script: |
4749
cd build
4850
unzip -l FrameExtractionTool-unsigned.ipa | head -20
51+
- name: Create changelog
52+
script: |
53+
if [[ -z ${CM_PREVIOUS_COMMIT} ]]; then
54+
echo "No previous builds found to generate changelog" | tee release_notes.txt
55+
else
56+
echo "$(git log --oneline $CM_PREVIOUS_COMMIT..$CM_COMMIT)" | tee release_notes.txt
57+
fi
4958
artifacts:
5059
- build/FrameExtractionTool-unsigned.ipa
5160
- build/FrameExtractionTool.xcarchive
5261
- /tmp/xcodebuild_logs/*.log
62+
publishing:
63+
scripts:
64+
- name: Discord notification
65+
script: |
66+
set -ex
67+
68+
# Get artifact link for the IPA file
69+
APP_LINK=$(echo $CM_ARTIFACT_LINKS | jq -r '.[] | select(.name | contains("FrameExtractionTool-unsigned.ipa")) | .url // "No artifact link available"')
70+
71+
# Get first 7 digits of commit number
72+
COMMIT=$(echo "${CM_COMMIT}" | sed 's/^\(........\).*/\1/;q')
73+
74+
# Get commit message
75+
COMMIT_MESSAGE=$(git log --format=%B -n 1 $CM_COMMIT)
76+
77+
# Get commit author
78+
AUTHOR=$(git show -s --format='%ae' $CM_COMMIT)
79+
80+
# Get build status
81+
BUILD_STATUS="✅ Build Successful"
82+
83+
# Send Discord notification
84+
curl -H "Content-Type: multipart/form-data" \
85+
-F 'payload_json={"username" : "FrameExtractionTool-CI", "content": "'"$BUILD_STATUS"' - iOS Unsigned Build\n\n**Commit:** `'"$COMMIT"'`\n\n**Commit message:** '"$COMMIT_MESSAGE"'\n\n**Branch:** '"$CM_BRANCH"'\n\n**Author:** '"$AUTHOR"'\n\n**Build:** '"$CM_BUILD_URL"'\n\n**Artifacts:**\n'"$APP_LINK"'\n"}' \
86+
-F "file1=@release_notes.txt" \
87+
$WEBHOOK_URL
5388
5489
ios-release-workflow:
5590
name: iOS Release Build
@@ -62,6 +97,8 @@ workflows:
6297
- pattern: 'v*'
6398
include: true
6499
environment:
100+
groups:
101+
- discord_credentials
65102
vars:
66103
XCODE_WORKSPACE: "FrameExtractionTool.xcodeproj"
67104
XCODE_SCHEME: "FrameExtractionTool"
@@ -110,7 +147,45 @@ workflows:
110147
cd build
111148
VERSION=${CM_TAG#v}
112149
unzip -l "FrameExtractionTool-$VERSION-unsigned.ipa" | head -20
150+
- name: Create release changelog
151+
script: |
152+
if [[ -z ${CM_PREVIOUS_COMMIT} ]]; then
153+
echo "Release $CM_TAG" | tee release_notes.txt
154+
echo "No previous builds found to generate changelog" >> release_notes.txt
155+
else
156+
echo "Release $CM_TAG" | tee release_notes.txt
157+
echo "$(git log --oneline $CM_PREVIOUS_COMMIT..$CM_COMMIT)" >> release_notes.txt
158+
fi
113159
artifacts:
114160
- build/FrameExtractionTool-*-unsigned.ipa
115161
- build/FrameExtractionTool-*.xcarchive
116162
- /tmp/xcodebuild_logs/*.log
163+
publishing:
164+
scripts:
165+
- name: Discord release notification
166+
script: |
167+
set -ex
168+
169+
# Get version from tag
170+
VERSION=${CM_TAG#v}
171+
172+
# Get artifact link for the release IPA file
173+
APP_LINK=$(echo $CM_ARTIFACT_LINKS | jq -r '.[] | select(.name | contains("FrameExtractionTool-") and contains("-unsigned.ipa")) | .url // "No artifact link available"')
174+
175+
# Get first 7 digits of commit number
176+
COMMIT=$(echo "${CM_COMMIT}" | sed 's/^\(........\).*/\1/;q')
177+
178+
# Get commit message
179+
COMMIT_MESSAGE=$(git log --format=%B -n 1 $CM_COMMIT)
180+
181+
# Get commit author
182+
AUTHOR=$(git show -s --format='%ae' $CM_COMMIT)
183+
184+
# Get build status
185+
BUILD_STATUS="🚀 Release Build Successful"
186+
187+
# Send Discord notification
188+
curl -H "Content-Type: multipart/form-data" \
189+
-F 'payload_json={"username" : "FrameExtractionTool-CI", "content": "'"$BUILD_STATUS"' - iOS Release v'"$VERSION"'\n\n**Release Tag:** `'"$CM_TAG"'`\n\n**Commit:** `'"$COMMIT"'`\n\n**Commit message:** '"$COMMIT_MESSAGE"'\n\n**Branch:** '"$CM_BRANCH"'\n\n**Author:** '"$AUTHOR"'\n\n**Build:** '"$CM_BUILD_URL"'\n\n**Release Artifacts:**\n'"$APP_LINK"'\n"}' \
190+
-F "file1=@release_notes.txt" \
191+
$WEBHOOK_URL

0 commit comments

Comments
 (0)