forked from KotatsuApp/Kotatsu
-
-
Notifications
You must be signed in to change notification settings - Fork 24
187 lines (160 loc) · 7.9 KB
/
Copy pathrelease.yml
File metadata and controls
187 lines (160 loc) · 7.9 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Release Build
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
check_version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from tag
id: tag
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
echo "Tag version: $VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=${PATCH:-0}
VERSION_CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
- name: Read AndroidManifest versions
run: |
MANIFEST=app/src/main/AndroidManifest.xml
if [ ! -f "$MANIFEST" ]; then echo "Missing $MANIFEST" && exit 1; fi
MAN_VER=$(grep -oP 'android:versionName="\K[^"]+' "$MANIFEST" | head -n1)
MAN_CODE=$(grep -oP 'android:versionCode="\K[^\"]+' "$MANIFEST" | head -n1)
echo "manifest_version=$MAN_VER" >> $GITHUB_OUTPUT
echo "manifest_version_code=$MAN_CODE" >> $GITHUB_OUTPUT
echo "AndroidManifest: $MAN_VER ($MAN_CODE)"
- name: Read build.gradle defaults
run: |
FILE=app/build.gradle
if [ ! -f "$FILE" ]; then echo "Missing $FILE" && exit 1; fi
GRADLE_VER=$(grep -oP "versionName project.hasProperty\\('versionName'\\) \\? project.property\\('versionName'\\) : '\\K[^']+" "$FILE" | head -n1 || true)
GRADLE_CODE=$(grep -oP "versionCode project.hasProperty\\('versionCode'\\) \\? project.property\\('versionCode'\\).toInteger\\(\\) : \\K[0-9]+" "$FILE" | head -n1 || true)
echo "gradle_version=$GRADLE_VER" >> $GITHUB_OUTPUT
echo "gradle_version_code=$GRADLE_CODE" >> $GITHUB_OUTPUT
echo "build.gradle defaults: $GRADLE_VER ($GRADLE_CODE)"
- name: Compare tag with files
run: |
set -e
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=${PATCH:-0}
EXPECTED_CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
MAN_VER=$(grep -oP 'android:versionName="\K[^"]+' app/src/main/AndroidManifest.xml | head -n1)
MAN_CODE=$(grep -oP 'android:versionCode="\K[^\"]+' app/src/main/AndroidManifest.xml | head -n1)
GRADLE_VER=$(grep -oP "versionName project.hasProperty\\('versionName'\\) \\? project.property\\('versionName'\\) : '\\K[^']+" app/build.gradle | head -n1 || true)
GRADLE_CODE=$(grep -oP "versionCode project.hasProperty\\('versionCode'\\) \\? project.property\\('versionCode'\\).toInteger\\(\\) : \\K[0-9]+" app/build.gradle | head -n1 || true)
echo "Tag: $VERSION ($EXPECTED_CODE)"
echo "AndroidManifest: $MAN_VER ($MAN_CODE)"
echo "build.gradle: $GRADLE_VER ($GRADLE_CODE)"
if [ "$MAN_VER" != "$VERSION" ]; then echo "ERROR: AndroidManifest versionName ($MAN_VER) does not match tag ($VERSION)" && exit 1; fi
if [ "$GRADLE_VER" != "$VERSION" ]; then echo "ERROR: app/build.gradle default versionName ($GRADLE_VER) does not match tag ($VERSION)" && exit 1; fi
if [ "$MAN_CODE" != "$EXPECTED_CODE" ]; then echo "ERROR: AndroidManifest versionCode ($MAN_CODE) does not match expected ($EXPECTED_CODE)" && exit 1; fi
if [ "$GRADLE_CODE" != "$EXPECTED_CODE" ]; then echo "ERROR: app/build.gradle default versionCode ($GRADLE_CODE) does not match expected ($EXPECTED_CODE)" && exit 1; fi
echo "Version check passed."
build:
needs: check_version
runs-on: ubuntu-latest
steps:
- name: Notify Discord - Build Started
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Build started for ${{ github.ref_name }}" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Notify Discord - Environment Setup Complete
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Environment setup complete (Java 17, Android SDK)" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true
- name: Get version from tag
id: version
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Extract major.minor.patch and calculate version code
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=${PATCH:-0}
VERSION_CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
- name: Decode keystore
run: |
echo "${{ secrets.KEYSTORE_FILE }}" | base64 -d > keystore.jks
- name: Notify Discord - Keystore Decoded
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Keystore decoded" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true
- name: Build release APK
env:
KEYSTORE_FILE: ${{ github.workspace }}/keystore.jks
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
./gradlew assembleRelease \
-PversionName=${{ steps.version.outputs.version }} \
-PversionCode=${{ steps.version.outputs.version_code }} \
--no-build-cache --no-configuration-cache
- name: Notify Discord - APK Build Complete
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Release APK build complete" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Futon ${{ steps.version.outputs.version }}
draft: false
prerelease: false
files: |
app/build/outputs/apk/release/app-release.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify Discord - Release Published
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
RELEASE_URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Release published: ${{ github.ref_name }}\n$RELEASE_URL" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true
- name: Clean up keystore
if: always()
run: rm -f keystore.jks
- name: Notify Discord - Build Failed
if: failure()
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_BUILD }}
run: |
if [ -z "$WEBHOOK" ]; then exit 0; fi
payload=$(jq -n --arg content "Build failed for ${{ github.ref_name }}\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" '{content: $content}')
curl -s -H "Content-Type: application/json" -d "$payload" "$WEBHOOK" || true