Skip to content

Commit 1eecbf1

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

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

.github/workflows/buildapk.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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+
commit_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+
run: |
80+
COMMIT_HASH=$(git rev-parse HEAD)
81+
echo "Commit hash: $COMMIT_HASH"
82+
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
83+
84+
# Set Java-JDK version
85+
- name: Setup JDK
86+
uses: actions/setup-java@v4
87+
with:
88+
distribution: 'temurin'
89+
java-version: '17'
90+
91+
# Cache gradle
92+
- name: Cache Gradle
93+
uses: actions/cache@v4
94+
with:
95+
path: |
96+
~/.gradle/caches
97+
~/.gradle/wrapper
98+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
99+
restore-keys: |
100+
${{ runner.os }}-gradle-
101+
102+
# Build the apk with the given variant
103+
- name: Build APK
104+
run: ./gradlew clean assemble${{ inputs.build_variant }}
105+
106+
# Name the out put artifact with date, commit, and variant
107+
- name: Set artifact name
108+
id: set-outputs
109+
run: |
110+
DATE=$(date +%Y%m%d_%H%M)
111+
COMMIT=$(git rev-parse --short HEAD)
112+
VARIANT="${{ inputs.build_variant }}"
113+
114+
# Extract flavor and build type from variant (e.g. qaRelease -> qa / release)
115+
FLAVOR=$(echo "$VARIANT" | sed -E 's/(Release|Debug)//' | tr '[:upper:]' '[:lower:]')
116+
BUILD_TYPE=$(echo "$VARIANT" | grep -qi debug && echo debug || echo release)
117+
NAME="ownCloud-${{ inputs.build_variant }}-${COMMIT}-${DATE}.apk"
118+
119+
APK_PATH=$(find ./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/ -name "*.apk")
120+
121+
echo $APK_PATH
122+
123+
# Verify that apk exists
124+
if [ -z "$APK_PATH" ]; then
125+
echo "❌ APK not found in ./owncloudApp/build/outputs/apk/$FLAVOR/$BUILD_TYPE/"
126+
exit 1
127+
fi
128+
129+
# Copy to root for an easier handling
130+
cp "$APK_PATH" "./$NAME"
131+
132+
# Publish as output
133+
echo "artifact_name=$NAME" >> $GITHUB_OUTPUT
134+
135+
# Publish the artifact
136+
- name: Upload artifact
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: ${{ steps.set-outputs.outputs.artifact_name }}
140+
path: ./${{ steps.set-outputs.outputs.artifact_name }}

0 commit comments

Comments
 (0)