Skip to content

Commit 1e13ce6

Browse files
authored
ci: automate release orchestration for desktop and mobile (#4861)
1 parent d386c00 commit 1e13ce6

File tree

6 files changed

+197
-50
lines changed

6 files changed

+197
-50
lines changed

.github/scripts/extract-release-info.mjs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const RELEASE_PATTERNS = {
1616

1717
const EXIT_CODES = {
1818
SUCCESS: 0,
19-
NO_RELEASE_FOUND: 1,
2019
GIT_ERROR: 2,
2120
ENV_ERROR: 3,
21+
OUTPUT_ERROR: 4,
2222
}
2323

2424
/**
@@ -38,6 +38,23 @@ function setGitHubEnv(key, value) {
3838
}
3939
}
4040

41+
/**
42+
* Write output variable to GitHub Output
43+
* @param {string} key - Output key
44+
* @param {string} value - Output value
45+
*/
46+
function setGitHubOutput(key, value) {
47+
try {
48+
if (!process.env.GITHUB_OUTPUT) {
49+
return
50+
}
51+
appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`)
52+
} catch (error) {
53+
console.error(`Failed to set output variable ${key}:`, error.message)
54+
process.exit(EXIT_CODES.OUTPUT_ERROR)
55+
}
56+
}
57+
4158
/**
4259
* Get the latest commit message
4360
* @returns {string} Latest commit message
@@ -88,7 +105,7 @@ function main() {
88105

89106
if (!releaseInfo) {
90107
console.info("No desktop or mobile release found in commit message.")
91-
process.exit(EXIT_CODES.NO_RELEASE_FOUND)
108+
process.exit(EXIT_CODES.SUCCESS)
92109
}
93110

94111
const { platform, version, tagName } = releaseInfo
@@ -97,6 +114,9 @@ function main() {
97114
setGitHubEnv("tag_version", tagName)
98115
setGitHubEnv("platform", platform)
99116
setGitHubEnv("version", version)
117+
setGitHubOutput("tag_version", tagName)
118+
setGitHubOutput("platform", platform)
119+
setGitHubOutput("version", version)
100120

101121
console.info(`Found ${platform} release: ${version}`)
102122
console.info(`Tag will be created: ${tagName}`)

.github/workflows/build-android.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ concurrency:
2828
jobs:
2929
build:
3030
name: Build Android apk for device
31-
if: github.secret_source != 'None'
31+
if: github.secret_source != 'None' && (github.event_name != 'push' || !startsWith(github.event.head_commit.message || '', 'release(mobile):'))
3232
runs-on: ubuntu-latest
3333

3434
steps:
@@ -104,13 +104,34 @@ jobs:
104104
with:
105105
type: "mobile"
106106

107+
- name: Prepare Release Notes
108+
if: github.event.inputs.release == 'true'
109+
id: release_notes
110+
run: |
111+
version="${{ steps.version.outputs.APP_VERSION }}"
112+
changelog_file="apps/mobile/changelog/${version}.md"
113+
release_notes_file="$RUNNER_TEMP/mobile-release-notes.md"
114+
115+
if [ -f "$changelog_file" ]; then
116+
cp "$changelog_file" "$release_notes_file"
117+
else
118+
{
119+
echo "# What's New in v${version}"
120+
echo
121+
echo "- No changelog file found at ${changelog_file}."
122+
} > "$release_notes_file"
123+
fi
124+
125+
echo "body_path=${release_notes_file}" >> "$GITHUB_OUTPUT"
126+
107127
- name: Create Release Draft
108128
if: github.event.inputs.release == 'true'
109129
uses: softprops/action-gh-release@v2
110130
with:
111131
name: Mobile v${{ steps.version.outputs.APP_VERSION }}
112-
draft: false
132+
draft: true
113133
prerelease: true
114134
tag_name: mobile/v${{ steps.version.outputs.APP_VERSION }}
135+
body_path: ${{ steps.release_notes.outputs.body_path }}
115136
# .aab cannot be installed directly on your Android Emulator or device.
116137
files: ${{ github.workspace }}/build.apk

.github/workflows/build-desktop.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env:
3737

3838
jobs:
3939
release:
40+
if: github.secret_source != 'None' && (github.event_name != 'push' || !startsWith(github.event.head_commit.message || '', 'release(desktop):'))
4041
runs-on: ${{ matrix.os }}
4142
env:
4243
PROD: ${{ github.event.inputs.tag_version == 'true' || github.ref_type == 'tag' || github.event.inputs.store == 'true' }}
@@ -293,6 +294,26 @@ jobs:
293294
with:
294295
type: "desktop"
295296

297+
- name: Prepare Release Notes
298+
if: env.RELEASE == 'true'
299+
id: release_notes
300+
run: |
301+
version="${{ steps.version.outputs.APP_VERSION }}"
302+
changelog_file="apps/desktop/changelog/${version}.md"
303+
release_notes_file="$RUNNER_TEMP/desktop-release-notes.md"
304+
305+
if [ -f "$changelog_file" ]; then
306+
cp "$changelog_file" "$release_notes_file"
307+
else
308+
{
309+
echo "# What's New in v${version}"
310+
echo
311+
echo "- No changelog file found at ${changelog_file}."
312+
} > "$release_notes_file"
313+
fi
314+
315+
echo "body_path=${release_notes_file}" >> "$GITHUB_OUTPUT"
316+
296317
- name: Create Release Draft
297318
if: env.RELEASE == 'true'
298319
uses: softprops/action-gh-release@v2
@@ -301,6 +322,7 @@ jobs:
301322
draft: false
302323
prerelease: true
303324
tag_name: desktop/v${{ steps.version.outputs.APP_VERSION }}
325+
body_path: ${{ steps.release_notes.outputs.body_path }}
304326
files: |
305327
apps/desktop/out/make/**/Folo-*.dmg
306328
apps/desktop/out/make/**/Folo-*.zip

.github/workflows/build-ios.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ concurrency:
2323

2424
jobs:
2525
check-runner:
26+
if: github.secret_source != 'None' && (github.event_name != 'push' || !startsWith(github.event.head_commit.message || '', 'release(mobile):'))
2627
runs-on: ubuntu-latest
2728
outputs:
2829
runner-label: ${{ steps.set-runner.outputs.runner-label }}
@@ -41,7 +42,7 @@ jobs:
4142
4243
build-ipa-self-hosted:
4344
name: Build iOS IPA (self-hosted)
44-
if: github.secret_source != 'None' && needs.check-runner.outputs.runner-label == 'self-hosted'
45+
if: needs.check-runner.outputs.runner-label == 'self-hosted'
4546
needs: check-runner
4647
runs-on: [self-hosted, macOS]
4748

@@ -84,7 +85,7 @@ jobs:
8485

8586
build-ipa-github:
8687
name: Build iOS IPA (GitHub)
87-
if: github.secret_source != 'None' && needs.check-runner.outputs.runner-label == 'macos-latest'
88+
if: needs.check-runner.outputs.runner-label == 'macos-latest'
8889
needs: check-runner
8990
runs-on: macos-latest
9091

.github/workflows/sync.yaml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
name: 🔄 Branch Synchronization
1+
name: 🔄 Sync Release Branches To Dev
22

33
on:
44
push:
55
branches:
66
- main
7+
- mobile-main
8+
9+
permissions:
10+
contents: write
711

812
jobs:
9-
sync-branches:
13+
sync-to-dev:
1014
runs-on: ubuntu-latest
15+
if: |
16+
(github.ref == 'refs/heads/main' && startsWith(github.event.head_commit.message, 'release(desktop):')) ||
17+
(github.ref == 'refs/heads/mobile-main' && startsWith(github.event.head_commit.message, 'release(mobile):'))
1118
steps:
1219
- name: Checkout repository
1320
uses: actions/checkout@v6
@@ -16,27 +23,13 @@ jobs:
1623

1724
- name: Set up Git
1825
run: |
19-
git config --global user.name 'GitHub Actions'
20-
git config --global user.email 'actions@github.com'
21-
22-
- name: Prepare sync branch
23-
id: branch
24-
run: |
25-
echo "SYNC_BRANCH_MAIN_DEV=sync/main-to-dev-$(date +'%Y%m%d')" >> $GITHUB_ENV
26+
git config --global user.name "github-actions[bot]"
27+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2628
27-
- name: Sync main to dev
28-
if: github.ref == 'refs/heads/main'
29+
- name: Merge source branch into dev
2930
run: |
30-
# Sync main to dev
31-
git checkout main
32-
SYNC_BRANCH_DEV=${{ env.SYNC_BRANCH_MAIN_DEV }}
33-
git checkout -B $SYNC_BRANCH_DEV
34-
DIFF=$(git diff origin/dev...)
35-
if [ -z "$DIFF" ]; then
36-
echo "No changes to sync"
37-
exit 0
38-
fi
39-
git push origin $SYNC_BRANCH_DEV -f
40-
gh pr create --base dev --head $SYNC_BRANCH_DEV --title "Sync main branch to dev branch" --body "Automatic sync" || exit 0
41-
env:
42-
GH_TOKEN: ${{ github.token }}
31+
source_branch="${GITHUB_REF_NAME}"
32+
git fetch origin main mobile-main dev
33+
git checkout dev
34+
git merge --no-ff "origin/${source_branch}" -m "chore(sync): merge ${source_branch} into dev"
35+
git push origin dev

0 commit comments

Comments
 (0)