Skip to content

Commit

Permalink
Build/nightly-android-test-deploy (#1125)
Browse files Browse the repository at this point in the history
# build: re-establish nightly android test build of mobile app

## JIRA Ticket

[BSS-271](https://jira.csiro.com/browse/BSS-271)

## Description

Get the workflow for android nightly deployment working again.

## Proposed Changes

Updates the workflow file to account for the app being in a
subdirectory. Everything else should be the same.


## How to Test

Testing by running the workflow, should result in an updated build on
the play store. You might have to take my word for it...

## Additional Information

Add any additional information or context about the pull request here.

## Checklist

- [x] I have confirmed all commits have been signed.
- [x] I have added JSDoc style comments to any new functions or classes.
- [ ] Relevant documentation such as READMEs, guides, and class comments
are updated.
  • Loading branch information
stevecassidy authored Sep 3, 2024
2 parents 3b36c5e + 7dc6a37 commit ba017ae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
---
# Nightly compile for e2e testing
name: Nightly Android builds
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
Expand All @@ -17,77 +10,84 @@ on:
schedule:
- cron: '39 20 * * 1-5'


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check_date:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
should_run: ${{ steps.commitswithintime.outputs.has-new-commits-within-time }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run CommitsWithinTime script
uses: AlexHolderDeveloper/CommitsWithinTime@v1.1.11
id: commitswithintime
with:
days: 1
- name: Get the output from CommitsWithinTime
- name: Check for changes
id: check
run: |
echo "The 'has-new-commits-within-time' value is ${{ steps.commitswithintime.outputs.has-new-commits-within-time }}"
echo "The 'number-of-commits-within-time' value is ${{ steps.commitswithintime.outputs.number-of-commits-within-time }}"
echo "The 'total-commits' value is ${{ steps.commitswithintime.outputs.total-commits }}"
git diff --quiet @{yesterday}.. || echo "changed=true" >> $GITHUB_OUTPUT
node-deb-gh-build-play:
# The type of runner that the job will run on
# https://github.com/Apple-Actions/Example-iOS/blob/master/.github/workflows/test.yml
runs-on: ubuntu-latest
needs: check_date
if: ${{ needs.check_date.outputs.should_run == 'true' }}
if: ${{ needs.check_date.outputs.changed == 'true' }}
continue-on-error: false
env:
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
strategy:
matrix:
node-version: ['20']
outputs:
prnum: ${{ steps.prnum.outputs.value }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Configure Turborepo Remote Cache
run: |
mkdir -p .turbo
if [ -n "${{ vars.TURBO_API_URL }}" ]; then
echo '{"apiurl": "${{ vars.TURBO_API_URL }}"}' > .turbo/config.json
echo "Turborepo config file created at .turbo/config.json"
else
echo "TURBO_API_URL not set. Skipping Turborepo cache configuration."
fi
if [ -n "$TURBO_TEAM" ] && [ -n "$TURBO_TOKEN" ]; then
echo "TURBO_TEAM and TURBO_TOKEN environment variables set"
else
echo "TURBO_TEAM and/or TURBO_TOKEN not set. Remote caching may not be available."
fi
- uses: actions/checkout@v4
- name: Cache node modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Get PR Number
id: prnum
- name: Install jq
run: sudo apt-get install -y jq

- name: Declare some variables
shell: bash
run: |
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
echo "app_version=$(jq -r '.version' app/package.json)" >> "$GITHUB_ENV"
- name: Create version string
shell: bash
run: |
echo -n "value=$(bin/getDescribeString.sh gh-play)" >> "$GITHUB_OUTPUT"
shell: bash
echo "version_string=v${{env.app_version}}-android-#${{env.sha_short}}" >> "$GITHUB_ENV"
# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-java-with-gradle
- name: Cache Gradle packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-java-with-gradle
- name: Set up adopt JDK 1.17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '17'
Expand All @@ -98,7 +98,7 @@ jobs:
with:
ruby-version: 3.3.1
bundler-cache: true
working-directory: android
working-directory: app/android
- name: Decode Service Account Key JSON File
uses: timheuer/base64-to-file@v1
id: service_account_json_file
Expand All @@ -113,34 +113,31 @@ jobs:
encodedString: ${{ secrets.KEYSTORE_FILE }}
# https://github.com/android-actions/setup-android
- name: Setup Android SDK
uses: android-actions/setup-android@v2
uses: android-actions/setup-android@v3
- name: Building webapp
run: |
export platform="github-actions-play"
export serverprefix="testing"
export VITE_CLUSTER_ADMIN_GROUP_NAME=cluster-admin
export VITE_COMMIT_VERSION=$(bin/getDescribeString.sh android)
export VITE_COMMIT_VERSION=${{env.version_string}}
export VITE_SHOW_WIPE=true
export VITE_SHOW_NEW_NOTEBOOK=true
export VITE_SHOW_MINIFAUXTON=true
export VITE_DIRECTORY_HOST=db.testing.fieldmark.app
export VITE_DIRECTORY_PORT=443
export VITE_CONDUCTOR_URL=${{env.NIGHTLY_CONDUCTOR_URL}}
export VITE_PRODUCTION_BUILD=true
export VITE_SERVICES=FAIMSTEXT
export VITE_USE_REAL_DATA=true
export VITE_PROD_BUILD=true
export VITE_TAG=prodAndroid
export VITE_PROD_BUILD=true
export VITE_TAG=prodAndroid
export VITE_BUGSNAG_KEY=${{secrets.BUGSNAG_KEY}}
git clean -xfd
npm ci
npm run build
# https://capacitorjs.com/docs/android
# The bundle install shouldn't be necessary, but given we've got ios and android in...
- run: npx cap update android
- run: npx cap sync --deployment android
- run: npm run app-update android --workspace=@faims3/app
- run: npm run webapp-sync --workspace=@faims3/app -- --deployment android
- name: Fastlane
run: |
cd android
cd app/android
bundle install
bundle exec fastlane deploy_fieldmark_closed_track
env:
Expand All @@ -150,21 +147,11 @@ jobs:
JAVA_KEY_PASSWORD: ${{ secrets.JAVA_KEY_PASSWORD }}
ANDROID_JSON_KEY_FILE: ${{ steps.service_account_json_file.outputs.filePath }}
serverprefix: "testing"
prnum: ${{steps.prnum.outputs.value}}
prnum: ${{env.version_string}}
# - run: cd android && ./gradlew assembleDebug
- name: Upload build artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: assets
path: |
${{ github.workspace }}/android/app/build/outputs/bundle/release
# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: "latest-android"
# prerelease: true
# title: "Android APK Development Build"
# files: |
# LICENSE
# *.apk

${{ github.workspace }}/app/android/app/build/outputs/bundle/release
12 changes: 8 additions & 4 deletions app/bin/getDescribeString.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ if [ -z "$1" ]; then
else
platform="$1";
fi

# Get the directory where the script is located
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# get some git commit info
descstring=$(echo $(git describe --long 2>/dev/null || git describe --all --long --always)| tr -d "\n")
# get the version number from package.json
version=$(grep '"version":' package.json | cut -d: -f 2 | sed -e 's/[", ]//g')
descstring=$(git rev-parse HEAD | cut -c 1-8)
# get the version number from package.json in the app project
version=$(grep '"version":' app/package.json | cut -d: -f 2 | sed -e 's/[", ]//g')
# put them together in a nice format
echo "$descstring" | sed -E "s#heads/[A-Za-z0-9-]+-0-g#v${version}-${platform}-#" | sed -E "s#-v.*-g#-#"
echo "v${version}-${platform}-#${descstring}"

0 comments on commit ba017ae

Please sign in to comment.