-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
276 lines (231 loc) · 10.4 KB
/
action.yml
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
name: "Nitro build tool for Android"
description: "A Gihub Action for building React Native apps with Nitro"
branding:
icon: "zap"
color: "gray-dark"
inputs:
# Basic configuration
root-directory:
description: The directory within your project, in which your code is located. Leave this field empty if your code is not located in a subdirectory"
default: "."
flavor:
description: "The product flavor for Gradle build variant"
# App Versioning
version-name:
description: "The version name for the app"
version-code:
description: "The version code for the app"
disable-version-name-from-package-json:
description: "Disable automatic version name configuration. By default will get the 'version' field from package.json and set the version name. Available Options: (`yes` / `no`)"
disable-version-code-auto-generation:
description: "Disable automatic version code generation. By default will generate a timestamp based number and set the version code. Available Options: (`yes` / `no`)"
# App Signing
keystore-url:
description: "Keystore url"
keystore-password:
description: "Keystore password"
keystore-key-alias:
description: "Keystore alias"
keystore-key-password:
description: "Keystore key password"
# Caching
cache-provider:
description: "Cache provider where cache artifacts will be persisted. Available Options: (`fs`: File system / `github`: Uses Github cache action / `s3`: Amazon - Simple Storage Service)"
default: "s3"
disable-cache:
description: "When setting this option to `yes` build cache optimizations won't be performed. Available Options: (`yes` / `no`)"
cache-env-var-lookup-keys:
description: "List of env var keys for lookup to determine cache fingerprint. A list of `\\|` separated values with env variable keys to lookup to determine whether the build should be cached or not"
cache-file-lookup-paths:
description: "List of files for lookup to determine cache fingerprint. A list of `\\|` separated value paths (relative to the root of the repo or absolute) to lookup in order to determine whether the build should be cached or not"
disable-metro-cache:
description: "Setting this field to yes will disable the React Native Metro cache feature"
# Hooks
pre-install-command:
description: "Run command prior to install project dependencies (e.g. `rm -rf ./some-folder`)"
pre-build-command:
description: "Run command prior to start building the app (e.g. `yarn tsc && yarn test`)"
post-build-command:
description: "Run command once build successfully finished (e.g. `yarn publish`)"
# Advanced
output-directory:
description: "The path to the directory where to place all of Nitro's output files"
entry-file:
description: "The entry file for bundle generation"
detox-configuration:
description: "Select a device configuration from your defined configurations"
debug:
description: "Enable verbose logs. Available Options: (`yes` / `no`)"
fail-safe:
description: "Runing the app in this mode allows you to prevent the build to fail but you can check the status in further steps"
outputs:
nitro-build-status:
description: "The status of the latest build (success / failure)"
value: ${{ steps.nitro-cli.outputs.nitro-build-status }}
nitro-output-dir:
description: "The path to the directory where to place all of Nitro's output files"
value: ${{ steps.nitro-cli.outputs.nitro-output-dir }}
nitro-logs-path:
description: "The full path to access the build log"
value: ${{ steps.nitro-cli.outputs.nitro-logs-path }}
nitro-summary-path:
description: "The full path to access the build summary report"
value: ${{ steps.nitro-cli.outputs.nitro-summary-path }}
nitro-app-path:
description: "The full path to access the Android package (.apk)"
value: ${{ steps.nitro-cli.outputs.nitro-app-path }}
runs:
using: "composite"
steps:
- name: Setup Android environment
uses: android-actions/setup-android@v2
- name: Setup JAVA SDK
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- name: Install Homebrew dependencies
shell: bash
if: runner.os == 'macOS'
run: |
brew update --preinstall
env HOMEBREW_NO_AUTO_UPDATE=1 brew install pigz coreutils jq
- name: Run Nitro CLI
id: nitro-cli
shell: bash
run: |
#!/bin/bash
# Do not exit on errors. If "safe mode" is not enabled it will exit properly at the end.
set +e
# shellcheck disable=SC2154
if [[ "${{ inputs.debug }}" == "true" || "${{ inputs.debug }}" == "yes" ]]; then
set -x
fi
if [[ -n "${{ inputs.entry-file }}" ]]; then
export ENTRY_FILE="${{ inputs.entry-file }}"
fi
# Build command arguments
args=("android")
args+=("--output-format" "json")
# shellcheck disable=SC2154
if [[ "${{ inputs.debug }}" == "true" || "${{ inputs.debug }}" == "yes" ]]; then
args+=("--verbose")
fi
args+=("--repo-path" "${GITHUB_WORKSPACE}")
# -------------------
# Basic configuration
# -------------------
if [[ -n "${{ inputs.root-directory }}" ]]; then
args+=("--root-directory" "${{ inputs.root-directory }}")
fi
if [[ -n "${{ inputs.flavor }}" ]]; then
args+=("--flavor" "${{ inputs.flavor }}")
fi
# --------------
# App Versioning
# --------------
if [[ -n "${{ inputs.version-name }}" ]]; then
args+=("--version-name" "${{ inputs.version-name }}")
fi
if [[ -n "${{ inputs.version-code }}" ]]; then
args+=("--version-code" "${{ inputs.version-code }}")
fi
# shellcheck disable=SC2154
if [[ "${{ inputs.disable-version-name-from-package-json }}" == "true" || "${{ inputs.disable-version-name-from-package-json }}" == "yes" ]]; then
args+=("--disable-version-name-from-package-json")
fi
# shellcheck disable=SC2154
if [[ "${{ inputs.disable-version-code-auto-generation }}" == "true" || "${{ inputs.disable-version-code-auto-generation }}" == "yes" ]]; then
args+=("--disable-version-code-auto-generation")
fi
# -----------
# App Signing
# -----------
if [[ -n "${{ inputs.keystore-url }}" ]]; then
args+=("--keystore-url" "${{ inputs.keystore-url }}")
fi
if [[ -n "${{ inputs.keystore-password }}" ]]; then
args+=("--keystore-password" '${{ inputs.keystore-password }}')
fi
if [[ -n "${{ inputs.keystore-key-alias }}" ]]; then
args+=("--keystore-key-alias" "${{ inputs.keystore-key-alias }}")
fi
if [[ -n "${{ inputs.keystore-key-password }}" ]]; then
args+=("--keystore-key-password" '${{ inputs.keystore-key-password }}')
fi
# -------
# Caching
# -------
if [[ -n "${{ inputs.cache-provider }}" ]]; then
args+=("--cache-provider" "${{ inputs.cache-provider }}")
fi
# shellcheck disable=SC2154
if [[ "${{ inputs.disable-cache }}" == "true" || "${{ inputs.disable-cache }}" == "yes" ]]; then
args+=("--disable-cache")
fi
if [[ -n "${{ inputs.cache-env-var-lookup-keys }}" ]]; then
IFS='|' cache_env_var_lookup_keys_value=("${{ inputs.cache-env-var-lookup-keys }}")
# shellcheck disable=SC2206
args+=("--cache-env-var-lookup-keys" ${cache_env_var_lookup_keys_value[@]})
fi
if [[ -n "${{ inputs.cache-file-lookup-paths }}" ]]; then
IFS='|' cache_file_lookup_paths_value=("${{ inputs.cache-file-lookup-paths }}")
# shellcheck disable=SC2206
args+=("--cache-file-lookup-paths" ${cache_file_lookup_paths_value[@]})
fi
# shellcheck disable=SC2154
if [[ "${{ inputs.disable-metro-cache }}" == "true" || "${{ inputs.disable-metro-cache }}" == "yes" ]]; then
args+=("--disable-metro-cache")
fi
# -----
# Hooks
# -----
if [[ -n "${{ inputs.pre-install-command }}" ]]; then
args+=("--pre-install-command" "${{ inputs.pre-install-command }}")
fi
if [[ -n "${{ inputs.pre-build-command }}" ]]; then
args+=("--pre-build-command" "${{ inputs.pre-build-command }}")
fi
if [[ -n "${{ inputs.post-build-command }}" ]]; then
args+=("--post-build-command" "${{ inputs.post-build-command }}")
fi
# --------
# Advanced
# --------
if [[ -n "${{ inputs.output-directory }}" ]]; then
args+=("--output-directory" "${{ inputs.output-directory }}")
fi
if [[ -n "${{ inputs.detox-configuration }}" ]]; then
args+=("--detox-configuration" "${{ inputs.detox-configuration }}")
fi
# -------------------
# Nitro Cli execution
# -------------------
NITRO_OUTPUT_JSON_PATH="$(pwd)/nitro-output.json"
npx @nitro-build/cli@^0.11.0 "${args[@]}"
exit_code=$?
# Set environment variables using envman
if [[ exit_code -ne 0 ]]; then
echo "nitro-build-status=failed" >> $GITHUB_OUTPUT
else
echo "nitro-build-status=success" >> $GITHUB_OUTPUT
fi
if [ -f "${NITRO_OUTPUT_JSON_PATH}" ]; then
output=$(cat < "${NITRO_OUTPUT_JSON_PATH}")
echo "${output}" | jq -r '.appPath' | xargs -I{} echo "nitro-app-path={}" >> $GITHUB_OUTPUT
echo "${output}" | jq -r '.outputDir' | xargs -I{} echo "nitro-output-dir={}" >> $GITHUB_OUTPUT
echo "${output}" | jq -r '.summaryPath' | xargs -I{} echo "nitro-summary-path={}" >> $GITHUB_OUTPUT
echo "${output}" | jq -r '.logsPath' | xargs -I{} echo "nitro-logs-path={}" >> $GITHUB_OUTPUT
else
echo "File not found: ${NITRO_OUTPUT_JSON_PATH}"
fi
# shellcheck disable=SC2154
if [[ "${{ inputs.fail-safe }}" == "true" || "${{ inputs.fail-safe }}" == "yes" ]]; then
if [[ exit_code -ne 0 ]]; then
echo "⚠️ Nitro has thrown a '${exit_code}' error code while running on fail-safe mode. You can check 'nitro-build-status' output value in further steps."
fi
else
# If not running in "safe mode" exit with captured exit_code
set -e
exit $exit_code
fi