Skip to content

Commit 6f1334d

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

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+
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+
ref: master
76+
77+
# Set Java-JDK version
78+
- name: Setup JDK
79+
uses: actions/setup-java@v4
80+
with:
81+
distribution: 'temurin'
82+
java-version: '17'
83+
84+
# Cache gradle
85+
- name: Cache Gradle
86+
uses: actions/cache@v4
87+
with:
88+
path: |
89+
~/.gradle/caches
90+
~/.gradle/wrapper
91+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
92+
restore-keys: |
93+
${{ runner.os }}-gradle-
94+
95+
# Build the apk with the given variant
96+
- name: Build APK
97+
# run: ./gradlew clean assemble${{ inputs.build_variant }}
98+
run: ./gradlew clean assembleqaRelease
99+
100+
# Name the out put artifact with date, commit, and variant
101+
- name: Set artifact name
102+
id: set-outputs
103+
run: |
104+
DATE=$(date +%Y%m%d_%H%M)
105+
COMMIT=$(git rev-parse --short HEAD)
106+
#VARIANT="${{ inputs.build_variant }}"
107+
VARIANT=qaRelease
108+
109+
# Extract flavor and build type from variant (e.g. qaRelease -> qa / release)
110+
FLAVOR=$(echo "$VARIANT" | sed -E 's/(Release|Debug)//' | tr '[:upper:]' '[:lower:]')
111+
BUILD_TYPE=$(echo "$VARIANT" | grep -qi debug && echo debug || echo release)
112+
#NAME="ownCloud-${{ inputs.build_variant }}-${COMMIT}-${DATE}.apk"
113+
NAME="ownCloud-qaRelease-${COMMIT}-${DATE}.apk"
114+
115+
echo $FLAVOR
116+
echo $BUILD_TYPE
117+
echo $NAME
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+
ls -al .
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)