Skip to content

Commit a37070c

Browse files
committed
refactor: refactor update test to prevent generating latest apk every push
1 parent 4f2de2d commit a37070c

File tree

2 files changed

+137
-20
lines changed

2 files changed

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

.github/workflows/update.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@ jobs:
1919
# Job to build APKs for the latest commit and the commit that triggered the workflow
2020
name: Build APKs
2121
runs-on: ubuntu-latest
22-
strategy:
23-
matrix:
24-
# Run matrix for latest commit on branch and current commit SHA
25-
commit: ["latest", "${{ github.sha }}"]
26-
22+
2723
env:
2824
BUILD_TOOLS_VERSION: "34.0.0"
2925

3026
steps:
31-
# Checkout the specific commit from matrix
27+
# Checkout the specific commit
3228
- name: Checkout specific commit
3329
uses: actions/checkout@v5
3430
with:
35-
ref: ${{ matrix.commit }}
31+
ref: ${{ github.sha }}
3632

3733
# Set up Java JDK required for Gradle
3834
- name: Set up JDK
@@ -62,19 +58,19 @@ jobs:
6258

6359
# Copy the built APK to a commit-specific name
6460
- name: Get apk
65-
run: cp owncloudApp/build/outputs/apk/qa/release/owncloud_*-qa-release*.apk owncloud-${{ matrix.commit }}.apk
61+
run: cp owncloudApp/build/outputs/apk/qa/release/owncloud_*-qa-release*.apk owncloud-${{ github.sha }}.apk
6662

6763
# Decode keystore from secret for signing
6864
- name: Restore keystore
6965
run: |
70-
echo "${{ secrets.TEST_KS_B64 }}" | base64 -d > ./test.keystore
66+
echo "${{ secrets.TEST_KS_B64 }}" | base64 --decode > ./test.keystore"
7167
7268
# Align and sign the APK
7369
- name: Sign APK
7470
run: |
75-
APK_INPUT="owncloud-${{ matrix.commit }}.apk"
76-
APK_ALIGNED="owncloud-${{ matrix.commit }}-aligned.apk"
77-
APK_SIGNED="owncloudSigned-${{ matrix.commit }}.apk"
71+
APK_INPUT="owncloud-${{ github.sha }}.apk"
72+
APK_ALIGNED="owncloud-${{ github.sha }}-aligned.apk"
73+
APK_SIGNED="owncloudSigned-${{ github.sha }}.apk"
7874
KEYSTORE="./test.keystore"
7975
KEY_ALIAS="${{ secrets.TEST_KS_ALIAS }}"
8076
KEY_PASSWORD="${{ secrets.TEST_KS_KEY }}"
@@ -87,6 +83,7 @@ jobs:
8783
echo "Signing APK..."
8884
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/apksigner sign \
8985
--ks "$KEYSTORE" \
86+
--ks-type PKCS12 \
9087
--ks-pass pass:"$KEY_PASSWORD" \
9188
--key-pass pass:"$KEY_PASSWORD" \
9289
--ks-key-alias "$KEY_ALIAS" \
@@ -103,10 +100,9 @@ jobs:
103100
- name: Upload APK as artifact
104101
uses: actions/upload-artifact@v4
105102
with:
106-
name: owncloudSigned-${{ matrix.commit }}
107-
path: ./owncloudSigned-${{ matrix.commit }}.apk
108-
# Removed after 1 day
109-
retention-days: 1
103+
name: owncloudSigned-${{ github.sha }}
104+
path: ./owncloudSigned-${{ github.sha }}.apk
105+
retention-days: 90
110106

111107
execute_tests:
112108
# Job to run tests using the APKs built in previous job
@@ -127,10 +123,11 @@ jobs:
127123
- name: Clone tests repo
128124
run: git clone https://github.com/owncloud/android-update-testing.git .
129125

130-
# Download APK built from latest commit
131-
- name: Get apk built from latest
132-
uses: actions/download-artifact@v4
126+
# Download APK built last latest signing
127+
- name: Download latest signed APK
128+
uses: dawidd6/action-download-artifact@v3
133129
with:
130+
workflow: Build apk from latest
134131
name: owncloudSigned-latest
135132
path: ./src/test/resources
136133

@@ -221,7 +218,7 @@ jobs:
221218
if: always()
222219
run: zip -r -9 test-recording.zip video || true
223220

224-
# Upload video file
221+
# Upload video file
225222
- name: Upload Video
226223
if: always()
227224
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)