Skip to content

Commit e0e1a58

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

File tree

2 files changed

+124
-20
lines changed

2 files changed

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

.github/workflows/update.yml

Lines changed: 18 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,11 +123,13 @@ 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
132+
branch: feature/improve_update_test
135133
path: ./src/test/resources
136134

137135
# Download APK built from current commit
@@ -221,7 +219,7 @@ jobs:
221219
if: always()
222220
run: zip -r -9 test-recording.zip video || true
223221

224-
# Upload video file
222+
# Upload video file
225223
- name: Upload Video
226224
if: always()
227225
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)