Skip to content

refactor: refactor update test to prevent generating latest apk every… #3

refactor: refactor update test to prevent generating latest apk every…

refactor: refactor update test to prevent generating latest apk every… #3

name: Build apk from latest

Check failure on line 1 in .github/workflows/buildapkfromlatest.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/buildapkfromlatest.yml

Invalid workflow file

(Line: 16, Col: 6): Unexpected value '', (Line: 17, Col: 1): 'name' is already defined, (Line: 19, Col: 1): 'on' is already defined, (Line: 28, Col: 1): 'permissions' is already defined, (Line: 32, Col: 1): 'jobs' is already defined
on:
workflow_dispatch:
push:
tags:
- latest
schedule:
# Runs on the 1st day of every 2 months at 00:00 UTC
- cron: "0 0 1 */2 *"
permissions:
# Only need read access to repository contents
contents: read
jobs:
name: Build Signed APK
on:
workflow_dispatch:
workflow_call:
# Commit or tag as input parameter
inputs:
ref:
required: true
type: string
permissions:
# Only need read access to repository contents
contents: read
jobs:
build_apks:
# Job to build APKs for the latest commit and the commit that triggered the workflow
name: Build APKs
runs-on: ubuntu-latest
env:
BUILD_TOOLS_VERSION: "34.0.0"
steps:
# Checkout the specific commit
- name: Checkout specific commit
uses: actions/checkout@v5
with:
ref: latest
# Set up Java JDK required for Gradle
- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '17'
# Set up Android SDK and build tools
- name: Set up Android SDK
uses: android-actions/setup-android@v2
# Cache Gradle dependencies to speed up builds
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Build the APK
- name: Build APK
run: ./gradlew assembleqaRelease --no-daemon --stacktrace --info
# Copy the built APK to a commit-specific name
- name: Get apk
run: cp owncloudApp/build/outputs/apk/qa/release/owncloud_*-qa-release*.apk owncloud-latest.apk
# Decode keystore from secret for signing
- name: Restore keystore
run: |
echo "${{ secrets.TEST_KS_B64 }}" | base64 --decode > ./test.keystore
# Align and sign the APK
- name: Sign APK
run: |
APK_INPUT="owncloud-latest.apk"
APK_ALIGNED="owncloud-latest-aligned.apk"
APK_SIGNED="owncloudSigned-latest.apk"
KEYSTORE="./test.keystore"
KEY_ALIAS="${{ secrets.TEST_KS_ALIAS }}"
KEY_PASSWORD="${{ secrets.TEST_KS_KEY }}"
# Align APK for optimal performance
echo "Aligning APK..."
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/zipalign -v -p 4 "$APK_INPUT" "$APK_ALIGNED"
# Sign APK using keystore
echo "Signing APK..."
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/apksigner sign \
--ks "$KEYSTORE" \
--ks-type PKCS12 \
--ks-pass pass:"$KEY_PASSWORD" \
--key-pass pass:"$KEY_PASSWORD" \
--ks-key-alias "$KEY_ALIAS" \
--out "$APK_SIGNED" \
"$APK_ALIGNED"
echo "Signed APK: $APK_SIGNED"
# Clean up temporary files
rm -f "$APK_ALIGNED"
rm -f ./test.keystore
# Upload the signed APK as an artifact
- name: Upload APK as artifact
uses: actions/upload-artifact@v4
with:
name: owncloudSigned-latest
path: ./owncloudSigned-latest.apk
retention-days: 90