66# This workflow is used to trigger a build on EAS.
77# Can be triggered manually from the actions tab.
88
9- # This action accepts those inputs:
10- # `environment`, which is used to generate a build for a specific environment (development, staging, QA, production). We use staging by default.
11- # `android`, true by default, set to true if you don't want to trigger build for Android.
12- # `ios`, false by default, set to true if you want to trigger build for IOS.
13-
149# Before triggering the build, we run a pre-build script to generate the necessary native folders based on the APP_ENV.
1510# Based on the ANDROID and IOS inputs, we trigger the build for the corresponding platform with the corresponding flags.
1611
2823# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
2924# - Name: NEW_VERSION_NUMBER_PAT
3025# - Value: The Personal Access Token you created
31- name : ' EAS Build (Android & IOS) (EAS)'
26+
27+ name : ' Build & Deploy'
3228
3329on :
3430 workflow_dispatch :
3531 inputs :
36- environment :
32+ platform :
3733 type : choice
38- description : ' Environment'
39- required : true
40- default : ' staging'
34+ description : Platform to build for
4135 options :
42- - development
43- - staging
44- - qa
45- - production
36+ - android
37+ - ios
4638 new-version :
4739 type : string
48- description : ' New version (e.g. 1.0.0)'
49- android :
40+ description : ' New version (e.g. 1.0.0) (optional) '
41+ auto-submit :
5042 type : boolean
51- description : ' Build for Android'
52- required : true
53- default : true
54- ios :
55- type : boolean
56- description : ' Build for iOS'
57- required : true
43+ description : ' Auto-submit the build to the store'
44+ required : false
5845 default : true
5946
6047jobs :
@@ -88,28 +75,33 @@ jobs:
8875
8976 build :
9077 needs : validate-new-version
91- runs-on : ${{ matrix.os }}
78+ runs-on : ${{ inputs.platform == 'ios' && 'macos-latest' || 'ubuntu-latest' }}
9279 permissions :
9380 contents : write
94- environment : app-${{ inputs.environment }}
95- strategy :
96- fail-fast : false
97- matrix :
98- platform : [ios, android]
99- include :
100- - platform : ios
101- os : macos-latest
102- - platform : android
103- os : ubuntu-latest
81+ environment : ${{ github.ref_name == 'main' && 'production' || github.ref_name == 'staging' && 'staging' || github.ref_name == 'qa' && 'qa' || github.ref_name == 'development' && 'development' }}
10482 steps :
83+ - name : Set environment variable
84+ run : |
85+ if [[ "${{ github.ref_name }}" == "main" ]]; then
86+ echo "ENV=production" >> $GITHUB_ENV
87+ elif [[ "${{ github.ref_name }}" == "staging" ]]; then
88+ echo "ENV=staging" >> $GITHUB_ENV
89+ elif [[ "${{ github.ref_name }}" == "qa" ]]; then
90+ echo "ENV=qa" >> $GITHUB_ENV
91+ elif [[ "${{ github.ref_name }}" == "development" ]]; then
92+ echo "ENV=development" >> $GITHUB_ENV
93+ else
94+ echo "Invalid branch: ${{ github.ref_name }}. You can only build for main, staging, qa or development branches."
95+ exit 1
96+ fi
10597 - name : Check if all required secrets exist
10698 run : |
10799 if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then
108100 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"
109101 exit 1
110102 fi
111103 if [ -z "${{ secrets.NEW_VERSION_NUMBER_PAT }}" ]; then
112- echo "echo " NEW_VERSION_NUMBER_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file." "
104+ echo "NEW_VERSION_NUMBER_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file."
113105 exit 1
114106 fi
115107
@@ -129,7 +121,7 @@ jobs:
129121 uses : ./.github/actions/setup-node-pnpm-install
130122
131123 - name : Create environment file
132- run : echo "${{ secrets.ENVIRONMENT_FILE }}" > .env.${{ inputs.environment }}
124+ run : echo "${{ secrets.ENVIRONMENT_FILE }}" > .env.${{ env.ENV }}
133125
134126 - name : Update version in package.json
135127 if : inputs.new-version
@@ -146,26 +138,43 @@ jobs:
146138
147139 - name : Setup latest version of Xcode
148140 uses : maxim-lobanov/setup-xcode@v1
149- if : matrix .platform == 'ios'
141+ if : inputs .platform == 'ios'
150142 with :
151143 xcode-version : latest
152144
153- - name : ⚙️ Run Prebuild
154- run : pnpm prebuild:${{ inputs.environment }}
145+ - name : Set Up JDK
146+ uses : actions/setup-java@v3
147+ if : inputs.platform == 'android'
148+ with :
149+ distribution : ' zulu' # See 'Supported distributions' for available options
150+ java-version : ' 17'
155151
156- - name : 📱 Run Build for ${{ matrix.platform }}
157- run : pnpm build :${{ inputs.environment }}:${{ matrix.platform }} --non-interactive --no-wait --message "Build ${{ inputs.environment }} for ${{ matrix.platform }}" --local
152+ - name : ⚙️ Run Prebuild
153+ run : pnpm prebuild :${{ env.ENV }}
158154
159- - name : 📦 Push changes to repository
160- if : inputs.new-version
155+ - name : 📱 Run Build for ${{ inputs.platform }}
161156 run : |
162- git push || echo "Skipping push: version was already updated."
163-
164- - name : Upload ${{ matrix.platform }} Build
157+ pnpm build:${{ env.ENV }}:${{ inputs.platform }} --non-interactive --no-wait --message "Build ${{ env.ENV }} for ${{ inputs.platform }}" --local
158+ if [ "${{ inputs.platform }}" = "android" ]; then
159+ ls -1 ./*.aab > path.txt
160+ elif [ "${{ inputs.platform }}" = "ios" ]; then
161+ ls -1 ./*.ipa > path.txt
162+ fi
163+ - name : Upload ${{ inputs.platform }} Build
165164 uses : actions/upload-artifact@v4
166165 with :
167- name : ${{ matrix .platform }}-build-${{ inputs.environment }}
166+ name : ${{ inputs .platform }}-build-${{ env.ENV }}
168167 path : |
168+ *.apks
169169 *.apk
170170 *.aab
171- *.ipa
171+ *.ipa
172+
173+ - name : 📱 Submit ${{ inputs.platform }} app to the store
174+ if : inputs.auto-submit
175+ run : pnpm submit:${{ env.ENV }}:mobile --platform=${{ inputs.platform }} --path=$(cat path.txt) --no-wait --non-interactive
176+
177+ - name : 📦 Push changes to repository
178+ if : inputs.new-version
179+ run : |
180+ git push || echo "Skipping push: version was already updated."
0 commit comments