-
Notifications
You must be signed in to change notification settings - Fork 3
130 lines (112 loc) · 4.35 KB
/
apk.yml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Android Release Build
on:
workflow_dispatch:
inputs:
name:
description: "Android APK Release"
default: "Android Release"
required: true
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
name: Build APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
# Load google-services.json
- name: Decode google-services.json and google maps api key and add to system env
env:
GOOGLE_MAPS_API_KEY: ${{secrets.GOOGLE_MAPS_API_KEY}}
GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
run: |
echo "$GOOGLE_SERVICES" | base64 --decode > ./app/google-services.json
MAPS_API_KEY=$(echo "$GOOGLE_MAPS_API_KEY" | base64 --decode)
echo "MAPS_API_KEY=$MAPS_API_KEY" >> $GITHUB_ENV
- name: Set permissions for google-services.json
run: chmod 644 ./app/google-services.json
# Decode the private key and certificate, then create the keystore
- name: Decode private key and certificate, create keystore
env:
SIGNING_PRIVATE_KEY: ${{ secrets.SIGNING_PRIVATE_KEY }}
SIGNING_CERTIFICATE: ${{ secrets.SIGNING_CERTIFICATE }}
run: |
# Create a temporary directory for the keystore
mkdir -p ~/.keystore
# Decode the private key and certificate from the secrets and save them as PEM files
echo "$SIGNING_PRIVATE_KEY" > ~/.keystore/private_key.pem
echo "$SIGNING_CERTIFICATE" > ~/.keystore/certificate.pem
# Create a PKCS12 keystore from the private key and certificate
openssl pkcs12 -export \
-inkey ~/.keystore/private_key.pem \
-in ~/.keystore/certificate.pem \
-out ~/.keystore/test-release.p12 \
-name testalias \
-passout pass:testpass
# Convert the PKCS12 keystore to JKS format (which Android uses)
keytool -importkeystore \
-srckeystore ~/.keystore/test-release.p12 \
-srcstorepass testpass \
-srcstoretype PKCS12 \
-destkeystore ~/.keystore/test-release.keystore \
-deststoretype JKS \
-storepass testpass \
-keypass testpass \
-alias testalias
# Set the path to the keystore as an environment variable
echo "KEYSTORE_FILE=$(readlink -f ~/.keystore/test-release.keystore)" >> $GITHUB_ENV
- name: Build APK Release with Custom Key
env:
KEYSTORE_PASSWORD: testpass
KEY_ALIAS: testalias
KEY_PASSWORD: testpass
run: |
echo "Keystore_file is: $KEYSTORE_FILE" && \
echo $(readlink -f ~/.keystore/test-release.keystore) &&
./gradlew clean assembleRelease --info
- name: Extract SHA-1 Fingerprint from Release Keystore
id: extract_sha
run: |
SHA1=$(keytool -list -v \
-keystore $KEYSTORE_FILE \
-alias testalias \
-storepass testpass | grep 'SHA1' | awk '{print $2}')
echo "SHA1=${SHA1}" >> $GITHUB_ENV
echo "SHA1 fingerprint: ${SHA1}"
- name: List APK files
run: |
find app/build/outputs/apk -type f
- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: "${{ github.event.inputs.name }}-Release-APK"
path: app/build/outputs/apk/release/*.apk
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.run_number }}
release_name: ${{ github.event.inputs.name }} (#${{ github.run_number }})
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/build/outputs/apk/release/app-release.apk
asset_name: TravelPouch-Release.apk
asset_content_type: application/vnd.android.package-archive