Repository navigation
98 lines (83 loc) · 3.18 KB
/
Copy pathandroid.yml
File metadata and controls
98 lines (83 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Android CI
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
# Needed for the tag build to create a GitHub Release; the default token is
# read-only for contents.
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Unit tests
run: ./gradlew testDebugUnitTest --no-daemon
- name: Build debug APK
run: ./gradlew assembleDebug --no-daemon
# Obtainium tracks releases by signature, so an unsigned release APK is
# useless for distribution. Signing is optional for CI on branches.
- name: Prepare signing key
id: signing
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
run: |
if [ -n "$KEYSTORE_BASE64" ]; then
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.jks"
echo "NETSWITCHER_KEYSTORE=$RUNNER_TEMP/release.jks" >> "$GITHUB_ENV"
echo "signed=true" >> "$GITHUB_OUTPUT"
else
echo "No KEYSTORE_BASE64 secret; the release APK will be unsigned."
echo "signed=false" >> "$GITHUB_OUTPUT"
fi
- name: Build release APK
env:
NETSWITCHER_KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
NETSWITCHER_KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
NETSWITCHER_KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: ./gradlew assembleRelease --no-daemon
- name: Upload debug APK
uses: actions/upload-artifact@v7
with:
name: netswitcher-debug-${{ github.sha }}
path: app/build/outputs/apk/debug/app-debug.apk
retention-days: 30
- name: Upload release APK
uses: actions/upload-artifact@v7
with:
name: netswitcher-release-${{ github.sha }}
path: app/build/outputs/apk/release/*.apk
retention-days: 30
- name: Refuse to publish an unsigned release
if: startsWith(github.ref, 'refs/tags/v') && steps.signing.outputs.signed != 'true'
run: |
echo "::error::Tag build without signing secrets. Obtainium cannot install or"
echo "::error::update an unsigned APK. Add KEYSTORE_BASE64, KEYSTORE_PASSWORD,"
echo "::error::KEY_ALIAS and KEY_PASSWORD to the repository secrets."
exit 1
- name: Name the release asset
if: startsWith(github.ref, 'refs/tags/v')
run: |
mkdir -p release
cp app/build/outputs/apk/release/app-release.apk \
"release/netswitcher-${GITHUB_REF_NAME}.apk"
# A single APK per release keeps Obtainium's asset matching unambiguous.
- name: Publish release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v3
with:
files: release/netswitcher-${{ github.ref_name }}.apk
generate_release_notes: true