Skip to content

Commit a460cf7

Browse files
committed
fix: optimize adhoc artifact uploads and naming
1 parent fa2f267 commit a460cf7

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

action.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,24 @@ runs:
290290
shell: bash
291291
working-directory: ${{ inputs.working-directory }}
292292

293-
- name: Update Artifact Name for re-signed builds
294-
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' }}
293+
- name: Set Identifier
294+
if: ${{ inputs.re-sign == 'true' || inputs.ad-hoc == 'true' }}
295295
run: |
296-
if [ "${{ github.event_name }}" = "pull_request" ]; then
297-
IDENTIFIER="${{ github.event.pull_request.number }}"
298-
elif [ -n "${{ inputs.custom-ref }}" ]; then
296+
if [ -n "${{ inputs.custom-ref }}" ]; then
299297
IDENTIFIER="${{ inputs.custom-ref }}"
298+
elif [ "${{ github.event_name }}" = "pull_request" ]; then
299+
IDENTIFIER="${{ github.event.pull_request.number }}"
300300
else
301301
IDENTIFIER=$(echo "$GITHUB_SHA" | cut -c1-7)
302302
fi
303+
echo "IDENTIFIER=$IDENTIFIER" >> $GITHUB_ENV
304+
shell: bash
305+
306+
# Non-ad-hoc re-sign flow: add identifier to ARTIFACT_NAME so the re-signed ZIP Artifact doesn't overwrite the base ZIP.
307+
# Skipped for ad-hoc — ARTIFACT_NAME stays fingerprint-only (one ZIP Artifact per fingerprint).
308+
- name: Update Artifact Name for re-signed builds
309+
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' && inputs.ad-hoc != 'true' }}
310+
run: |
303311
ARTIFACT_TRAITS="${{ inputs.variant }},${IDENTIFIER}"
304312
ARTIFACT_TRAITS_HYPHENATED=$(echo "$ARTIFACT_TRAITS" | tr ',' '-')
305313
ARTIFACT_TRAITS_HYPHENATED_FINGERPRINT="${ARTIFACT_TRAITS_HYPHENATED}-${FINGERPRINT}"
@@ -328,28 +336,45 @@ runs:
328336
path: ${{ env.ARTIFACT_PATH }}
329337
if-no-files-found: error
330338

339+
# Non-ad-hoc re-sign flow: upload ZIP Artifact with {identifier}-{fingerprint} name
331340
# For re-signed builds, the ARTIFACT_NAME may contain PR-number, while Rock will save the artifact without PR trait in its cache.
332341
# 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.
333-
- name: Upload Artifact to Remote Cache for re-signed builds
334-
if: ${{ env.PROVIDER_NAME != 'GitHub' && inputs.re-sign == 'true' }}
342+
- name: Upload re-signed ZIP Artifact for non-ad-hoc flow
343+
if: ${{ env.PROVIDER_NAME != 'GitHub' && inputs.re-sign == 'true' && inputs.ad-hoc != 'true' }}
335344
run: |
336345
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path "${{ env.ARTIFACT_PATH }}" --json --verbose) || (echo "$OUTPUT" && exit 1)
337346
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
338347
shell: bash
339348

340-
- name: Upload Artifact to Remote Cache for regular builds
341-
if: ${{ env.PROVIDER_NAME != 'GitHub' && inputs.re-sign != 'true' && !env.ARTIFACT_URL }}
349+
# Upload ZIP Artifact with {fingerprint}-only name as base ZIP Artifact for caching only (first build only).
350+
# Runs only when no cached artifact exists (!ARTIFACT_URL), meaning native build was done from scratch.
351+
# Excludes non-ad-hoc re-sign, which uploads with identifier in the name.
352+
# Applies to:
353+
# - regular builds (no ad-hoc, no re-sign)
354+
# - re-sign with ad-hoc
355+
- name: Upload ZIP Artifact for caching
356+
if: ${{ env.PROVIDER_NAME != 'GitHub' && !env.ARTIFACT_URL && (inputs.re-sign != 'true' || inputs.ad-hoc == 'true') }}
342357
run: |
343358
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --json --verbose) || (echo "$OUTPUT" && exit 1)
344359
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
345360
shell: bash
346361

347-
# For ad-hoc builds, the ARTIFACT_NAME may contain PR-number, while Rock will save the artifact without PR trait in its cache.
348-
# 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.
362+
363+
# Ad-hoc uploads always include an identifier in the name {identifier}-{fingerprint}
364+
- name: Set Ad-Hoc Artifact Name
365+
if: ${{ inputs.ad-hoc == 'true' }}
366+
run: |
367+
ADHOC_TRAITS="${{ inputs.variant }},${IDENTIFIER}"
368+
ADHOC_TRAITS_HYPHENATED=$(echo "$ADHOC_TRAITS" | tr ',' '-')
369+
echo "ADHOC_ARTIFACT_NAME=rock-android-${ADHOC_TRAITS_HYPHENATED}-${FINGERPRINT}" >> $GITHUB_ENV
370+
shell: bash
371+
372+
# Uploads APK/AAB + index.html under ad-hoc/{ADHOC_ARTIFACT_NAME}/.
373+
# The ARTIFACT_URL output points to index.html
349374
- name: Upload for Ad-hoc distribution
350375
if: ${{ env.PROVIDER_NAME != 'GitHub' && inputs.ad-hoc == 'true' }}
351376
run: |
352-
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ARTIFACT_NAME }} --binary-path "${{ env.ARTIFACT_PATH }}" --json --ad-hoc) || (echo "$OUTPUT" && exit 1)
377+
OUTPUT=$(npx rock remote-cache upload --name ${{ env.ADHOC_ARTIFACT_NAME }} --binary-path "${{ env.ARTIFACT_PATH }}" --json --ad-hoc) || (echo "$OUTPUT" && exit 1)
353378
echo "ARTIFACT_URL=$(echo "$OUTPUT" | jq -r '.url')" >> $GITHUB_ENV
354379
shell: bash
355380

0 commit comments

Comments
 (0)