-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
321 lines (283 loc) · 13 KB
/
action.yml
File metadata and controls
321 lines (283 loc) · 13 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: "EAS Build"
description: "Run EAS Build for Expo projects in a monorepo using pnpm"
inputs:
project_path:
description: "Path to the Expo project within the monorepo"
required: true
default: "apps/expo"
github-token:
description: "GitHub token"
required: true
expo-token:
description: "Expo token"
required: true
node-version:
description: "Optional node version. Default is 18"
default: "18"
pnpm-version:
description: "Optional pnpm version. Default is 8.15.4"
default: "8.15.4"
eas-channel:
description: "Optional EAS channel (dev, stg, prd, none). Default is 'none' which defaults to the branch"
default: "none"
runs:
using: "composite"
steps:
- name: Check for EXPO_TOKEN
shell: bash
run: |
if [ -z "${{ inputs.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: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
- name: Install pnpm
shell: bash
run: npm install -g pnpm@${{ inputs.pnpm-version }}
- name: Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ inputs.expo-token }}
- name: Install dependencies
shell: bash
run: |
cd ${{ inputs.project_path }}
pnpm install
- name: Update apt-get packages
shell: bash
run: sudo apt-get update
- name: Install sponge, imagemagick etc
shell: bash
run: sudo apt-get install -y moreutils imagemagick ghostscript fonts-freefont-otf expect
- name: Get version numbers
shell: bash
run: |
cd ${{ inputs.project_path }}
echo "Getting Android version..."
ANDROID_VERSION=$(pnpm -F expo exec eas build:version:get --platform android 2>/dev/null | grep "Android versionCode" | awk '{print $NF}') || ANDROID_VERSION=0
echo "Android version: $ANDROID_VERSION"
echo "Getting iOS version..."
IOS_VERSION=$(pnpm -F expo exec eas build:version:get --platform ios 2>/dev/null | grep "iOS buildNumber" | awk '{print $NF}') || IOS_VERSION=0
echo "iOS version: $IOS_VERSION"
CURRENT_VERSION=$(( ANDROID_VERSION > IOS_VERSION ? ANDROID_VERSION : IOS_VERSION ))
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "CURRENT VERSION IS ${CURRENT_VERSION}"
- name: Set to latest version number
shell: bash
run: |
for platform in ios android
do
expect << EOF
set timeout -1
spawn pnpm -F expo exec eas build:version:set --platform $platform
expect "What version would you like to set?"
send "$CURRENT_VERSION\r"
expect eof
EOF
done
- name: EAS Build
shell: bash
run: |
echo "Input eas-channel value: '${{ inputs.eas-channel }}'"
echo "Raw input value: '${{ toJSON(inputs.eas-channel) }}'"
cd ${{ inputs.project_path }}
if [ ! -z "${{ github.event.pull_request }}" ]; then
COMMIT_HASH=${{ github.event.pull_request.head.sha }}
else
COMMIT_HASH=${{ github.sha }}
fi
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
echo "Commit hash is: $COMMIT_HASH"
# Choose the correct EAS channel
if [ "${{ inputs.eas-channel }}" == "none" ] || [ -z "${{ inputs.eas-channel }}" ]; then
# Default to the branch
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
CHANNEL=prd
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then
CHANNEL=stg
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
CHANNEL=dev
elif [ ! -z "${{ github.event.pull_request }}" ]; then
CHANNEL=fte
else
echo "Branch not recognized for EAS build defaulting to production build with out auto submit"
CHANNEL=prd
AUTO_SUBMIT=false
fi
else
CHANNEL="${{ inputs.eas-channel }}"
fi
echo "CHANNEL IS $CHANNEL"
# Get the keys and determine the correct environment name
EAS_KEYS=$(jq -r '.build | keys[]' eas.json)
EAS_ENV_DEV=`echo "$EAS_KEYS" | grep -E "^(dev|develop|development)$" | head -n 1`
EAS_ENV_STG=`echo "$EAS_KEYS" | grep -E "^(stg|stage|staging)$" | head -n 1`
EAS_ENV_PRD=`echo "$EAS_KEYS" | grep -E "^(prd|prod|production)$" | head -n 1`
EAS_ENV_FTE=`echo "$EAS_KEYS" | grep -E "^(fte|feat|feature)$" | head -n 1`
echo "EAS_ENV_DEV: $EAS_ENV_DEV"
echo "EAS_ENV_STG: $EAS_ENV_STG"
echo "EAS_ENV_PRD: $EAS_ENV_PRD"
echo "EAS_ENV_FTE: $EAS_ENV_FTE"
if [[ "$CHANNEL" == "prd" ]]; then
# Update production env
jq --arg hash "$COMMIT_HASH" '.build.production.env.EXPO_PUBLIC_COMMIT_HASH = $hash' eas.json | sponge eas.json
set +e
eas build --platform all --profile $EAS_ENV_PRD --no-wait --auto-submit --non-interactive
EAS_EXIT_CODE=$?
set -e
if [ $EAS_EXIT_CODE -ne 0 ]; then
echo "EAS build failed with exit code $EAS_EXIT_CODE"
exit $EAS_EXIT_CODE
fi
elif [[ "$CHANNEL" == "stg" ]]; then
# Update staging env
jq --arg hash "$COMMIT_HASH" '.build.staging.env.EXPO_PUBLIC_COMMIT_HASH = $hash' eas.json | sponge eas.json
set +e
eas build --platform all --profile $EAS_ENV_STG --no-wait --auto-submit --non-interactive
EAS_EXIT_CODE=$?
set -e
if [ $EAS_EXIT_CODE -ne 0 ]; then
echo "EAS build failed with exit code $EAS_EXIT_CODE"
exit $EAS_EXIT_CODE
fi
elif [[ "$CHANNEL" == "dev" ]]; then
# Update development env
jq --arg hash "$COMMIT_HASH" '.build.development.env.EXPO_PUBLIC_COMMIT_HASH = $hash' eas.json | sponge eas.json
set +e
eas build --platform all --profile $EAS_ENV_DEV --no-wait --auto-submit --non-interactive
EAS_EXIT_CODE=$?
set -e
if [ $EAS_EXIT_CODE -ne 0 ]; then
echo "EAS build failed with exit code $EAS_EXIT_CODE"
exit $EAS_EXIT_CODE
fi
elif [[ "$CHANNEL" == "fte" ]]; then
echo "Running feature build"
# Get public name from PR title
ID=$(echo ${{ github.event.pull_request.title }} | grep -oP '\[MD-\K[0-9]+' || echo "")
echo "Got id $ID"
if [ -z "$ID" ]; then
CHANNEL=feat
else
CHANNEL=feat-$ID
fi
echo "CHANNEL IS $CHANNEL"
PROJECT_NAME="${{ github.event.repository.name }}"
PUBLIC_NAME="${PROJECT_NAME^} $ID"
PR="${{ github.event.number }}"
jq --arg a "$PUBLIC_NAME" --arg hash "$COMMIT_HASH" '.build.feature.env.EXPO_PUBLIC_NAME = $a | .build.feature.env.EXPO_PUBLIC_COMMIT_HASH = $hash' eas.json | sponge eas.json
echo "PUBLIC_NAME IS $PUBLIC_NAME"
# Get preview link from Vercel bot comment
echo "Waiting for Vercel bot comment..."
RETRY_COUNT=0
MAX_RETRIES=10
RETRY_DELAY=60 # 1 minute
VERCEL_FOUND=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Attempt $((RETRY_COUNT + 1)) of $MAX_RETRIES to find Vercel bot comment..."
COMMENTS=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.github-token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments?per_page=100)
echo "COMMENT LENGTH: ${#COMMENTS}"
BODY=$(echo $COMMENTS | jq -r '.[] | select(.user.login == "vercel[bot]") | .body')
echo "BODY: $BODY"
if [ ! -z "$BODY" ] && [ "$BODY" != "null" ]; then
LINK=$(echo $BODY | grep -oP '\| \[Preview]\(\K[^\)]+' || echo "")
echo "LINK: $LINK"
if [ ! -z "$LINK" ]; then
echo "Found Vercel preview link: $LINK"
URL=$(curl -Ls -o /dev/null -w %{url_effective} $LINK)
echo "URL: $URL"
API_URL="https://$(echo $URL | cut -d/ -f3)"
echo "API_URL: $API_URL"
VERCEL_FOUND=true
break
else
echo "Vercel bot comment found but no preview link detected"
fi
else
echo "Vercel bot comment not found yet"
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "Waiting $RETRY_DELAY seconds before next attempt..."
sleep $RETRY_DELAY
fi
done
if [ "$VERCEL_FOUND" = false ]; then
echo "ERROR: Vercel bot comment with preview link not found after $MAX_RETRIES attempts (10 minutes total)"
echo "This usually means the Vercel deployment failed or is taking longer than expected"
echo "Check the Vercel dashboard for the build status"
exit 1
fi
jq --arg a "$API_URL" '.build.feature.env.EXPO_PUBLIC_API_URL = $a' eas.json | sponge eas.json
echo "Updated API URL to $API_URL"
# Update app icon
ICON_PATH=$(jq '.build.feature.env.EXPO_PUBLIC_ICON' eas.json | tr -d '"')
echo "ICON_PATH: $ICON_PATH"
ADAPTIVE_ICON_PATH=$(jq '.build.feature.env.EXPO_PUBLIC_ADAPTIVE_ICON' eas.json | tr -d '"')
echo "ADAPTIVE_ICON_PATH: $ADAPTIVE_ICON_PATH"
convert $ICON_PATH -pointsize 378 -fill white -gravity center -stroke black -strokewidth 5 -draw "rotate -45 text 0,0 '$ID'" "$ICON_PATH"
convert $ADAPTIVE_ICON_PATH -pointsize 378 -fill white -gravity center -stroke black -strokewidth 5 -draw "rotate -45 text 0,0 '$ID'" "$ADAPTIVE_ICON_PATH"
echo "Converted icons"
echo "EAS BUILD COMMAND: eas build --platform all --profile $EAS_ENV_FTE --no-wait --non-interactive"
set +e
EAS_STDOUT=$(eas build --platform all --profile $EAS_ENV_FTE --no-wait --non-interactive 2>&1)
EAS_EXIT_CODE=$?
set -e
echo "EAS Build Output:"
echo "$EAS_STDOUT"
if [ $EAS_EXIT_CODE -ne 0 ]; then
echo "EAS build failed with exit code $EAS_EXIT_CODE"
exit $EAS_EXIT_CODE
fi
ANDROID_BUILD_LINK=$(echo $EAS_STDOUT | grep -oP 'Android logs: \K[^ )]+')
echo "ANDROID_BUILD_LINK=$ANDROID_BUILD_LINK" >> $GITHUB_ENV
echo "ANDROID_BUILD_LINK IS ${ANDROID_BUILD_LINK}"
IOS_BUILD_LINK=$(echo $EAS_STDOUT | grep -oP 'iOS logs: \K[^ )]+')
echo "IOS_BUILD_LINK=$IOS_BUILD_LINK" >> $GITHUB_ENV
echo "IOS_BUILD_LINK IS ${IOS_BUILD_LINK}"
BUILD_COMMENT_ID=$(echo "$COMMENTS" | jq '.[] | select(.body | startswith("Most recent mobile feature builds:")) | .id' | tail -n1)
# Delete existing comment if it exists
if [ ! -z "$ANDROID_BUILD_LINK" ] || [ ! -z "$IOS_BUILD_LINK" ]; then
if [ ! -z "$BUILD_COMMENT_ID" ]; then
echo "Deleting existing comment with ID: $BUILD_COMMENT_ID"
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.github-token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/issues/comments/$BUILD_COMMENT_ID"
fi
# Create a new comment
echo "Creating new comment with build links"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.github-token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d "{\"body\":\"Most recent mobile feature builds:\niOS build: $IOS_BUILD_LINK\nAndroid build: $ANDROID_BUILD_LINK\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments"
fi
else
echo "Path not recognized for EAS build; erroring"
exit 1
fi
# Storing the channel in the environment for the next step
echo "CHANNEL=$CHANNEL" >> $GITHUB_ENV
- name: Create tag
shell: bash
run: |
git fetch --prune --unshallow --tags
if [ ! -z "${{ github.event.pull_request }}" ]; then
git checkout ${{ github.event.pull_request.head.sha }}
fi
# Add one since we incremented
git tag build-$((CURRENT_VERSION+1))-${{ env.CHANNEL }}
git push origin build-$((CURRENT_VERSION+1))-${{ env.CHANNEL }}