forked from obytes/react-native-template-obytes
-
Notifications
You must be signed in to change notification settings - Fork 3
181 lines (159 loc) · 7.41 KB
/
eas-build.yml
File metadata and controls
181 lines (159 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# 🔗 Links:
# 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 workflow is used to trigger a build on EAS.
# Can be triggered manually from the actions tab.
# 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.
# 🚨 GITHUB SECRETS REQUIRED:
# - EXPO_TOKEN: Expo token to authenticate with EAS to sync version numbers and submit the build.
# You can get it from https://expo.dev/settings/access-tokens
# - NEW_VERSION_NUMBER_PAT: A fine-grained Personal Access Token.
# This token is used to commit and push to protected branches.
# You can generate one from here: https://github.com/settings/tokens?type=beta
# Set the token name to something meaningful, e.g. "New version number PAT for <Project name>".
# Set the Repository access to "Only select repositories" and select this repository.
# Set the following Repo permissions:
# - Contents: Read & write (to commit and push)
# Make sure to add it to the repo secrets with the name NEW_VERSION_NUMBER_PAT:
# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
# - Name: NEW_VERSION_NUMBER_PAT
# - Value: The Personal Access Token you created
name: 'Build & Deploy'
run-name: Build & Deploy - ${{inputs.platform}}
on:
workflow_dispatch:
inputs:
platform:
type: choice
description: Platform to build for
options:
- android
- ios
new-version:
type: string
description: 'New version (e.g. 1.0.0) (optional)'
auto-submit:
type: boolean
description: 'Auto-submit the build to the store'
required: false
default: true
jobs:
validate-new-version:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
if: inputs.new-version
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Node.js
if: inputs.new-version
uses: actions/setup-node@v4
with:
node-version: 20
- name: Validate new version
if: inputs.new-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION="${{ inputs.new-version }}"
echo "Current version: $CURRENT_VERSION"
echo "New version: $NEW_VERSION"
npx semver -r ">=$CURRENT_VERSION" "$NEW_VERSION" > /dev/null || (echo "❌ New version must be greater than or equal to current version ($CURRENT_VERSION)" && exit 1)
echo "✅ New version is valid"
build:
needs: validate-new-version
runs-on: ${{ inputs.platform == 'ios' && 'macos-latest' || 'ubuntu-latest' }}
permissions:
contents: write
environment: ${{ github.ref_name == 'main' && 'production' || github.ref_name == 'staging' && 'staging' || github.ref_name == 'qa' && 'qa' || github.ref_name == 'development' && 'development' }}
steps:
- name: Set environment variable
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "ENV=production" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "staging" ]]; then
echo "ENV=staging" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "qa" ]]; then
echo "ENV=qa" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "development" ]]; then
echo "ENV=development" >> $GITHUB_ENV
else
echo "Invalid branch: ${{ github.ref_name }}. You can only build for main, staging, qa or development branches."
exit 1
fi
- name: Check if all required secrets exist
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
if [ -z "${{ secrets.NEW_VERSION_NUMBER_PAT }}" ]; then
echo "NEW_VERSION_NUMBER_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file."
exit 1
fi
- name: 📦 Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Checkout project repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.NEW_VERSION_NUMBER_PAT }}
- name: 📦 Setup Node + PNPM + install deps
uses: ./.github/actions/setup-node-pnpm-install
- name: Create environment file
run: echo "${{ secrets.ENVIRONMENT_FILE }}" > .env.${{ env.ENV }}
- name: Update version in package.json
if: inputs.new-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$CURRENT_VERSION" == "${{inputs.new-version}}" ]; then
echo "Current version is already ${{ inputs.new-version }}, no need to update"
exit 0
fi
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
pnpm version ${{ inputs.new-version }} -m "chore: set app version to ${{ inputs.new-version }}"
- name: Setup latest version of Xcode
uses: maxim-lobanov/setup-xcode@v1
if: inputs.platform == 'ios'
with:
xcode-version: latest
- name: Set Up JDK
uses: actions/setup-java@v3
if: inputs.platform == 'android'
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'
- name: ⚙️ Run Prebuild
run: pnpm prebuild:${{ env.ENV }}
- name: 📱 Run Build for ${{ inputs.platform }}
run: |
pnpm build:${{ env.ENV }}:${{ inputs.platform }} --non-interactive --no-wait --message "Build ${{ env.ENV }} for ${{ inputs.platform }}" --local
if [ "${{ inputs.platform }}" = "android" ]; then
ls -1 ./*.aab > path.txt
elif [ "${{ inputs.platform }}" = "ios" ]; then
ls -1 ./*.ipa > path.txt
fi
- name: Upload ${{ inputs.platform }} Build
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.platform }}-build-${{ env.ENV }}
path: |
*.apks
*.apk
*.aab
*.ipa
- name: 📱 Submit ${{ inputs.platform }} app to the store
if: inputs.auto-submit
run: pnpm submit:${{ env.ENV }}:mobile --platform=${{ inputs.platform }} --path=$(cat path.txt) --no-wait --non-interactive
- name: 📦 Push changes to repository
if: inputs.new-version
run: |
git push || echo "Skipping push: version was already updated."