Skip to content

[RN][GHA] Add Android Helloworld test on PR #7

[RN][GHA] Add Android Helloworld test on PR

[RN][GHA] Add Android Helloworld test on PR #7

Workflow file for this run

name: Test Android Helloworld on PR
on: [workflow_dispatch, pull_request, push]
jobs:
prepare_hermes_workspace:
runs-on: ubuntu-latest
env:
HERMES_WS_DIR: /tmp/hermes
HERMES_VERSION_FILE: packages/react-native/sdks/.hermesversion
BUILD_FROM_SOURCE: true
outputs:
react-native-version: ${{ steps.react-native-version.outputs.version }}
hermes-version: ${{ steps.hermes-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup node.js
uses: ./.github/actions/setup-node
- name: Setup hermes version
id: hermes-version
run: |
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
if [ -f "$HERMES_VERSION_FILE" ]; then
echo "Hermes Version file found! Using this version for the build:"
echo "VERSION=$(cat $HERMES_VERSION_FILE)" >> "$GITHUB_OUTPUT"
else
echo "Hermes Version file not found!!!"
echo "Using the last commit from main for the build:"
HERMES_TAG_SHA=$(git ls-remote https://github.com/$GITHUB_REPOSITORY main | cut -f 1 | tr -d '[:space:]')
echo "VERSION=$HERMES_TAG_SHA" >> "$GITHUB_OUTPUT"
fi
echo "Hermes commit is $HERMES_TAG_SHA"
- name: Get react-native version
id: react-native-version
run: |
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
# Save the react native version we are building in an output variable so we can use that file as part of the cache key.
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "React Native Version is $VERSION"
- name: Cache hermes workspace
uses: actions/cache@v4.0.0
with:
path: |
/tmp/hermes/download/
/tmp/hermes/hermes/
key: v1-hermes-${{ steps.hermes-version.outputs.version }}-${{ github.run_number }}
enableCrossOsArchive: true
- name: Yarn- Install Dependencies
run: yarn install --non-interactive
- name: Download Hermes tarball
run: |
node packages/react-native/scripts/hermes/prepare-hermes-for-build ${{ github.event.pull_request.html_url }}
cp packages/react-native/sdks/download/* $HERMES_WS_DIR/download/.
cp -r packages/react-native/sdks/hermes/* $HERMES_WS_DIR/hermes/.
echo ${{ steps.hermes-version.outputs.version }}
test_android_helloworld:
runs-on: ubuntu-latest
needs: prepare_hermes_workspace
container:
image: reactnativecommunity/react-native-android:latest
env:
# Set the encoding to resolve a known character encoding issue with decompressing tar.gz files in conatiners
# via Gradle: https://github.com/gradle/gradle/issues/23391#issuecomment-1878979127
LC_ALL: C.UTF8
YARN_ENABLE_IMMUTABLE_INSTALLS: false
TERM: "dumb"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
TARGET_ARCHITECTURE: "arm64-v8a"
continue-on-error: true
strategy:
fail-fast: false
matrix:
flavor: [Debug, Release]
architecture: [NewArch, OldArch]
jsengine: [Hermes, JSC]
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Cache setup
id: cache_setup
uses: ./.github/actions/cache_setup
with:
hermes-version: ${{ needs.prepare_hermes_workspace.outputs.hermes-version }}
react-native-version: ${{ needs.prepare_hermes_workspace.outputs.react-native-version }}
- name: Run yarn
shell: bash
run: yarn install --non-interactive
- name: Setup gradle
uses: ./.github/actions/setup-gradle
- name: Build CodeGen JS scripts
shell: bash
run: |
cd packages/react-native-codegen
yarn run build
- name: Monitor Disk utilization (before build)
shell: bash
if: always()
run: |
echo "On Runner:"
df -h
echo "Root:"
du -hs *
echo "Projects folder:"
du -hs ./packages/*
- name: Build the Helloworld application for ${{ matrix.flavor }} with Architecture set to ${{ matrix.architecture }}, and using the ${{ matrix.jsengine }} JS engine.
shell: bash
run: |
cd packages/helloworld/android
args=()
if [[ ${{ matrix.architecture }} == "OldArch" ]]; then
args+=(--arch old)
fi
if [[ ${{ matrix.jsengine }} == "JSC" ]]; then
args+=(--jsvm jsc)
fi
if [[ ${{ matrix.flavor }} == "Release" ]]; then
args+=(--prod)
fi
yarn build android "${args[@]}" -P reactNativeArchitectures="$TARGET_ARCHITECTURE"
- name: Monitor Disk utilization (after build)
shell: bash
if: always()
run: |
echo "On Runner:"
df -h
echo "Root:"
du -hs *
echo "Projects folder:"
du -hs ./packages/*
- name: Upload artifact
uses: actions/upload-artifact@v4.3.1
with:
name: template-apk-${{ matrix.flavor }}-${{ matrix.architecture }}-${{ matrix.jsengine }}
path: ./app/build/outputs/apk/
compression-level: 0