Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
# keystore-key-alias: 'your-key-alias'
# keystore-key-password: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
# keystore-path: 'tools/buildtools/upload-key.keystore' # Optional: for custom keystore locations
# For store AAB add this:
# aab: true
```

## Inputs
Expand All @@ -55,6 +57,7 @@ jobs:
| `validate-gradle-wrapper` | Whether to validate the Gradle wrapper | No | `true` |
| `setup-java` | Whether to run actions/setup-java action | No | `true` |
| `variant` | Build variant (debug/release) | No | `debug` |
| `aab` | Build Android App Bundle instead of APK | No | `false` |
| `sign` | Whether to sign the build with keystore | No | - |
| `re-sign` | Re-sign the APK with new JS bundle | No | `false` |
| `keystore-file` | Path to the keystore file | No | - |
Expand Down
33 changes: 22 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
description: 'Build variant'
required: false
default: 'debug'
aab:
description: 'Build Android App Bundle instead of APK'
required: false
default: false
rock-build-extra-params:
description: 'Extra parameters to pass to "rock build:android"'
required: false
Expand Down Expand Up @@ -116,6 +120,12 @@ runs:
shell: bash
working-directory: ${{ inputs.working-directory }}

- name: Set Build Type Env
id: build-type
run: echo "BUILD_TYPE=${{ inputs.aab == 'true' && 'aab' || 'apk' }}" >> $GITHUB_ENV
shell: bash
working-directory: ${{ inputs.working-directory }}

- name: Get Provider Name
run: |
PROVIDER_NAME=$(npx rock remote-cache get-provider-name) || (echo "$PROVIDER_NAME" && exit 1)
Expand All @@ -133,7 +143,7 @@ runs:
- name: Check if PR-related artifact exists
if: ${{ github.event_name == 'pull_request' && inputs.re-sign == 'true' }}
run: |
ARTIFACT_TRAITS="${{ inputs.variant }},${{ github.event.pull_request.number}}"
ARTIFACT_TRAITS="${{ inputs.variant }},${{ env.BUILD_TYPE }},${{ github.event.pull_request.number}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break existing remote caching. Let's remove that and for now you'll need to differentiate another way between APK and AAB artifacts (e.g. by setting up an env variable and adding that to fingerprint config: https://www.rockjs.dev/docs/configuration#fingerprint-configuration)

echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV

OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
Expand All @@ -147,7 +157,7 @@ runs:
- name: Check if regular artifact exists
if: ${{ !env.ARTIFACT_NAME }}
run: |
ARTIFACT_TRAITS="${{ inputs.variant }}"
ARTIFACT_TRAITS="${{ inputs.variant }},${{ env.BUILD_TYPE }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

echo "ARTIFACT_TRAITS=$ARTIFACT_TRAITS" >> $GITHUB_ENV

OUTPUT=$(npx rock remote-cache list -p android --traits "${ARTIFACT_TRAITS}" --json) || (echo "$OUTPUT" && exit 1)
Expand Down Expand Up @@ -240,27 +250,28 @@ runs:
run: |
npx rock build:android \
--variant "${{ inputs.variant }}" \
${{ env.BUILD_TYPE == 'aab' && '--aab' || '' }} \
${{ inputs.rock-build-extra-params }}
shell: bash
working-directory: ${{ inputs.working-directory }}

- name: Find Build Artifact
if: ${{ !env.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
BINARY_PATH=$(find $ANDROID_SOURCE_DIR/$APP_NAME/build/outputs -name '*.${{ inputs.aab == 'true' && 'aab' || 'apk' }}' | head -1 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create BINARY_EXT variable and use that instead of ${{ inputs.aab == 'true' && 'aab' || 'apk' }}

echo BINARY_PATH $BINARY_PATH
echo "ARTIFACT_PATH=$BINARY_PATH" >> $GITHUB_ENV
shell: bash

- name: Download and Unpack APK
- name: Download and Unpack Binary
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' }}
run: |
DOWNLOAD_OUTPUT=$(npx rock remote-cache download --name ${{ env.ARTIFACT_NAME }} --json) || (echo "$DOWNLOAD_OUTPUT" && exit 1)
APK_PATH=$(echo "$DOWNLOAD_OUTPUT" | jq -r '.path')
echo "ARTIFACT_PATH=$APK_PATH" >> $GITHUB_ENV
BINARY_PATH=$(echo "$DOWNLOAD_OUTPUT" | jq -r '.path')
echo "ARTIFACT_PATH=$BINARY_PATH" >> $GITHUB_ENV
shell: bash

- name: Re-sign APK
- name: Re-sign Binary
if: ${{ env.ARTIFACT_URL && inputs.re-sign == 'true' }}
run: |
npx rock sign:android ${{ env.ARTIFACT_PATH }} \
Expand All @@ -276,7 +287,7 @@ runs:
else
IDENTIFIER=$(echo "$GITHUB_SHA" | cut -c1-7)
fi
ARTIFACT_TRAITS="${{ inputs.variant }},${IDENTIFIER}"
ARTIFACT_TRAITS="${{ inputs.variant }},${{ env.BUILD_TYPE }},${IDENTIFIER}"
ARTIFACT_TRAITS_HYPHENATED=$(echo "$ARTIFACT_TRAITS" | tr ',' '-')
ARTIFACT_TRAITS_HYPHENATED_FINGERPRINT="${ARTIFACT_TRAITS_HYPHENATED}-${FINGERPRINT}"
echo "ARTIFACT_NAME=rock-android-${ARTIFACT_TRAITS_HYPHENATED_FINGERPRINT}" >> $GITHUB_ENV
Expand Down Expand Up @@ -342,6 +353,6 @@ runs:
if: ${{ github.event_name == 'pull_request' && inputs.comment-bot == 'true' }}
uses: callstackincubator/android/.github/actions/rock-post-build@v3
with:
title: Android ${{ inputs.variant }} APK for all devices
title: Android ${{ inputs.variant }} Binary for all devices
artifact-url: ${{ steps.upload-artifact.outputs.artifact-url || env.ARTIFACT_URL }}
github-token: ${{ inputs.github-token }}