Skip to content

Commit 4db53d8

Browse files
committed
feat: add workflow that builds an app with version and variant
1 parent 365d7a0 commit 4db53d8

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

.github/workflows/buildapk.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Build apk
2+
3+
on:
4+
push:
5+
branches:
6+
- feature/actions_generic_workflow_build_app
7+
workflow_dispatch:
8+
inputs:
9+
build_variant:
10+
description: "Variant to build"
11+
type: choice
12+
required: true
13+
default: "originalRelease"
14+
options:
15+
- originalDebug
16+
- originalRelease
17+
- mdmDebug
18+
- mdmRelease
19+
- qaDebug
20+
- qaRelease
21+
version:
22+
description: "Version to build (commit, branch or tag)"
23+
type: string
24+
default: "master"
25+
26+
# This workflow can be reused from other repositories via workflow_call.
27+
# It builds the APK from the caller repository at the requested version
28+
# and exposes the generated artifact name as an output.
29+
workflow_call:
30+
inputs:
31+
build_variant:
32+
description: Variant to build
33+
type: string
34+
default: "originalRelease"
35+
version:
36+
description: "Version to build (commit, branch or tag)"
37+
type: string
38+
default: "master"
39+
outputs:
40+
artifact-name:
41+
description: "Generated APK artifact name"
42+
value: ${{ jobs.build_apk.outputs.artifact-name }}
43+
44+
permissions:
45+
contents: read
46+
actions: read
47+
48+
# NOTE:
49+
# This workflow generates an UNSIGNED APK intended for internal usage
50+
51+
jobs:
52+
53+
# Builds the requested app variant and publishes the generated APK as an artifact
54+
build_apk:
55+
name: Build APK
56+
runs-on: ubuntu-latest
57+
outputs:
58+
artifact-name: ${{ steps.set-outputs.outputs.artifact-name }}
59+
60+
steps:
61+
62+
# Validate build variant (mainly for workflow_call usage)
63+
- name: Validate build variant
64+
run: |
65+
case "${{ inputs.build_variant }}" in
66+
originalDebug|originalRelease|mdmDebug|mdmRelease|qaDebug|qaRelease) ;;
67+
*) echo "Invalid build_variant: ${{ inputs.build_variant }}" && exit 1 ;;
68+
esac
69+
70+
# Checkout the repo
71+
- name: Checkout current repo
72+
uses: actions/checkout@v4
73+
with:
74+
ref: ${{ inputs.version }}
75+
76+
# Set Java-JDK version
77+
- name: Setup JDK
78+
uses: actions/setup-java@v4
79+
with:
80+
distribution: 'temurin'
81+
java-version: '17'
82+
83+
# Cache gradle
84+
- name: Cache Gradle
85+
uses: actions/cache@v4
86+
with:
87+
path: |
88+
~/.gradle/caches
89+
~/.gradle/wrapper
90+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
91+
restore-keys: |
92+
${{ runner.os }}-gradle-
93+
94+
# Build the apk with the given variant
95+
- name: Build APK
96+
run: ./gradlew clean assemble${{ inputs.build_variant }}
97+
98+
# Name the out put artifact with date, commit, and variant
99+
- name: Set artifact name
100+
id: set-outputs
101+
run: |
102+
DATE=$(date +%Y%m%d_%H%M)
103+
COMMIT=$(git rev-parse --short HEAD)
104+
VARIANT="${{ inputs.build_variant }}"
105+
106+
# Extract flavor and build type from variant (e.g. qaRelease -> qa / release)
107+
FLAVOR=$(echo "$VARIANT" | sed -E 's/(Release|Debug)//' | tr '[:upper:]' '[:lower:]')
108+
BUILD_TYPE=$(echo "$VARIANT" | grep -qi debug && echo debug || echo release)
109+
NAME="ownCloud-${{ inputs.build_variant }}-${COMMIT}-${DATE}.apk"
110+
111+
APK_PATH=./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/ownCloud*.apk
112+
113+
# Copy to root for an easier handling
114+
cp "$APK_PATH" "./$NAME"
115+
116+
# Publish as output
117+
echo "artifact-name=$NAME" >> $GITHUB_OUTPUT
118+
ls -al .
119+
120+
# Publish the artifact
121+
- name: Upload artifact
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: ${{ steps.set-outputs.outputs.artifact-name }}
125+
path: ./${{ steps.set-outputs.outputs.artifact-name }}

0 commit comments

Comments
 (0)