Skip to content

Commit 61eeae9

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

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

.github/workflows/buildapk.yml

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

0 commit comments

Comments
 (0)