-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (129 loc) · 4.89 KB
/
apk-builder.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: APK Builder
on:
workflow_dispatch:
inputs:
tag_name:
required: true
type: string
description: "Version tag for this release (e.g., v0.1.0)"
default: "v0.1.0"
build_type:
required: true
type: choice
description: "Select the build type (debug or release)"
options:
- debug
- release
default: debug
permissions:
contents: write
jobs:
build:
name: Build APK
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Set up the Java Development Kit
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# Load google-services.json from GitHub Secrets
- name: Load Google Services configuration
env:
DATA: ${{ secrets.GOOGLE_SERVICES }}
run: echo "$DATA" | base64 -d > app/google-services.json
# Load and decode Google Maps API Key into local.properties
- name: Load and Decode Google Maps API Key
env:
DATA: ${{ secrets.LOCAL_PROPERTIES }}
run: |
echo "$DATA" | base64 -d | grep "MAPS_API_KEY" >> local.properties
# Load the Perspective API Key from GitHub Secrets
- name: Load Perspective API Key
env:
PERSPECTIVE_API_KEY: ${{ secrets.PERSPECTIVE_API_KEY }}
run: |
echo "::add-mask::$PERSPECTIVE_API_KEY"
echo "PERSPECTIVE_API_KEY=${PERSPECTIVE_API_KEY}" >> local.properties
# Load the DigitalOcean S3 Access Key from GitHub Secrets
- name: Load DigitalOcean S3 Access Key
env:
DIGITAL_OCEAN_SPACE_ACCESS_KEY: ${{ secrets.DIGITAL_OCEAN_SPACE_ACCESS_KEY }}
run: |
echo "::add-mask::DIGITAL_OCEAN_SPACE_ACCESS_KEY"
echo "DIGITAL_OCEAN_SPACE_ACCESS_KEY=${DIGITAL_OCEAN_SPACE_ACCESS_KEY}" >> local.properties
# Load the DigitalOcean S3 Secret Key from GitHub Secrets
- name: Load DigitalOcean S3 Secret Key
env:
DIGITAL_OCEAN_SPACE_SECRET_KEY: ${{ secrets.DIGITAL_OCEAN_SPACE_SECRET_KEY }}
run: |
echo "::add-mask::DIGITAL_OCEAN_SPACE_SECRET_KEY"
echo "DIGITAL_OCEAN_SPACE_SECRET_KEY=${DIGITAL_OCEAN_SPACE_SECRET_KEY}" >> local.properties
# Load the keystore (.jks) file from GitHub Secrets
- name: Load Keystore file
env:
DATA: ${{ secrets.KEYSTORE_BASE64 }}
run: echo "$DATA" | base64 -d > keystore.jks
# Set environment variables for keystore passwords
- name: Set Keystore Environment Variables
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
echo "::add-mask::$KEYSTORE_PASSWORD"
echo "::add-mask::$KEYSTORE_ALIAS"
echo "::add-mask::$KEY_PASSWORD"
# Grant execute permission for Gradle wrapper
- name: Make gradlew executable
run: chmod +x ./gradlew
# Build APK with appropriate configuration and detailed logs
- name: Build APK with logs
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
if [ "${{ inputs.build_type }}" == "release" ]; then
./gradlew assembleRelease
else
./gradlew assembleDebug
fi
# Locate and list the generated APK files
- name: Find and list APK files
id: apkpath
run: |
if [ "${{ inputs.build_type }}" == "release" ]; then
find app/build/outputs/apk/release/ -name "*.apk" -exec ls -lh {} \;
echo "apk_path=$(find app/build/outputs/apk/release/*.apk)" >> $GITHUB_ENV
else
find app/build/outputs/apk/debug/ -name "*.apk" -exec ls -lh {} \;
echo "apk_path=$(find app/build/outputs/apk/debug/*.apk)" >> $GITHUB_ENV
fi
# Create a Git tag for the release
- name: Create Git Tag
id: tag
run: |
git tag ${{ inputs.tag_name }}
git push origin ${{ inputs.tag_name }}
# Upload the generated APK as a build artifact
- name: Upload APK to GitHub Artifacts
uses: actions/upload-artifact@v4
with:
name: streetworkapp-${{ inputs.build_type }}
path: ${{ env.apk_path }}
retention-days: 90
# Release the APK on GitHub with the specified tag
- name: Publish Release on GitHub
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ inputs.tag_name }}
files: ${{ env.apk_path }}
draft: false
token: ${{ secrets.GITHUB_TOKEN }}