Skip to content

Commit 3c81e08

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

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

action.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ runs:
9494
- name: Native Fingerprint
9595
id: fingerprint
9696
run: |
97-
FINGERPRINT_OUTPUT=$(npx rock fingerprint -p android --raw)
97+
FINGERPRINT_OUTPUT=$(npx rock fingerprint -p android --raw) || (echo "$FINGERPRINT_OUTPUT" && exit 1)
9898
echo "FINGERPRINT=$FINGERPRINT_OUTPUT" >> $GITHUB_ENV
9999
shell: bash
100100
working-directory: ${{ inputs.working-directory }}
101101

102102
- name: Get Provider Name
103103
run: |
104-
PROVIDER_NAME=$(npx rock remote-cache get-provider-name)
104+
PROVIDER_NAME=$(npx rock remote-cache get-provider-name) || (echo "$PROVIDER_NAME" && exit 1)
105105
echo "PROVIDER_NAME=$PROVIDER_NAME" >> $GITHUB_ENV
106106
shell: bash
107107
working-directory: ${{ inputs.working-directory }}
@@ -120,7 +120,7 @@ runs:
120120
ARTIFACT_TRAITS="${{ inputs.variant }},${{ github.event.pull_request.number}}"
121121
echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV
122122
123-
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json)
123+
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
124124
if [ "$OUTPUT" ]; then
125125
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
126126
echo "ARTIFACT_ID=$(echo "$OUTPUT" | jq -r '.id')" >> $GITHUB_ENV
@@ -134,7 +134,7 @@ runs:
134134
ARTIFACT_TRAITS="${{ inputs.variant }}"
135135
echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV
136136
137-
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json)
137+
OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
138138
if [ "$OUTPUT" ]; then
139139
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
140140
echo "ARTIFACT_ID=$(echo "$OUTPUT" | jq -r '.id')" >> $GITHUB_ENV
@@ -177,7 +177,7 @@ runs:
177177
- name: Determine Android sourceDir and appName
178178
if: ${{ !env.ARTIFACT_URL }}
179179
run: |
180-
JSON_OUTPUT=$(npx rock config -p android)
180+
JSON_OUTPUT=$(npx rock config -p android) || (echo "$JSON_OUTPUT" && exit 1)
181181
echo "$JSON_OUTPUT" | jq -r '.project'
182182
ANDROID_SOURCE_DIR=$(echo "$JSON_OUTPUT" | jq -r '.project.android.sourceDir')
183183
APP_NAME=$(echo "$JSON_OUTPUT" | jq -r '.project.android.appName')
@@ -212,7 +212,7 @@ runs:
212212
- name: Download and Unpack APK
213213
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' && github.event_name == 'pull_request' }}
214214
run: |
215-
DOWNLOAD_OUTPUT=$(npx rock remote-cache download --name ${{ env.ARTIFACT_NAME }} --json)
215+
DOWNLOAD_OUTPUT=$(npx rock remote-cache download --name ${{ env.ARTIFACT_NAME }} --json) || (echo "$DOWNLOAD_OUTPUT" && exit 1)
216216
APK_PATH=$(echo "$DOWNLOAD_OUTPUT" | jq -r '.path')
217217
echo "ARTIFACT_PATH=$APK_PATH" >> $GITHUB_ENV
218218
shell: bash
@@ -228,7 +228,7 @@ runs:
228228
# Find artifact URL again before uploading, as other concurrent workflows could upload the same artifact
229229
- name: Find artifact URL again before uploading
230230
run: |
231-
OUTPUT=$(npx rock remote-cache list --name ${{ env.ARTIFACT_NAME }} --json)
231+
OUTPUT=$(npx rock remote-cache list --name ${{ env.ARTIFACT_NAME }} --json) || (echo "$OUTPUT" && exit 1)
232232
if [ -z "$OUTPUT" ]; then
233233
echo "No artifact found"
234234
else
@@ -247,17 +247,19 @@ runs:
247247
path: ${{ env.ARTIFACT_PATH }}
248248
if-no-files-found: error
249249

250+
# For re-signed builds, the ARTIFACT_NAME may contain PR-number, while Rock will save the artifact without PR trait in its cache.
251+
# 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.
250252
- name: Upload Artifact to Remote Cache for re-signed builds
251253
if: ${{ env.PROVIDER_NAME != 'GitHub' && (inputs.re-sign == 'true' && github.event_name == 'pull_request') }}
252254
run: |
253-
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path ${{ env.ARTIFACT_PATH }} --json --verbose)
255+
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path ${{ env.ARTIFACT_PATH }} --json --verbose) || (echo "$OUTPUT" && exit 1)
254256
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
255257
shell: bash
256258

257259
- name: Upload Artifact to Remote Cache for regular builds
258260
if: ${{ env.PROVIDER_NAME != 'GitHub' && !env.ARTIFACT_URL }}
259261
run: |
260-
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --json --verbose)
262+
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --json --verbose) || (echo "$OUTPUT" && exit 1)
261263
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
262264
shell: bash
263265

0 commit comments

Comments
 (0)