Skip to content

Commit f34745f

Browse files
authored
chore: send slack notification on sample app build (#496)
1 parent ce526c5 commit f34745f

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

.github/workflows/reusable_build_sample_apps.yml

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ jobs:
2525
cio-workspace-name: "Mobile: Native iOS & Android"
2626
cio-cdpapikey-secret-key: "CUSTOMERIO_JAVA_WORKSPACE_CDP_API_KEY"
2727
cio-siteid-secret-key: "CUSTOMERIO_JAVA_WORKSPACE_SITE_ID"
28+
firebase-app-id-secret-key: "SAMPLE_APPS_JAVA_FIREBASE_APP_ID"
2829
- sample-app: "kotlin_compose"
2930
cio-workspace-name: "Mobile: xiOS CocoaPods FCM + Kotlin Android"
3031
cio-cdpapikey-secret-key: "CUSTOMERIO_KOTLIN_WORKSPACE_CDP_API_KEY"
3132
cio-siteid-secret-key: "CUSTOMERIO_KOTLIN_WORKSPACE_SITE_ID"
33+
firebase-app-id-secret-key: "SAMPLE_APPS_KOTLIN_FIREBASE_APP_ID"
3234

3335
name: Building app...${{ matrix.sample-app }}
3436
permissions:
@@ -39,6 +41,15 @@ jobs:
3941
with:
4042
fetch-depth: 0 # Workaround for bug https://github.com/actions/checkout/issues/1471
4143

44+
- name: Set IS_PRIMARY_APP
45+
shell: bash
46+
run: |
47+
if [[ "${{ matrix.sample-app }}" == "java_layout" ]]; then
48+
echo "IS_PRIMARY_APP=true" >> $GITHUB_ENV
49+
else
50+
echo "IS_PRIMARY_APP=false" >> $GITHUB_ENV
51+
fi
52+
4253
- name: Set Default Firebase Distribution Groups
4354
shell: bash
4455
env:
@@ -48,7 +59,6 @@ jobs:
4859
NEXT_BUILDS_GROUP: next
4960
PUBLIC_BUILDS_GROUP: public
5061
# Input variables
51-
IS_PRIMARY_APP: ${{ matrix.sample-app == 'java_layout' }}
5262
CURRENT_BRANCH: ${{ github.ref }}
5363
USE_LATEST_SDK_VERSION: ${{ inputs.use_latest_sdk_version }}
5464
run: |
@@ -65,13 +75,6 @@ jobs:
6575
# Export the groups as an environment variable
6676
echo "firebase_distribution_groups=$(IFS=','; echo "${distribution_groups[*]}")" >> $GITHUB_ENV
6777
68-
- name: Get latest SDK version
69-
if: ${{ inputs.use_latest_sdk_version == true }}
70-
id: latest-sdk-version-step
71-
run: |
72-
latest_tag=$(git describe --tags --abbrev=0)
73-
echo "LATEST_TAG=$latest_tag" >> "$GITHUB_OUTPUT"
74-
7578
- uses: ./.github/actions/setup-android
7679

7780
# CLI to replace strings in files. The CLI recommends using `cargo install` which is slow. This Action is fast because it downloads pre-built binaries.
@@ -85,23 +88,29 @@ jobs:
8588
ruby-version: '3.0'
8689
bundler-cache: true # cache tools to make builds faster in future
8790

91+
- name: Capture Git Context
92+
shell: bash
93+
id: git-context
94+
run: |
95+
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV
96+
COMMIT_HASH="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}"
97+
echo "COMMIT_HASH=${COMMIT_HASH:0:7}" >> $GITHUB_ENV
98+
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
99+
88100
- name: Setup local.properties file for sample app
89-
env:
90-
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
91-
COMMIT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
92101
run: |
93102
LOCAL_PROPS_FILE="samples/local.properties"
94103
touch "$LOCAL_PROPS_FILE"
95104
echo "cdpApiKey=${{ secrets[matrix.cio-cdpapikey-secret-key] }}" >> "$LOCAL_PROPS_FILE"
96105
echo "siteId=${{ secrets[matrix.cio-siteid-secret-key] }}" >> "$LOCAL_PROPS_FILE"
97106
echo "workspace=${{ matrix.cio-workspace-name }}" >> "$LOCAL_PROPS_FILE"
98-
echo "branchName=$BRANCH_NAME" >> "$LOCAL_PROPS_FILE"
99-
echo "commitHash=${COMMIT_HASH:0:7}" >> "$LOCAL_PROPS_FILE"
100-
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "untagged")
107+
echo "branchName=${{ env.BRANCH_NAME }}" >> "$LOCAL_PROPS_FILE"
108+
echo "commitHash=${{ env.COMMIT_HASH }}" >> "$LOCAL_PROPS_FILE"
109+
LAST_TAG="${LATEST_TAG:-untagged}"
101110
COMMITS_AHEAD=$(git rev-list $LAST_TAG..HEAD --count 2>/dev/null || echo "untracked")
102111
echo "commitsAheadCount=$COMMITS_AHEAD" >> "$LOCAL_PROPS_FILE"
103112
if [ "${{ inputs.use_latest_sdk_version == true }}" ]; then
104-
echo "sdkVersion=${{ steps.latest-sdk-version-step.outputs.LATEST_TAG }}" >> "$LOCAL_PROPS_FILE"
113+
echo "sdkVersion=${{ env.LATEST_TAG }}" >> "$LOCAL_PROPS_FILE"
105114
fi
106115
107116
- name: Dump GitHub Action metadata because Fastlane uses it. Viewing it here helps debug JSON parsing code in Firebase.
@@ -110,7 +119,7 @@ jobs:
110119
- name: Prepare Fastlane Build Arguments
111120
run: |
112121
if [ "${{ inputs.use_latest_sdk_version }}" = "true" ]; then
113-
sdk_version="\"sdk_version\":\"${{ steps.latest-sdk-version-step.outputs.LATEST_TAG }}\""
122+
sdk_version="\"sdk_version\":\"${{ env.LATEST_TAG }}\""
114123
else
115124
sdk_version=""
116125
fi
@@ -139,6 +148,32 @@ jobs:
139148
ANDROID_SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
140149
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }}
141150

