Skip to content

Commit f59a6fb

Browse files
committed
feature: workflow to build apk from latest, only in specific moments
1 parent 5e9893a commit f59a6fb

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Build apk from latest
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- latest
8+
schedule:
9+
# Runs on the 1st day of every 2 months at 00:00 UTC
10+
- cron: "0 0 1 */2 *"
11+
12+
permissions:
13+
# Only need read access to repository contents
14+
contents: read
15+
16+
jobs:
17+
build_apks:
18+
# Job to build APKs for the latest commit and the commit that triggered the workflow
19+
name: Build Signed APK
20+
runs-on: ubuntu-latest
21+
22+
env:
23+
BUILD_TOOLS_VERSION: "34.0.0"
24+
25+
steps:
26+
# Checkout the specific commit
27+
- name: Checkout specific commit
28+
uses: actions/checkout@v5
29+
with:
30+
ref: latest
31+
32+
# Set up Java JDK required for Gradle
33+
- name: Set up JDK
34+
uses: actions/setup-java@v5
35+
with:
36+
distribution: temurin
37+
java-version: '17'
38+
39+
# Set up Android SDK and build tools
40+
- name: Set up Android SDK
41+
uses: android-actions/setup-android@v2
42+
43+
# Cache Gradle dependencies to speed up builds
44+
- name: Cache Gradle
45+
uses: actions/cache@v4
46+
with:
47+
path: |
48+
~/.gradle/caches
49+
~/.gradle/wrapper
50+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
51+
restore-keys: |
52+
${{ runner.os }}-gradle-
53+
54+
# Build the APK
55+
- name: Build APK
56+
run: ./gradlew assembleqaRelease --no-daemon --stacktrace --info
57+
58+
# Copy the built APK to a commit-specific name
59+
- name: Get apk
60+
run: cp owncloudApp/build/outputs/apk/qa/release/owncloud_*-qa-release*.apk owncloud-latest.apk
61+
62+
# Decode keystore from secret for signing
63+
- name: Restore keystore
64+
run: |
65+
echo "${{ secrets.TEST_KS_B64 }}" | base64 --decode > ./test.keystore
66+
67+
# Align and sign the APK
68+
- name: Sign APK
69+
run: |
70+
APK_INPUT="owncloud-latest.apk"
71+
APK_ALIGNED="owncloud-latest-aligned.apk"
72+
APK_SIGNED="owncloudSigned-latest.apk"
73+
KEYSTORE="./test.keystore"
74+
KEY_ALIAS="${{ secrets.TEST_KS_ALIAS }}"
75+
KEY_PASSWORD="${{ secrets.TEST_KS_KEY }}"
76+
77+
# Align APK for optimal performance
78+
echo "Aligning APK..."
79+
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/zipalign -v -p 4 "$APK_INPUT" "$APK_ALIGNED"
80+
81+
# Sign APK using keystore
82+
echo "Signing APK..."
83+
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/apksigner sign \
84+
--ks "$KEYSTORE" \
85+
--ks-type PKCS12 \
86+
--ks-pass pass:"$KEY_PASSWORD" \
87+
--key-pass pass:"$KEY_PASSWORD" \
88+
--ks-key-alias "$KEY_ALIAS" \
89+
--out "$APK_SIGNED" \
90+
"$APK_ALIGNED"
91+
92+
echo "Signed APK: $APK_SIGNED"
93+
94+
# Clean up temporary files
95+
rm -f "$APK_ALIGNED"
96+
rm -f ./test.keystore
97+
98+
# Upload the signed APK as an artifact
99+
- name: Upload APK as artifact
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: owncloudSigned-latest
103+
path: ./owncloudSigned-latest.apk
104+
retention-days: 90
105+

0 commit comments

Comments
 (0)