-
-
Notifications
You must be signed in to change notification settings - Fork 2
366 lines (319 loc) · 11.7 KB
/
release-on-tag.yml
File metadata and controls
366 lines (319 loc) · 11.7 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
name: GitHub Release (gms + foss)
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to build/release"
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
# ── Resolve tag and version metadata (fast, shared by all jobs) ──
meta:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.rel.outputs.tag }}
sha: ${{ steps.rel.outputs.sha }}
ref: ${{ steps.ref.outputs.ref }}
app_version: ${{ steps.ver.outputs.app_version }}
build_number: ${{ steps.ver.outputs.build_number }}
full_version: ${{ steps.ver.outputs.full_version }}
prerelease: ${{ steps.pre.outputs.prerelease }}
steps:
- name: Resolve ref (tag)
id: ref
shell: bash
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ref=refs/tags/${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.ref }}" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.ref.outputs.ref }}
- name: Resolve release metadata
id: rel
shell: bash
run: |
set -euo pipefail
TAG=""
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Read version from tag
id: ver
shell: bash
run: |
TAG="${{ steps.rel.outputs.tag }}"
SEMVER="${TAG#v}"
APP_VERSION="${SEMVER%%-*}"
BUILD_NUMBER="$(git rev-list --count HEAD)"
echo "app_version=$APP_VERSION" >> "$GITHUB_OUTPUT"
echo "build_number=$BUILD_NUMBER" >> "$GITHUB_OUTPUT"
echo "full_version=$SEMVER" >> "$GITHUB_OUTPUT"
- name: Determine prerelease flag
id: pre
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.rel.outputs.tag }}"
if [[ "$TAG" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
# ── GMS APK build ──
build-gms:
needs: meta
runs-on: ubuntu-latest
env:
JAVA_VERSION: "21"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.ref }}
- name: Setup Flutter (from .flutter-version)
uses: subosito/flutter-action@v2
with:
flutter-version-file: .flutter-version
channel: stable
cache: true
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Write android/local.properties
shell: bash
run: |
set -e
SDK_DIR="${ANDROID_SDK_ROOT:-$ANDROID_HOME}"
FLUTTER_SDK="${FLUTTER_HOME:-$(dirname "$(dirname "$(readlink -f "$(which flutter)")")")}"
{
echo "sdk.dir=${SDK_DIR}"
echo "flutter.sdk=${FLUTTER_SDK}"
} > android/local.properties
- name: Make gradlew executable
run: chmod +x android/gradlew
- name: Decode keystore
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/dawarich-upload.jks
- name: Create keystore.properties
run: |
cat > android/keystore.properties <<'EOF'
storePassword=${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}
keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}
storeFile=../dawarich-upload.jks
EOF
- name: Flutter pub get
run: flutter pub get
- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs
- name: Build APK (GMS)
shell: bash
run: |
set -euo pipefail
flutter build apk --release --flavor gms \
--build-name=${{ needs.meta.outputs.app_version }} \
--build-number=${{ needs.meta.outputs.build_number }}
- name: Upload GMS artifact
uses: actions/upload-artifact@v4
with:
name: gms-apk
path: build/app/outputs/flutter-apk/app-gms-release.apk
retention-days: 5
# ── FOSS APK build (parallel to GMS) ──
build-foss:
needs: meta
runs-on: ubuntu-latest
env:
JAVA_VERSION: "21"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.ref }}
- name: Setup Flutter (from .flutter-version)
uses: subosito/flutter-action@v2
with:
flutter-version-file: .flutter-version
channel: stable
cache: true
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Write android/local.properties
shell: bash
run: |
set -e
SDK_DIR="${ANDROID_SDK_ROOT:-$ANDROID_HOME}"
FLUTTER_SDK="${FLUTTER_HOME:-$(dirname "$(dirname "$(readlink -f "$(which flutter)")")")}"
{
echo "sdk.dir=${SDK_DIR}"
echo "flutter.sdk=${FLUTTER_SDK}"
} > android/local.properties
- name: Make gradlew executable
run: chmod +x android/gradlew
- name: Decode keystore
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/dawarich-upload.jks
- name: Create keystore.properties
run: |
cat > android/keystore.properties <<'EOF'
storePassword=${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}
keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}
storeFile=../dawarich-upload.jks
EOF
- name: Switch pubspec to FOSS
shell: bash
run: |
set -euo pipefail
cp pubspec-foss.yaml pubspec.yaml
cp pubspec-foss.lock pubspec.lock
- name: Flutter pub get
run: flutter pub get
- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs
- name: FOSS proprietary dependency check
shell: bash
run: |
chmod +x tools/check_proprietary_deps.sh
tools/check_proprietary_deps.sh fossReleaseRuntimeClasspath
- name: Build APK (FOSS)
shell: bash
run: |
set -euo pipefail
flutter build apk --release --flavor foss \
--build-name=${{ needs.meta.outputs.app_version }} \
--build-number=${{ needs.meta.outputs.build_number }}
- name: Upload FOSS artifact
uses: actions/upload-artifact@v4
with:
name: foss-apk
path: build/app/outputs/flutter-apk/app-foss-release.apk
retention-days: 5
# ── Create GitHub Release (waits for both builds) ──
release:
needs: [meta, build-gms, build-foss]
runs-on: ubuntu-latest
steps:
- name: Download GMS artifact
uses: actions/download-artifact@v4
with:
name: gms-apk
path: dist
- name: Download FOSS artifact
uses: actions/download-artifact@v4
with:
name: foss-apk
path: dist
- name: Rename artifacts
shell: bash
run: |
set -euo pipefail
VER="${{ needs.meta.outputs.app_version }}"
BN="${{ needs.meta.outputs.build_number }}"
mv dist/app-gms-release.apk "dist/dawarich-${VER}+${BN}-gms.apk"
mv dist/app-foss-release.apk "dist/dawarich-${VER}+${BN}-foss.apk"
ls -la dist
- name: Create GitHub Release and upload assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.meta.outputs.tag }}
target_commitish: ${{ needs.meta.outputs.sha }}
files: dist/*
generate_release_notes: false
fail_on_unmatched_files: true
prerelease: ${{ needs.meta.outputs.prerelease }}
# ── F-Droid changelog (non-blocking, runs after meta, independent of release) ──
changelog:
needs: meta
runs-on: ubuntu-latest
# This job must never block the release
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.ref }}
- name: Generate and push F-Droid changelog via PR
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
BUILD_NUMBER="${{ needs.meta.outputs.build_number }}"
TAG="${{ needs.meta.outputs.tag }}"
CHANGELOG_DIR="fastlane/metadata/android/en-US/changelogs"
CHANGELOG="${CHANGELOG_DIR}/${BUILD_NUMBER}.txt"
WHATSNEW="distribution/whatsnew/whatsnew-en-US"
BRANCH="chore/fdroid-changelog-${BUILD_NUMBER}"
# Generate the changelog file
mkdir -p "$CHANGELOG_DIR"
if [ -f "$WHATSNEW" ]; then
cp "$WHATSNEW" "$CHANGELOG"
else
echo "See https://github.com/sunstep/dawarich-android/releases/tag/${TAG}" \
> "$CHANGELOG"
fi
# Skip if the file already exists on main
git fetch origin main
if git show "origin/main:${CHANGELOG}" &>/dev/null; then
echo "Changelog ${BUILD_NUMBER}.txt already exists on main, skipping."
exit 0
fi
# Save to temp before switching branches
cp "$CHANGELOG" /tmp/changelog.txt
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create a new branch from main, add the file, force-push, open PR
# Force-push handles retries where the branch already exists from a previous failed run
git checkout -b "$BRANCH" origin/main
mkdir -p "$(dirname "$CHANGELOG")"
cp /tmp/changelog.txt "$CHANGELOG"
git add "$CHANGELOG"
git commit -m "chore: add F-Droid changelog for build ${BUILD_NUMBER} [skip ci]"
git push --force origin "$BRANCH"
# Only create a PR if one doesn't already exist for this branch
EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number // empty')
if [ -n "$EXISTING_PR" ]; then
echo "PR #${EXISTING_PR} already exists for branch ${BRANCH}, skipping creation."
PR_NUMBER="$EXISTING_PR"
else
PR_URL=$(gh pr create \
--base main \
--head "$BRANCH" \
--title "chore: F-Droid changelog for ${TAG}" \
--body "Auto-generated F-Droid changelog for build ${BUILD_NUMBER} (${TAG})." \
--label "automated")
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
echo "Created PR #${PR_NUMBER}"
fi
# Merge the PR: try auto-merge first, fall back to immediate merge if PR is already clean
if ! gh pr merge "$PR_NUMBER" --auto --squash 2>/dev/null; then
echo "Auto-merge unavailable (PR may already be clean). Merging immediately."
gh pr merge "$PR_NUMBER" --squash
fi