151+
- name: Determine SDK Version
152+
shell: bash
153+
id: determine-sdk-version
154+
run: |
155+
sdk_version="${{ env.SDK_VERSION }}"
156+
sdk_version="${sdk_version:-$LATEST_TAG}"
157+
echo "SDK Version used in app build: $sdk_version"
158+
echo "APP_SDK_BUILD_VERSION=$sdk_version" >> $GITHUB_ENV
159+
160+
- name: Send Slack Notification for Sample App Builds
161+
if: ${{ always() && env.IS_PRIMARY_APP == 'true' }}
162+
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1
163+
with:
164+
build_status: ${{ job.status }}
165+
app_icon_emoji: ":android:"
166+
app_name: "Android Native"
167+
firebase_app_id: ${{ secrets[matrix.firebase-app-id-secret-key] }}
168+
firebase_distribution_groups: ${{ env.firebase_distribution_groups }}
169+
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})"
170+
icon_url: "https://media.pocketgamer.com/artwork/na-qulrguj/android.jpg"
171+
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }}
172+
platform: "android"
173+
sdk_name: "Android Native SDK"
174+
sdk_version: ${{ env.APP_SDK_BUILD_VERSION }}
175+
slack_webhook_url: ${{ secrets.SLACK_NOTIFY_RELEASES_WEBHOOK_URL }}
176+
142177
- name: Update sample builds PR comment with build information
143178
if: ${{ github.event_name == 'pull_request' }}
144179
uses: peter-evans/create-or-update-comment@v4

samples/fastlane/Fastfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ private_lane :build_sample_app do |options|
3232

3333
if !options.key?(:sdk_version)
3434
UI.important("Updating the SDK's source code version to non-production version. This allows the sample apps to show the SDK version at runtime for app user to better understand the version of the SDK they are running.")
35-
sh("../../../scripts/update-version.sh \"#{new_app_version}.#{new_build_number}\"")
35+
new_sdk_version = "#{new_app_version}.#{new_build_number}"
36+
sh("../../../scripts/update-version.sh \"#{new_sdk_version}\"")
37+
sh("echo 'SDK_VERSION=#{new_sdk_version}' >> $GITHUB_ENV")
3638
end
3739

3840
build_android_app(

0 commit comments

Comments
 (0)