-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaction.yml
More file actions
239 lines (215 loc) · 9.48 KB
/
action.yml
File metadata and controls
239 lines (215 loc) · 9.48 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
name: 'Remote Build - Android'
description: 'Github implementation of the RNEF Remote Build for Android'
inputs:
github-token:
description: 'GitHub Token'
required: true
working-directory:
description: 'Working directory for the build command'
required: false
default: '.'
validate-gradle-wrapper:
description: 'Whether to validate the Gradle wrapper'
required: false
default: true
variant:
description: 'Build variant'
required: false
default: 'debug'
rnef-build-extra-params:
description: 'Extra parameters to pass to "rnef build:android"'
required: false
architectures:
description: 'A comma-separated list of device architectures to build for (e.g. "arm64-v8a,armeabi-v7a")'
required: false
sign:
description: 'Whether to sign the build with release keystore'
required: false
re-sign:
description: Re-sign the app bundle with new JS bundle
required: false
keystore-base64:
description: 'Base64 version of the release keystore'
required: false
keystore-store-file:
description: 'Keystore store file name'
required: false
keystore-store-password:
description: 'Keystore store password'
required: false
keystore-key-alias:
description: 'Keystore key alias'
required: false
keystore-key-password:
description: 'Keystore key password'
required: false
comment-bot:
description: 'Whether to send a comment under PR with the link to the generated build'
required: false
default: true
outputs:
artifact-url:
description: 'URL of the relevant Android build artifact (could be cached)'
value: ${{ steps.upload-artifact.outputs.artifact-url || (steps.find-artifact.outcome == 'success' && steps.find-artifact.outputs.artifact-url) }}
artifact-id:
description: 'ID of the relevant Android build artifact (could be cached)'
value: ${{ steps.upload-artifact.outputs.artifact-id || (steps.find-artifact.outcome == 'success' && steps.find-artifact.outputs.artifact-id) }}
runs:
using: 'composite'
steps:
- name: Validate Inputs
run: |
if [ "${{ inputs.sign }}" == "true" ]; then
if [ -z "${{ inputs.keystore-base64 }}" ]; then
echo "Input 'keystore-base64' is required for signed builds."
exit 1
fi
if [ -z "${{ inputs.keystore-store-file }}" ]; then
echo " Input 'keystore-store-file' is required for signed builds."
exit 1
fi
if [ -z "${{ inputs.keystore-store-password }}" ]; then
echo "Input 'keystore-store-password' is required for signed builds."
exit 1
fi
if [ -z "${{ inputs.keystore-key-alias }}" ]; then
echo "Input 'keystore-key-alias' is required for signed builds."
exit 1
fi
if [ -z "${{ inputs.keystore-key-password }}" ]; then
echo "Input 'keystore-key-password' is required for signed builds."
exit 1
fi
fi
shell: bash
- name: Native Fingerprint
id: fingerprint
uses: callstackincubator/android/.github/actions/rnef-native-fingerprint@feat/architectures
with:
platform: android
working-directory: ${{ inputs.working-directory }}
- name: Set Artifact Name
run: |
echo "ARTIFACT_NAME=rnef-android-${{ inputs.variant }}-${{ steps.fingerprint.outputs.hash}}" >> $GITHUB_ENV
shell: bash
- name: Find artifact URL
id: find-artifact
uses: callstackincubator/android/.github/actions/find-artifact@feat/architectures
with:
name: ${{ env.ARTIFACT_NAME }}
re-sign: ${{ inputs.re-sign }}
github-token: ${{ inputs.github-token }}
pr-number: ${{ github.event.pull_request.number }}
- name: Install Java
if: ${{ !steps.find-artifact.outputs.artifact-url }}
uses: actions/setup-java@v4
with:
java-version: 17
distribution: adopt
cache: gradle
- name: Validate Gradle wrapper
if: ${{ inputs.validate-gradle-wrapper == 'true' && !steps.find-artifact.outputs.artifact-url }}
uses: gradle/actions/wrapper-validation@v4
- name: Create local gradle.properties
if: ${{ !steps.find-artifact.outputs.artifact-url && inputs.sign }}
run: |
mkdir -p $HOME/.gradle
touch $HOME/.gradle/gradle.properties
echo "RNEF_UPLOAD_STORE_FILE=${{ inputs.keystore-store-file }}" >> $HOME/.gradle/gradle.properties
echo "RNEF_UPLOAD_STORE_PASSWORD=${{ inputs.keystore-store-password }}" >> $HOME/.gradle/gradle.properties
echo "RNEF_UPLOAD_KEY_ALIAS=${{ inputs.keystore-key-alias }}" >> $HOME/.gradle/gradle.properties
echo "RNEF_UPLOAD_KEY_PASSWORD=${{ inputs.keystore-key-password }}" >> $HOME/.gradle/gradle.properties
shell: bash
- name: Determine Android sourceDir and appName
if: ${{ !steps.find-artifact.outputs.artifact-url }}
run: |
JSON_OUTPUT=$(npx rnef config -p android)
echo "$JSON_OUTPUT" | jq -r '.project'
ANDROID_SOURCE_DIR=$(echo "$JSON_OUTPUT" | jq -r '.project.android.sourceDir')
APP_NAME=$(echo "$JSON_OUTPUT" | jq -r '.project.android.appName')
echo "ANDROID_SOURCE_DIR=$ANDROID_SOURCE_DIR" >> $GITHUB_ENV
echo "APP_NAME=$APP_NAME" >> $GITHUB_ENV
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Decode and store keystore file
if: ${{ !steps.find-artifact.outputs.artifact-url && inputs.sign }}
run: |
echo "${{ inputs.keystore-base64 }}" | base64 --decode > $ANDROID_SOURCE_DIR/$APP_NAME/release.keystore
shell: bash
- name: Build Android
if: ${{ !steps.find-artifact.outputs.artifact-url }}
run: |
npx rnef build:android \
--variant "${{ inputs.variant }}" \
${{ inputs.architectures ? '--extra-params -PreactNativeArchitectures=' + inputs.architectures : '' }} \
${{ inputs.rnef-build-extra-params }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Find Build Artifact
if: ${{ !steps.find-artifact.outputs.artifact-url }}
run: |
APK_PATH=$(find $ANDROID_SOURCE_DIR/$APP_NAME/build/outputs -name '*.apk' | head -1 )
echo APK_PATH $APK_PATH
echo "ARTIFACT_PATH=$APK_PATH" >> $GITHUB_ENV
shell: bash
- name: Download and Unpack APK
if: ${{ steps.find-artifact.outputs.artifact-url && inputs.re-sign == 'true' && github.event_name == 'pull_request' }}
run: |
curl -L -H "Authorization: token ${{ inputs.github-token }}" \
-o artifact.zip \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${{ steps.find-artifact.outputs.artifact-id }}/zip"
unzip artifact.zip -d downloaded-artifacts
ls -l downloaded-artifacts
APK_PATH=$(find downloaded-artifacts -name "*.apk" -print -quit)
if [ -z "$APK_PATH" ]; then
echo "No APK file found in the extracted contents."
exit 1
fi
echo "ARTIFACT_PATH=$APK_PATH" >> $GITHUB_ENV
shell: bash
- name: Re-sign APK
if: ${{ steps.find-artifact.outputs.artifact-url && inputs.re-sign == 'true' && github.event_name == 'pull_request' }}
run: |
npx rnef sign:android ${{ env.ARTIFACT_PATH }} \
--build-jsbundle
shell: bash
working-directory: ${{ inputs.working-directory }}
# Find artifact URL again before uploading, as other concurrent workflows could upload the same artifact
- name: Find artifact URL again before uploading
id: find-artifact-after-build
uses: callstackincubator/android/.github/actions/find-artifact@feat/architectures
with:
name: ${{ env.ARTIFACT_NAME }}
re-sign: ${{ inputs.re-sign }}
github-token: ${{ inputs.github-token }}
pr-number: ${{ github.event.pull_request.number }}
- name: Upload Artifact
id: upload-artifact
if: ${{ !steps.find-artifact-after-build.outputs.artifact-url || (inputs.re-sign == 'true' && github.event_name == 'pull_request') }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.find-artifact-after-build.outputs.artifact-name || env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}
if-no-files-found: error
- name: Delete Old Re-Signed Artifacts
if: ${{ steps.find-artifact-after-build.outputs.artifact-url && inputs.re-sign == 'true' && github.event_name == 'pull_request' }}
run: |
for ID in ${{ steps.find-artifact-after-build.outputs.artifact-ids }}; do
echo "Deleting artifact with ID: $ID"
curl -X DELETE -H "Authorization: token ${{ inputs.github-token }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$ID"
done
shell: bash
- name: Clean Up Keystore and gradle properties (signed builds only)
if: ${{ !steps.find-artifact-after-build.outputs.artifact-url && inputs.sign }}
run: |
rm $HOME/.gradle/gradle.properties
rm $ANDROID_SOURCE_DIR/$APP_NAME/release.keystore
shell: bash
- name: Post Build
if: ${{ github.event_name == 'pull_request' && inputs.comment-bot == 'true' }}
uses: callstackincubator/android/.github/actions/rnef-post-build@feat/architectures
with:
title: Android ${{ inputs.variant }} APK for all devices
artifact-url: ${{ steps.upload-artifact.outputs.artifact-url || steps.find-artifact-after-build.outputs.artifact-url }}
github-token: ${{ inputs.github-token }}