Skip to content

Commit 9bd97df

Browse files
committed
feat: add workflow that builds an app with version and variant
1 parent 834cab8 commit 9bd97df

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

.github/workflows/buildapk.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
token:
37+
description: "Security level required for external calls"
38+
required: false
39+
type: string
40+
outputs:
41+
artifact_name:
42+
description: "Generated APK artifact name"
43+
value: ${{ jobs.build_apk.outputs.artifact_name }}
44+
commit_hash:
45+
description: "Commit hash of the artifact"
46+
value: ${{ jobs.build_apk.outputs.commit_hash }}
47+
48+
permissions:
49+
contents: read
50+
51+
# NOTE:
52+
# This workflow generates an UNSIGNED APK intended for internal usage
53+
54+
jobs:
55+
56+
# Builds the requested app variant and publishes the generated APK as an artifact
57+
build_apk:
58+
name: Build APK
59+
runs-on: ubuntu-latest
60+
outputs:
61+
artifact_name: ${{ steps.set-outputs.outputs.artifact_name }}
62+
commit_hash: ${{ steps.commit.outputs.commit_hash }}
63+
64+
steps:
65+
66+
# Validate build variant (mainly for workflow_call usage)
67+
- name: Validate build variant
68+
run: |
69+
case "${{ inputs.build_variant }}" in
70+
originalDebug|originalRelease|mdmDebug|mdmRelease|qaDebug|qaRelease) ;;
71+
*) echo "Invalid build_variant: ${{ inputs.build_variant }}" && exit 1 ;;
72+
esac
73+
74+
# Checkout the repo
75+
- name: Checkout current repo
76+
uses: actions/checkout@v4
77+
with:
78+
ref: ${{ inputs.version }}
79+
token: ${{ inputs.token || github.token }}
80+
81+
# Save the app commit has in a variable to check later
82+
- name: Get commit hash
83+
run: |
84+
COMMIT_HASH=$(git rev-parse HEAD)
85+
echo "Commit hash: $COMMIT_HASH"
86+
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
87+
88+
# Set Java-JDK version
89+
- name: Setup JDK
90+
uses: actions/setup-java@v4
91+
with:
92+
distribution: 'temurin'
93+
java-version: '17'
94+
95+
# Cache gradle
96+
- name: Cache Gradle
97+
uses: actions/cache@v4
98+
with:
99+
path: |
100+
~/.gradle/caches
101+
~/.gradle/wrapper
102+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
103+
restore-keys: |
104+
${{ runner.os }}-gradle-
105+
106+
# Build the apk with the given variant
107+
- name: Build APK
108+
run: ./gradlew clean assemble${{ inputs.build_variant }}
109+
110+
# Name the out put artifact with date, commit, and variant
111+
- name: Set artifact name
112+
id: set-outputs
113+
run: |
114+
DATE=$(date +%Y%m%d_%H%M)
115+
COMMIT=$(git rev-parse --short HEAD)
116+
VARIANT="${{ inputs.build_variant }}"
117+
118+
# Extract flavor and build type from variant (e.g. qaRelease -> qa / release)
119+
FLAVOR=$(echo "$VARIANT" | sed -E 's/(Release|Debug)//' | tr '[:upper:]' '[:lower:]')
120+
BUILD_TYPE=$(echo "$VARIANT" | grep -qi debug && echo debug || echo release)
121+
NAME="ownCloud-${{ inputs.build_variant }}-${COMMIT}-${DATE}.apk"
122+
123+
APK_PATH=$(find ./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/ -name "*.apk")
124+
125+
echo $APK_PATH
126+
127+
# Verify that apk exists
128+
if [ -z "$APK_PATH" ]; then
129+
echo "❌ APK not found in ./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/"
130+
exit 1
131+
fi
132+
133+
# Copy to root for an easier handling
134+
cp "$APK_PATH" "./$NAME"
135+
136+
# Publish as output
137+
echo "artifact_name=$NAME" >> $GITHUB_OUTPUT
138+
139+
# Publish the artifact
140+
- name: Upload artifact
141+
uses: actions/upload-artifact@v4
142+
with:
143+
name: ${{ steps.set-outputs.outputs.artifact_name }}
144+
path: ./${{ steps.set-outputs.outputs.artifact_name }}

0 commit comments

Comments
 (0)