From 2e5d6982dcc60391c78b88f2f130f5ab715a309b Mon Sep 17 00:00:00 2001 From: Lucas Raposeiras Date: Wed, 4 Sep 2024 01:18:06 +0200 Subject: [PATCH] build(eas): refactor EAS build GitHub Actions --- .github/workflows/eas-build-prod.yml | 43 ---------------------- .github/workflows/eas-build-qa.yml | 47 ------------------------- .github/workflows/eas-build-staging.yml | 47 ------------------------- .github/workflows/eas-build.yml | 44 +++++++++++++---------- env.js | 12 ++++++- package.json | 28 ++++++++------- 6 files changed, 51 insertions(+), 170 deletions(-) delete mode 100644 .github/workflows/eas-build-prod.yml delete mode 100644 .github/workflows/eas-build-qa.yml delete mode 100644 .github/workflows/eas-build-staging.yml diff --git a/.github/workflows/eas-build-prod.yml b/.github/workflows/eas-build-prod.yml deleted file mode 100644 index af1499535..000000000 --- a/.github/workflows/eas-build-prod.yml +++ /dev/null @@ -1,43 +0,0 @@ -# 🔗 Links: -# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/eas-build-prod.yml -# Starter releasing process: https://starter.obytes.com/ci-cd/app-releasing-process/ - -# ✍️ Description: -# This workflow is used to trigger a build on EAS for Prod environment. -# Can be triggered manually from the actions tab. -# This workflow will use ./actions/eas-build action to trigger the build on EAS with production env. - -# 🚨 GITHUB SECRETS REQUIRED: -# - EXPO_TOKEN: Expo token to authenticate with EAS -# - You can get it from https://expo.dev/settings/access-tokens - -name: EAS Production Build (Android & IOS) (EAS) - -on: - workflow_dispatch: - -jobs: - Build: - name: EAS Production Build (Android & IOS) (EAS) - runs-on: ubuntu-latest - steps: - - name: Check for EXPO_TOKEN - run: | - if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then - echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" - exit 1 - fi - - - name: 📦 Checkout project repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: 📦 Setup Node + PNPM + install deps - uses: ./.github/actions/setup-node-pnpm-install - - - name: ⏱️ EAS Build - uses: ./.github/actions/eas-build - with: - APP_ENV: production - EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} diff --git a/.github/workflows/eas-build-qa.yml b/.github/workflows/eas-build-qa.yml deleted file mode 100644 index 31f1a2fb8..000000000 --- a/.github/workflows/eas-build-qa.yml +++ /dev/null @@ -1,47 +0,0 @@ -# 🔗 Links: -# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/eas-build-qa.yml -# Starter releasing process: https://starter.obytes.com/ci-cd/app-releasing-process/ - -# ✍️ Description: -# This workflow is used to trigger a build on EAS for the QA environment. -# It will run on every GitHub release published on the repo or can be triggered manually from the actions tab. -# This workflow will use ./actions/eas-build action to trigger the build on EAS with staging env. - -# 🚨 GITHUB SECRETS REQUIRED: -# - EXPO_TOKEN: Expo token to authenticate with EAS -# - You can get it from https://expo.dev/settings/access-tokens - -name: EAS QA Build (Android & IOS) (EAS) - -on: - workflow_dispatch: - release: - types: [published] - -jobs: - Build: - name: EAS QA Build (Android & IOS) (EAS) - runs-on: ubuntu-latest - steps: - - name: Check for EXPO_TOKEN - run: | - if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then - echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" - exit 1 - fi - - name: 📦 Checkout project repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: 📦 Setup Node + PNPM + install deps - uses: ./.github/actions/setup-node-pnpm-install - - - name: ⏱️ EAS Build - uses: ./.github/actions/eas-build - with: - APP_ENV: qa - EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} - VERSION: ${{ github.event.release.tag_name }} - IOS: false # TODO: set as true when IOS account is ready - diff --git a/.github/workflows/eas-build-staging.yml b/.github/workflows/eas-build-staging.yml deleted file mode 100644 index 25593f105..000000000 --- a/.github/workflows/eas-build-staging.yml +++ /dev/null @@ -1,47 +0,0 @@ -# 🔗 Links: -# Source file: https://github.com/obytes/react-native-template-obytes/blob/master/.github/workflows/eas-build-qa.yml -# Starter releasing process: https://starter.obytes.com/ci-cd/app-releasing-process/ - -# ✍️ Description: -# This workflow is used to trigger a build on EAS for the Staging environment. -# It will run on every GitHub release published on the repo or can be triggered manually from the actions tab. -# This workflow will use ./actions/eas-build action to trigger the build on EAS with staging env. - -# 🚨 GITHUB SECRETS REQUIRED: -# - EXPO_TOKEN: Expo token to authenticate with EAS -# - You can get it from https://expo.dev/settings/access-tokens - -name: EAS Staging Build (Android & IOS) (EAS) - -on: - workflow_dispatch: - release: - types: [published] - -jobs: - Build: - name: EAS Staging Build (Android & IOS) (EAS) - runs-on: ubuntu-latest - steps: - - name: Check for EXPO_TOKEN - run: | - if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then - echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" - exit 1 - fi - - name: 📦 Checkout project repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: 📦 Setup Node + PNPM + install deps - uses: ./.github/actions/setup-node-pnpm-install - - - name: ⏱️ EAS Build - uses: ./.github/actions/eas-build - with: - APP_ENV: staging - EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} - VERSION: ${{ github.event.release.tag_name }} - IOS: false # TODO: set as true when IOS account is ready - diff --git a/.github/workflows/eas-build.yml b/.github/workflows/eas-build.yml index 121cd22df..12db95f8d 100644 --- a/.github/workflows/eas-build.yml +++ b/.github/workflows/eas-build.yml @@ -1,44 +1,48 @@ # 🔗 Links: -# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/actions/eas-build/action.yml +# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/eas-build.yml # EAS Build docs: https://docs.expo.dev/eas-update/github-actions/ # ✍️ Description: -# This is a composite action, which means it can be used in other actions. -# This action is used to trigger an EAS Build for a specific environment (development, staging, production). +# This workflow is used to trigger a build on EAS. +# Can be triggered manually from the actions tab. + # This action accepts those inputs: -# `APP_ENV`, which is used to generate an APK for a specific environment (development, staging, production). We use staging by default. -# `AUTO_SUBMIT`, false by default, set to true if you want to automatically submit your build to stores. -# `EXPO_TOKEN`, required, access token for your Expo account. https://expo.dev/settings/access-tokens -# `VERSION`, required, version of the app to build. used as the build message. -# `ANDROID`, true by default, set to true if you don't want to trigger build for Android. -# `IOS`, false by default, set to true if you want to trigger build for IOS. +# `environment`, which is used to generate a build for a specific environment (development, staging, QA, production). We use staging by default. +# `android`, true by default, set to true if you don't want to trigger build for Android. +# `ios`, false by default, set to true if you want to trigger build for IOS. # Before triggering the build, we run a pre-build script to generate the necessary native folders based on the APP_ENV. # Based on the ANDROID and IOS inputs, we trigger the build for the corresponding platform with the corresponding flags. -# 👀 Example usage: -# - name: ⏱️ EAS Build -# uses: ./.github/actions/eas-build -# with: -# environment: staging -# EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} -# VERSION: ${{ github.event.release.tag_name }} -# IOS: false +# 🚨 GITHUB SECRETS REQUIRED: +# - EXPO_TOKEN: Expo token to authenticate with EAS +# - You can get it from https://expo.dev/settings/access-tokens -name: 'Setup EAS Build + Trigger Build' +name: 'EAS Build (Android & IOS) (EAS)' on: workflow_dispatch: inputs: environment: type: choice - description: 'environment (one of): development, staging, production' + description: 'Environment' required: true default: 'staging' options: - development - staging + - qa - production + android: + type: boolean + description: 'Build for Android' + required: true + default: true + ios: + type: boolean + description: 'Build for iOS' + required: true + default: true jobs: Build: @@ -69,7 +73,9 @@ jobs: run: pnpm prebuild:${{ inputs.environment }} - name: 📱 Run Android Build + if: ${{ inputs.android == true }} run: pnpm build:${{ inputs.environment }}:android --non-interactive --no-wait --message "Build ${{ inputs.environment }}" - name: 📱 Run IOS Build + if: ${{ inputs.ios == true }} run: pnpm build:${{ inputs.environment }}:ios --non-interactive --no-wait --message "Build ${{ inputs.environment }}" diff --git a/env.js b/env.js index d305609d6..00afc94ce 100644 --- a/env.js +++ b/env.js @@ -41,8 +41,18 @@ const scriptIsEnvironmentDependant = ENVIRONMENT_DEPENDANT_SCRIPTS.some( ); // Check if the environment file has to be validated for the current running script and build method +const isBuilding = isEASBuild || isLocalBuild; +const isRunning = process.env.npm_lifecycle_script?.includes('expo run'); const shouldValidateEnv = - (isEASBuild || isLocalBuild) && scriptIsEnvironmentDependant; + (isBuilding && scriptIsEnvironmentDependant) || isRunning; + +console.log({ + npm_lifecycle_script: process.env.npm_lifecycle_script, + scriptIsEnvironmentDependant, + isLocalBuild, + isEASBuild, + shouldValidateEnv, +}); const easEnvironmentFileVariable = `ENVIRONMENT_FILE_${APP_ENV.toUpperCase()}`; const easEnvironmentFilePath = process.env[easEnvironmentFileVariable]; diff --git a/package.json b/package.json index 3cb25fbc2..f04caa901 100644 --- a/package.json +++ b/package.json @@ -6,31 +6,33 @@ "scripts": { "start": "cross-env EXPO_NO_DOTENV=1 expo start", "prebuild": "cross-env EXPO_NO_DOTENV=1 pnpm expo prebuild", + "start:development": "cross-env APP_ENV=development pnpm run start", + "prebuild:development": "cross-env APP_ENV=development pnpm run prebuild", "android": "cross-env EXPO_NO_DOTENV=1 expo run:android", "ios": "cross-env EXPO_NO_DOTENV=1 expo run:ios", - "xcode": "xed -b ios", - "doctor": "npx expo-doctor@latest", - "preinstall": "npx only-allow pnpm", + "build:development:android": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform android ", + "build:development:ios": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform ios", "start:staging": "cross-env APP_ENV=staging pnpm run start", - "start:qa": "cross-env APP_ENV=qa pnpm run start", "prebuild:staging": "cross-env APP_ENV=staging pnpm run prebuild", - "prebuild:qa": "cross-env APP_ENV=qa pnpm run prebuild", "android:staging": "cross-env APP_ENV=staging pnpm run android", - "android:qa": "cross-env APP_ENV=qa pnpm run android", "ios:staging": "cross-env APP_ENV=staging pnpm run ios", + "build:staging:android": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform android ", + "build:staging:ios": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform ios", + "start:qa": "cross-env APP_ENV=qa pnpm run start", + "prebuild:qa": "cross-env APP_ENV=qa pnpm run prebuild", + "android:qa": "cross-env APP_ENV=qa pnpm run android", "ios:qa": "cross-env APP_ENV=qa pnpm run ios", + "build:qa:ios": "cross-env APP_ENV=qa EXPO_NO_DOTENV=1 eas build --profile qa --platform ios", + "build:qa:android": "cross-env APP_ENV=qa EXPO_NO_DOTENV=1 eas build --profile qa --platform android ", "start:production": "cross-env APP_ENV=production pnpm run start", "prebuild:production": "cross-env APP_ENV=production pnpm run prebuild", "android:production": "cross-env APP_ENV=production pnpm run android", "ios:production": "cross-env APP_ENV=production pnpm run ios", - "build:development:ios": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform ios", - "build:development:android": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform android ", - "build:staging:ios": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform ios", - "build:qa:ios": "cross-env APP_ENV=qa EXPO_NO_DOTENV=1 eas build --profile qa --platform ios", - "build:staging:android": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform android ", - "build:qa:android": "cross-env APP_ENV=qa EXPO_NO_DOTENV=1 eas build --profile qa --platform android ", - "build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios", "build:production:android": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform android ", + "build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios", + "xcode": "xed -b ios", + "doctor": "npx expo-doctor@latest", + "preinstall": "npx only-allow pnpm", "postinstall": "husky install", "app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft --message 'chore: release template v%s'", "version": "git add .",