Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
**/node_modules
Expand Down
127 changes: 22 additions & 105 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Generate Env.tsx
env:
COURIER_BRAND_ID: ${{ secrets.COURIER_BRAND_ID }}
COURIER_AUTH_KEY: ${{ secrets.COURIER_AUTH_KEY }}
COURIER_CLIENT_KEY: ${{ secrets.COURIER_CLIENT_KEY }}
COURIER_TOPIC_ID: ${{ secrets.COURIER_TOPIC_ID }}
run: |
printf "export default class Env {\n static readonly brandId = '%s';\n static readonly authKey = '%s';\n static readonly clientKey = '%s';\n static readonly topicId = '%s';\n}\n" "$COURIER_BRAND_ID" "$COURIER_AUTH_KEY" "$COURIER_CLIENT_KEY" "$COURIER_TOPIC_ID" > example/src/Env.tsx
npx prettier --write example/src/Env.tsx

- name: Lint files
run: yarn lint

Expand All @@ -27,125 +37,32 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Generate Env.tsx
env:
COURIER_BRAND_ID: ${{ secrets.COURIER_BRAND_ID }}
COURIER_AUTH_KEY: ${{ secrets.COURIER_AUTH_KEY }}
COURIER_CLIENT_KEY: ${{ secrets.COURIER_CLIENT_KEY }}
COURIER_TOPIC_ID: ${{ secrets.COURIER_TOPIC_ID }}
run: |
printf "export default class Env {\n static readonly brandId = '%s';\n static readonly authKey = '%s';\n static readonly clientKey = '%s';\n static readonly topicId = '%s';\n}\n" "$COURIER_BRAND_ID" "$COURIER_AUTH_KEY" "$COURIER_CLIENT_KEY" "$COURIER_TOPIC_ID" > example/src/Env.tsx

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepack

build-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for Android
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-

- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")

if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi

- name: Install JDK
if: env.turbo_cache_hit != 1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Finalize Android SDK
if: env.turbo_cache_hit != 1
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

- name: Cache Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Build example for Android
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"

build-ios:
runs-on: macos-latest
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for iOS
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-

- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")

if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi

- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
with:
path: |
**/ios/Pods
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-

- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn example pods
env:
NO_FLIPPER: 1

- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
99 changes: 99 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Deploy

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy to npm
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
deployed: ${{ steps.check.outputs.deployed }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: 'https://registry.npmjs.org'

- name: Check version
id: check
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"

PUBLISHED=$(npm view @trycourier/courier-react-native versions --json 2>/dev/null || echo "[]")
if echo "$PUBLISHED" | python3 -c "import sys,json; vs=json.load(sys.stdin); sys.exit(0 if '$VERSION' in vs else 1)" 2>/dev/null; then
echo "Version $VERSION already published on npm. Skipping deploy."
echo "deployed=false" >> "$GITHUB_OUTPUT"
else
echo "Version $VERSION not yet published. Deploying."
echo "deployed=true" >> "$GITHUB_OUTPUT"
fi

- name: Install dependencies
if: steps.check.outputs.deployed == 'true'
run: yarn install --frozen-lockfile

- name: Build package
if: steps.check.outputs.deployed == 'true'
run: yarn prepack

- name: Create git tag
if: steps.check.outputs.deployed == 'true'
run: |
VERSION="${{ steps.check.outputs.version }}"
git tag "$VERSION"
git push origin "$VERSION"

- name: Generate release notes
if: steps.check.outputs.deployed == 'true'
id: notes
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || git rev-list --max-parents=0 HEAD)
NOTES=$(git log "$PREVIOUS_TAG"..HEAD --pretty=format:"- %s" --no-merges)
echo "notes<<EOF" >> "$GITHUB_OUTPUT"
echo "$NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: Create GitHub release
if: steps.check.outputs.deployed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.check.outputs.version }}"
gh release create "$VERSION" --notes "${{ steps.notes.outputs.notes }}"

- name: Publish to npm
if: steps.check.outputs.deployed == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Setup
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage
20 changes: 0 additions & 20 deletions .github/workflows/test-status-report.yml

This file was deleted.

Loading
Loading