Skip to content

Commit 2d4e507

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

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

.github/workflows/buildapk.yml

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

0 commit comments

Comments
 (0)