Skip to content

Commit

Permalink
chore: react native as data pipeline source (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-aman authored Sep 24, 2024
1 parent 8516377 commit 4992774
Show file tree
Hide file tree
Showing 137 changed files with 52,874 additions and 19,892 deletions.
225 changes: 225 additions & 0 deletions .github/workflows/build-sample-apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
name: Build sample apps

on:
pull_request: # build sample apps for every commit pushed to an open pull request (including drafts)
push:
branches: [ main, feature/* ]

concurrency: # cancel previous workflow run if one exists.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
XCODE_VERSION: "15.3"
RUBY_VERSION: "3.0"
NODE_VERSION: "18"

jobs:
update-pr-comment:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write # to be able to comment on PR
outputs:
comment-id: ${{ steps.create-comment.outputs.comment-id }}
steps:
- name: Find Comment
uses: peter-evans/find-comment@v3
id: existing-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: <!-- sample app builds -->

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
id: create-comment
with:
comment-id: ${{ steps.existing-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- sample app builds -->
# Sample app builds 📱
Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.
---
${{ steps.build.outputs.build-log }}
edit-mode: replace # replace the existing comment with new content since we are creating new builds

build-sample-apps:
if: ${{ always() }} # do not skip running this step if update-pr-comment does not run
needs: [update-pr-comment] # wait for PR comment to be created saying new builds are being made.
permissions:
pull-requests: write # comment on pull request with build information
strategy:
fail-fast: false # if one sample app fails to build, let the other sample apps continue to build and not cancel them.
matrix: # Use a matrix allowing us to build multiple apps in parallel. Just add an entry to the matrix and it will build!
sample-app:
# List all sample apps you want to have compiled.
# List item is name of directory inside of "Apps" directory for the corresponding app to compile.
- "APN"
- "FCM"
defaults:
run:
working-directory: apps/${{ matrix.sample-app }}
runs-on: macos-14
name: Building sample app ${{ matrix.sample-app }}

steps:
- uses: actions/checkout@v4

# Install CLI tools, Ruby, and Ruby dependencies for Fastlane

- 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/${{ matrix.sample-app }}

# Update version numbers and workspace credentials before building the app

- name: Generate New Version
uses: maierj/[email protected]
with:
subdirectory: Apps/${{ matrix.sample-app }}
lane: "generate_new_version"
options: '{"branch_name":"${{ github.ref_name }}", "pull_request_number":"${{ github.event.pull_request.number }}"}'

- name: Update React Native SDK Version
uses: maierj/[email protected]
with:
subdirectory: Apps/${{ matrix.sample-app }}
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/[email protected]
with:
subdirectory: Apps/${{ matrix.sample-app }}
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: 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 the apiKey in the environment file
sd "siteId: '.*'" "siteId: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', matrix.sample-app)] }}'" "$ENV_FILE"
sd "apiKey: '.*'" "apiKey: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_API_KEY', matrix.sample-app)] }}'" "$ENV_FILE"
- name: Setup workspace credentials in iOS environment files
working-directory: Apps/${{ matrix.sample-app }}/ios
run: |
cp "Env.swift.example" "Env.swift"
sd 'siteId: String = ".*"' "siteId: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', matrix.sample-app)] }}\"" "Env.swift"
sd 'apiKey: String = ".*"' "apiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_API_KEY', matrix.sample-app)] }}\"" "Env.swift"
# 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/${{ matrix.sample-app }}/Pods
key: ${{ runner.os }}-${{ matrix.sample-app }}-Pods-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ matrix.sample-app }}-Pods
- name: Install dependencies to build SDK
run: npm ci
working-directory: .

- name: Install dependencies for sample app
run: npm run ci:install

# 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/[email protected]
with:
subdirectory: Apps/${{ matrix.sample-app }}
lane: 'android build'
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/[email protected]
with:
subdirectory: Apps/${{ matrix.sample-app }}
lane: "ios build"
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: |
if [ "${{ steps.android_build.outcome }}" != "success" ] || [ "${{ steps.ios_build.outcome }}" != "success" ]; then
echo "One or more builds failed."
exit 1
fi
# Update PR comment with build information

- name: Update sample builds PR comment with build information
if: ${{ github.event_name == 'pull_request' }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ needs.update-pr-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
# the variables APP_VERSION_NAME, APP_VERSION_CODE are generated above in generate_new_version lane
body: |
* ${{ matrix.sample-app }}: `${{ env.APP_VERSION_NAME }} (${{ env.APP_VERSION_CODE }})`
edit-mode: append # append new line to the existing PR comment to build a list of all sample app builds.

- name: Update sample builds PR comment with build failure message
if: ${{ github.event_name == 'pull_request' && failure() }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ needs.update-pr-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
* ${{ matrix.sample-app }}: Build failed. See [CI job logs](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) to determine the issue and try re-building.
edit-mode: append # append new line to the existing PR comment to build a list of all sample app builds.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ buck-out/
# CocoaPods
Apps/APN/ios/Pods/

package-lock.json
lib/module/index.js
3 changes: 0 additions & 3 deletions Apps/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Because the sample apps install the RN SDK from a local file path, every time that someone makes a change to the RN SDK source code, all sample app lock files will be changed. This can make git commits noisey. To avoid this, we ignore all lock files in the sample apps. This is not recommended for production apps.
package-lock.json

# Config files
#
env.js
Expand Down
6 changes: 2 additions & 4 deletions Apps/APN/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export default function App() {
prepare();
const inAppEventListener = registerInAppEventListener();

// Remove listeners once unmounted
return () => {
inAppEventListener.remove();
};
// TODO: Add this when inapp feature is implemented
// inAppEventListener.remove();
}, [
applyCustomerIoConfig,
handleCustomerIoConfigChanged,
Expand Down
12 changes: 12 additions & 0 deletions Apps/APN/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

gem 'cocoapods', '~> 1.12'
gem 'fastlane'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
Loading

0 comments on commit 4992774

Please sign in to comment.