chore: send slack notification on sample app build #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Sample App | |
on: | |
workflow_call: | |
inputs: | |
app_name: | |
description: "Name of the sample app to build" | |
required: true | |
type: string | |
branch_name: | |
description: "Branch name for versioning" | |
required: false | |
type: string | |
cio-workspace-name: | |
description: "Name of the Customer.io workspace to use" | |
required: true | |
type: string | |
sdk_version: | |
default: "" | |
description: "SDK version to use (optional, defaults to local dependency)" | |
required: false | |
type: string | |
outputs: | |
sdk_version_name: | |
description: "SDK version used in the build" | |
value: ${{ jobs.build-sample-app.outputs.sdk_version_name }} | |
app_version_name: | |
description: "Generated app version name" | |
value: ${{ jobs.build-sample-app.outputs.app_version_name }} | |
app_version_code: | |
description: "Generated app version code" | |
value: ${{ jobs.build-sample-app.outputs.app_version_code }} | |
env: | |
XCODE_VERSION: "15.3" | |
RUBY_VERSION: "3.0" | |
NODE_VERSION: "18" | |
jobs: | |
build-sample-app: | |
name: Building sample app ${{ inputs.app_name }} with SDK version ${{ inputs.sdk_version }} | |
runs-on: macos-14 | |
defaults: | |
run: | |
working-directory: Apps/${{ inputs.app_name }} # sets working directory for all steps in this job | |
outputs: | |
sdk_version_name: ${{ steps.export-vars.outputs.sdk_version_name }} | |
app_version_name: ${{ steps.export-vars.outputs.app_version_name }} | |
app_version_code: ${{ steps.export-vars.outputs.app_version_code }} | |
steps: | |
- name: Check out code with conditional fetch-depth | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Workaround for bug https://github.com/actions/checkout/issues/1471 | |
# Install CLI tools, Ruby, and Ruby dependencies for Fastlane | |
- name: Set IS_PRIMARY_APP | |
run: | | |
if [[ "${{ inputs.app_name }}" == "APN" ]]; then | |
echo "IS_PRIMARY_APP=true" >> $GITHUB_ENV | |
else | |
echo "IS_PRIMARY_APP=false" >> $GITHUB_ENV | |
fi | |
- name: Set Default Firebase Distribution Groups | |
shell: bash | |
env: | |
# Distribution group constants | |
ALL_BUILDS_GROUP: all-builds | |
FEATURE_BUILDS_GROUP: feature-branch | |
NEXT_BUILDS_GROUP: next | |
PUBLIC_BUILDS_GROUP: public | |
# Input variables | |
CURRENT_BRANCH: ${{ github.ref }} | |
run: | | |
# Initialize with the default distribution group | |
distribution_groups=("$ALL_BUILDS_GROUP") | |
# Append distribution groups based on branch and context if the app is primary | |
if [[ "$IS_PRIMARY_APP" == "true" ]]; then | |
[[ "$CURRENT_BRANCH" == "refs/heads/feature/"* ]] && distribution_groups+=("$FEATURE_BUILDS_GROUP") | |
[[ "$CURRENT_BRANCH" == "refs/heads/main" ]] && distribution_groups+=("$NEXT_BUILDS_GROUP") | |
[[ -n "${{ inputs.sdk_version }}" ]] && distribution_groups+=("$PUBLIC_BUILDS_GROUP") | |
fi | |
# Export the groups as an environment variable | |
echo "firebase_distribution_groups=$(IFS=','; echo "${distribution_groups[*]}")" >> $GITHUB_ENV | |
- name: Install CLI tools used in CI script | |
shell: bash | |
run: | | |
brew install sd # used in CI script as an easier to use sed CLI. Replaces text in files. | |
brew install xcbeautify # used by fastlane for output | |
- name: Install Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: ${{ env.RUBY_VERSION }} | |
bundler-cache: true # cache tools to make builds faster in future | |
working-directory: Apps/${{ inputs.app_name }} | |
# Update version numbers and workspace credentials before building the app | |
- name: Generate New Version | |
uses: maierj/fastlane-action@v3.1.0 | |
with: | |
subdirectory: Apps/${{ inputs.app_name }} | |
lane: "generate_new_version" | |
options: > | |
{ | |
"branch_name": "${{ inputs.branch_name || github.ref_name }}", | |
"pull_request_number": "${{ github.event.pull_request.number }}", | |
"sdk_version": "${{ inputs.sdk_version }}" | |
} | |
- name: Export App and SDK Version Info | |
id: export-vars | |
run: | | |
echo "Exporting SDK and App Version..." | |
echo "sdk_version_name=${SDK_VERSION_NAME}" >> $GITHUB_OUTPUT | |
echo "app_version_name=${APP_VERSION_NAME}" >> $GITHUB_OUTPUT | |
echo "app_version_code=${APP_VERSION_CODE}" >> $GITHUB_OUTPUT | |
env: | |
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }} | |
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }} | |
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }} | |
- name: Update React Native SDK Version | |
uses: maierj/fastlane-action@v3.1.0 | |
with: | |
subdirectory: Apps/${{ inputs.app_name }} | |
lane: "update_react_native_sdk_version" | |
env: | |
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }} | |
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }} | |
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }} | |
- name: Update Sample App Version | |
uses: maierj/fastlane-action@v3.1.0 | |
with: | |
subdirectory: Apps/${{ inputs.app_name }} | |
lane: "update_react_native_app_version" | |
env: | |
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }} | |
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }} | |
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }} | |
- name: Set Git Context Variables | |
run: | | |
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV | |
COMMIT_HASH="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" | |
echo "COMMIT_HASH=${COMMIT_HASH:0:7}" >> $GITHUB_ENV | |
- name: Setup workspace credentials in React Native environment files | |
run: | | |
# Determine the correct file extension (.js or .ts) | |
if [ -f "env.sample.js" ]; then | |
ENV_FILE="env.js" | |
cp "env.sample.js" "$ENV_FILE" | |
elif [ -f "env.sample.ts" ]; then | |
ENV_FILE="env.ts" | |
cp "env.sample.ts" "$ENV_FILE" | |
else | |
echo "No env.sample.js or env.sample.ts file found." | |
exit 1 | |
fi | |
# Update keys in the environment file | |
sd "buildTimestamp: .*" "buildTimestamp: $(date +%s)," "$ENV_FILE" | |
sd "cdpApiKey: '.*'" "cdpApiKey: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', inputs.app_name)] }}'" "$ENV_FILE" | |
sd "siteId: '.*'" "siteId: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', inputs.app_name)] }}'" "$ENV_FILE" | |
sd "workspaceName: '.*'" "workspaceName: '${{ inputs.cio-workspace-name }}'" "$ENV_FILE" | |
sd "branchName: '.*'" "branchName: '${{ env.BRANCH_NAME }}'" "$ENV_FILE" | |
sd "commitHash: '.*'" "commitHash: '${{ env.COMMIT_HASH }}'" "$ENV_FILE" | |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "untagged") | |
COMMITS_AHEAD=$(git rev-list $LAST_TAG..HEAD --count 2>/dev/null || echo "untracked") | |
sd "commitsAheadCount: '.*'" "commitsAheadCount: '$COMMITS_AHEAD'" "$ENV_FILE" | |
- name: Setup workspace credentials in iOS environment files | |
working-directory: Apps/${{ inputs.app_name }}/ios | |
run: | | |
ENV_FILE="Env.swift" | |
cp "$ENV_FILE.example" "$ENV_FILE" | |
sd 'siteId: String = ".*"' "siteId: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', inputs.app_name)] }}\"" "$ENV_FILE" | |
sd 'cdpApiKey: String = ".*"' "cdpApiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', inputs.app_name)] }}\"" "$ENV_FILE" | |
# Make sure to fetch dependencies only after updating version numbers and workspace credentials | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: 'npm' | |
cache-dependency-path: | | |
**/package-lock.json | |
- name: Cache CocoaPods downloaded dependencies for faster builds in the future | |
uses: actions/cache@v4 | |
with: | |
path: Apps/${{ inputs.app_name }}/Pods | |
key: ${{ runner.os }}-${{ inputs.app_name }}-Pods-${{ github.ref }} | |
restore-keys: | | |
${{ runner.os }}-${{ inputs.app_name }}-Pods | |
- name: Install dependencies to build SDK | |
run: npm ci | |
working-directory: . | |
- name: Install dependencies for sample app | |
run: | | |
SDK_VERSION="${{ inputs.sdk_version }}" | |
if [[ -n "$SDK_VERSION" ]]; then | |
npm run ci:install -- --cio-rn-sdk=$SDK_VERSION | |
else | |
npm run ci:install | |
fi | |
# Android setup | |
- name: Setup Android environment for sample app | |
uses: customerio/customerio-android/.github/actions/setup-android@main | |
- name: Build and upload Android app via Fastlane | |
id: android_build | |
uses: maierj/fastlane-action@v3.1.0 | |
with: | |
subdirectory: Apps/${{ inputs.app_name }} | |
lane: 'android build' | |
options: '{"distribution_groups": "${{ env.firebase_distribution_groups }}"}' | |
env: | |
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }} | |
continue-on-error: true # continue to build iOS app even if Android build fails | |
# iOS setup | |
- name: Setup iOS environment for sample app | |
uses: customerio/customerio-ios/.github/actions/setup-ios@main | |
with: | |
xcode-version: ${{ env.XCODE_VERSION }} | |
- name: Build and upload iOS app via Fastlane | |
id: ios_build | |
uses: maierj/fastlane-action@v3.1.0 | |
with: | |
subdirectory: Apps/${{ inputs.app_name }} | |
lane: "ios build" | |
options: '{"distribution_groups": "${{ env.firebase_distribution_groups }}"}' | |
env: | |
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64: ${{ secrets.GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64 }} | |
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }} | |
- name: Check build statuses and mark failure | |
run: | | |
FAILED_BUILDS=() | |
[ "${{ steps.android_build.outcome }}" != "success" ] && FAILED_BUILDS+=("Android") | |
[ "${{ steps.ios_build.outcome }}" != "success" ] && FAILED_BUILDS+=("iOS") | |
if [ ${#FAILED_BUILDS[@]} -ne 0 ]; then | |
echo "Build failed for: ${FAILED_BUILDS[*]}" | |
exit 1 | |
fi | |
- name: Send Slack Notification for Sample App Builds (Android) | |
if: env.IS_PRIMARY_APP == 'true' | |
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1 | |
with: | |
build_status: ${{ job.status }} | |
app_icon_emoji: ":react:" | |
app_name: "React Native" | |
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_ANDROID', inputs.app_name)] }} | |
firebase_distribution_groups: ${{ env.firebase_distribution_groups }} | |
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})" | |
icon_url: "https://vectorified.com/images/icon-react-native-24.png" | |
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }} | |
platform: "android" | |
repository_name: "React Native" | |
sdk_name: "React Native SDK" | |
sdk_version: ${{ env.SDK_VERSION_NAME }} | |
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} | |
- name: Send Slack Notification for Sample App Builds (iOS) | |
if: env.IS_PRIMARY_APP == 'true' | |
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1 | |
with: | |
build_status: ${{ job.status }} | |
app_icon_emoji: ":react:" | |
app_name: "React Native" | |
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_IOS', inputs.app_name)] }} | |
firebase_distribution_groups: ${{ env.firebase_distribution_groups }} | |
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})" | |
icon_url: "https://vectorified.com/images/icon-react-native-24.png" | |
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }} | |
platform: "ios" | |
repository_name: "React Native" | |
sdk_name: "React Native SDK" | |
sdk_version: ${{ env.SDK_VERSION_NAME }} | |
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} |