Skip to content

feat: add workflow that builds an app with version and variant #2

feat: add workflow that builds an app with version and variant

feat: add workflow that builds an app with version and variant #2

Workflow file for this run

name: Build apk
on:
push:
branches:
- feature/actions_generic_workflow_build_app
workflow_dispatch:
inputs:
build_variant:
description: "Variant to build"
type: choice
required: true
default: "originalRelease"
options:
- originalDebug
- originalRelease
- mdmDebug
- mdmRelease
- qaDebug
- qaRelease
version:
description: "Version to build (commit, branch or tag)"
type: string
default: "master"
# This workflow can be reused from other repositories via workflow_call.
# It builds the APK from the caller repository at the requested version
# and exposes the generated artifact name as an output.
workflow_call:
inputs:
build_variant:
description: Variant to build
type: string
default: "originalRelease"
version:
description: "Version to build (commit, branch or tag)"
type: string
default: "master"
outputs:
artifact-name:
description: "Generated APK artifact name"
value: ${{ jobs.build_apk.outputs.artifact-name }}
permissions:
contents: read
actions: read
# NOTE:
# This workflow generates an UNSIGNED APK intended for internal usage
jobs:
# Builds the requested app variant and publishes the generated APK as an artifact
build_apk:
name: Build APK
runs-on: ubuntu-latest
outputs:
artifact-name: ${{ steps.set-outputs.outputs.artifact-name }}
steps:
# Validate build variant (mainly for workflow_call usage)
- name: Validate build variant
run: |
case "${{ inputs.build_variant }}" in
originalDebug|originalRelease|mdmDebug|mdmRelease|qaDebug|qaRelease) ;;
*) echo "Invalid build_variant: ${{ inputs.build_variant }}" && exit 1 ;;
esac
# Checkout the repo
- name: Checkout current repo
uses: actions/checkout@v4
with:
#ref: ${{ inputs.version }}
ref: master
# Set Java-JDK version
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
# Cache gradle
- 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 with the given variant
- name: Build APK
# run: ./gradlew clean assemble${{ inputs.build_variant }}
run: ./gradlew clean assembleqaRelease
# Name the out put artifact with date, commit, and variant
- name: Set artifact name
id: set-outputs
run: |
DATE=$(date +%Y%m%d_%H%M)
COMMIT=$(git rev-parse --short HEAD)
VARIANT="${{ inputs.build_variant }}"
# Extract flavor and build type from variant (e.g. qaRelease -> qa / release)
FLAVOR=$(echo "$VARIANT" | sed -E 's/(Release|Debug)//' | tr '[:upper:]' '[:lower:]')
BUILD_TYPE=$(echo "$VARIANT" | grep -qi debug && echo debug || echo release)
NAME="ownCloud-${{ inputs.build_variant }}-${COMMIT}-${DATE}.apk"
APK_PATH=./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/ownCloud*.apk
# Copy to root for an easier handling
cp "$APK_PATH" "./$NAME"
# Publish as output
echo "artifact-name=$NAME" >> $GITHUB_OUTPUT
ls -al .
# Publish the artifact
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-outputs.outputs.artifact-name }}
path: ./${{ steps.set-outputs.outputs.artifact-name }}