Skip to content

Commit 8e7867c

Browse files
committed
feat: refactor update test to avoid multiple executions over build latest
1 parent 4f2de2d commit 8e7867c

3 files changed

Lines changed: 135 additions & 93 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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-apk:
18+
uses: ./.github/workflows/buildsignedapk.yml
19+
with:
20+
ref: latest
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Build Signed APK
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
# Commit or tag as input parameter
7+
inputs:
8+
ref:
9+
required: true
10+
type: string
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 APKs
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: ${{ inputs.ref }}
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-${{ inputs.ref }}.apk
61+
62+
# Decode keystore from secret for signing
63+
- name: Restore keystore
64+
run: |
65+
echo "${{ secrets.TEST_KS_B64 }}" | base64 -d > ./test.keystore
66+
67+
# Align and sign the APK
68+
- name: Sign APK
69+
run: |
70+
APK_INPUT="owncloud-${{ inputs.ref }}.apk"
71+
APK_ALIGNED="owncloud-${{ inputs.ref }}-aligned.apk"
72+
APK_SIGNED="owncloudSigned-${{ inputs.ref }}.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 "Verifying signed APK..."
93+
$ANDROID_SDK_ROOT/build-tools/${{ env.BUILD_TOOLS_VERSION }}/apksigner verify --verbose "$APK_SIGNED"
94+
95+
echo "Signed APK: $APK_SIGNED"
96+
97+
# Clean up temporary files
98+
rm -f "$APK_ALIGNED"
99+
rm -f ./test.keystore
100+
101+
# Upload the signed APK as an artifact
102+
- name: Upload APK as artifact
103+
uses: actions/upload-artifact@v4
104+
with:
105+
name: owncloudSigned-${{ inputs.ref }}
106+
path: ./owncloudSigned-${{ inputs.ref }}.apk
107+
retention-days: 90

‎.github/workflows/update.yml‎

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

11125
execute_tests:
11226
# Job to run tests using the APKs built in previous job
@@ -127,10 +41,11 @@ jobs:
12741
- name: Clone tests repo
12842
run: git clone https://github.com/owncloud/android-update-testing.git .
12943

130-
# Download APK built from latest commit
131-
- name: Get apk built from latest
132-
uses: actions/download-artifact@v4
44+
# Download APK built last latest signing
45+
- name: Download latest signed APK
46+
uses: dawidd6/action-download-artifact@v3
13347
with:
48+
workflow: Build apk from latest
13449
name: owncloudSigned-latest
13550
path: ./src/test/resources
13651

@@ -221,7 +136,7 @@ jobs:
221136
if: always()
222137
run: zip -r -9 test-recording.zip video || true
223138

224-
# Upload video file
139+
# Upload video file
225140
- name: Upload Video
226141
if: always()
227142
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)