Skip to content

Commit 15517fa

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

File tree

2 files changed

+139
-20
lines changed

2 files changed

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