Skip to content

Commit d5a5ab2

Browse files
committed
chore: add error handling for escaped npx rock commands
1 parent 3cb20ec commit d5a5ab2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

action.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: 'Remote Build - Android'
22
description: 'Github implementation of the Rock Remote Build for Android'
33

4+
branding:
5+
icon: 'box'
6+
color: 'green'
7+
48
inputs:
59
github-token:
610
description: 'GitHub Token'
@@ -94,14 +98,14 @@ runs:
9498
- name: Native Fingerprint
9599
id: fingerprint
96100
run: |
97-
FINGERPRINT_OUTPUT=$(npx rock fingerprint -p android --raw)
101+
FINGERPRINT_OUTPUT=$(npx rock fingerprint -p android --raw) || (echo "$FINGERPRINT_OUTPUT" && exit 1)
98102
echo "FINGERPRINT=$FINGERPRINT_OUTPUT" >> $GITHUB_ENV
99103
shell: bash
100104
working-directory: ${{ inputs.working-directory }}
101105

102106
- name: Get Provider Name
103107
run: |
104-
PROVIDER_NAME=$(npx rock remote-cache get-provider-name)
108+
PROVIDER_NAME=$(npx rock remote-cache get-provider-name) || (echo "$PROVIDER_NAME" && exit 1)
105109
echo "PROVIDER_NAME=$PROVIDER_NAME" >> $GITHUB_ENV
106110
shell: bash
107111
working-directory: ${{ inputs.working-directory }}
@@ -120,7 +124,7 @@ runs:
120124
ARTIFACT_TRAITS="${{ inputs.variant }},${{ github.event.pull_request.number}}"
121125
echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV
122126
123-
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json)
127+
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
124128
if [ "$OUTPUT" ]; then
125129
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
126130
echo "ARTIFACT_ID=$(echo "$OUTPUT" | jq -r '.id')" >> $GITHUB_ENV
@@ -134,7 +138,7 @@ runs:
134138
ARTIFACT_TRAITS="${{ inputs.variant }}"
135139
echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV
136140
137-
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json)
141+
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
138142
if [ "$OUTPUT" ]; then
139143
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
140144
echo "ARTIFACT_ID=$(echo "$OUTPUT" | jq -r '.id')" >> $GITHUB_ENV
@@ -177,7 +181,7 @@ runs:
177181
- name: Determine Android sourceDir and appName
178182
if: ${{ !env.ARTIFACT_URL }}
179183
run: |
180-
JSON_OUTPUT=$(npx rock config -p android)
184+
JSON_OUTPUT=$(npx rock config -p android) || (echo "$JSON_OUTPUT" && exit 1)
181185
echo "$JSON_OUTPUT" | jq -r '.project'
182186
ANDROID_SOURCE_DIR=$(echo "$JSON_OUTPUT" | jq -r '.project.android.sourceDir')
183187
APP_NAME=$(echo "$JSON_OUTPUT" | jq -r '.project.android.appName')
@@ -212,7 +216,7 @@ runs:
212216
- name: Download and Unpack APK
213217
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' && github.event_name == 'pull_request' }}
214218
run: |
215-
DOWNLOAD_OUTPUT=$(npx rock remote-cache download --name ${{ env.ARTIFACT_NAME }} --json)
219+
DOWNLOAD_OUTPUT=$(npx rock remote-cache download --name ${{ env.ARTIFACT_NAME }} --json) || (echo "$DOWNLOAD_OUTPUT" && exit 1)
216220
APK_PATH=$(echo "$DOWNLOAD_OUTPUT" | jq -r '.path')
217221
echo "ARTIFACT_PATH=$APK_PATH" >> $GITHUB_ENV
218222
shell: bash
@@ -228,7 +232,7 @@ runs:
228232
# Find artifact URL again before uploading, as other concurrent workflows could upload the same artifact
229233
- name: Find artifact URL again before uploading
230234
run: |
231-
OUTPUT=$(npx rock remote-cache list --name ${{ env.ARTIFACT_NAME }} --json)
235+
OUTPUT=$(npx rock remote-cache list --name ${{ env.ARTIFACT_NAME }} --json) || (echo "$OUTPUT" && exit 1)
232236
if [ -z "$OUTPUT" ]; then
233237
echo "No artifact found"
234238
else
@@ -247,17 +251,19 @@ runs:
247251
path: ${{ env.ARTIFACT_PATH }}
248252
if-no-files-found: error
249253

254+
# For re-signed builds, the ARTIFACT_NAME may contain PR-number, while Rock will save the artifact without PR trait in its cache.
255+
# We need to upload the artifact with the PR-number in the name, that's why we use --binary-path with appropriate ARTIFACT_PATH that accounts for it.
250256
- name: Upload Artifact to Remote Cache for re-signed builds
251257
if: ${{ env.PROVIDER_NAME != 'GitHub' && (inputs.re-sign == 'true' && github.event_name == 'pull_request') }}
252258
run: |
253-
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path ${{ env.ARTIFACT_PATH }} --json --verbose)
259+
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path ${{ env.ARTIFACT_PATH }} --json --verbose) || (echo "$OUTPUT" && exit 1)
254260
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
255261
shell: bash
256262

257263
- name: Upload Artifact to Remote Cache for regular builds
258264
if: ${{ env.PROVIDER_NAME != 'GitHub' && !env.ARTIFACT_URL }}
259265
run: |
260-
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --json --verbose)
266+
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --json --verbose) || (echo "$OUTPUT" && exit 1)
261267
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
262268
shell: bash
263269

0 commit comments

Comments
 (0)