Skip to content

Commit 2c825c0

Browse files
Pin release notes to prior channel tag
- Resolve previous stable or nightly tag before publishing - Use it for GitHub release notes and document the release flow
1 parent 5042785 commit 2c825c0

3 files changed

Lines changed: 236 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ jobs:
3636
tag: ${{ steps.release_meta.outputs.tag }}
3737
release_name: ${{ steps.release_meta.outputs.name }}
3838
short_sha: ${{ steps.release_meta.outputs.short_sha }}
39+
previous_tag: ${{ steps.previous_tag.outputs.previous_tag }}
3940
cli_dist_tag: ${{ steps.release_meta.outputs.cli_dist_tag }}
4041
is_prerelease: ${{ steps.release_meta.outputs.is_prerelease }}
4142
make_latest: ${{ steps.release_meta.outputs.make_latest }}
4243
ref: ${{ github.sha }}
4344
steps:
4445
- name: Checkout
4546
uses: actions/checkout@v6
47+
with:
48+
fetch-depth: 0
4649

4750
- name: Setup Bun
4851
uses: oven-sh/setup-bun@v2
@@ -120,6 +123,14 @@ jobs:
120123
- name: Test
121124
run: bun run test
122125

126+
- id: previous_tag
127+
name: Resolve previous release tag
128+
run: |
129+
node scripts/resolve-previous-release-tag.ts \
130+
--channel "${{ steps.release_meta.outputs.release_channel }}" \
131+
--current-tag "${{ steps.release_meta.outputs.tag }}" \
132+
--github-output
133+
123134
build:
124135
name: Build ${{ matrix.label }}
125136
needs: preflight
@@ -337,6 +348,27 @@ jobs:
337348
done
338349
339350
- name: Publish release
351+
if: needs.preflight.outputs.previous_tag != ''
352+
uses: softprops/action-gh-release@v2
353+
with:
354+
tag_name: ${{ needs.preflight.outputs.tag }}
355+
target_commitish: ${{ needs.preflight.outputs.ref }}
356+
name: ${{ needs.preflight.outputs.release_name }}
357+
generate_release_notes: true
358+
previous_tag: ${{ needs.preflight.outputs.previous_tag }}
359+
prerelease: ${{ needs.preflight.outputs.is_prerelease }}
360+
make_latest: ${{ needs.preflight.outputs.make_latest }}
361+
files: |
362+
release-assets/*.dmg
363+
release-assets/*.zip
364+
release-assets/*.AppImage
365+
release-assets/*.exe
366+
release-assets/*.blockmap
367+
release-assets/*.yml
368+
fail_on_unmatched_files: true
369+
370+
- name: Publish first release
371+
if: needs.preflight.outputs.previous_tag == ''
340372
uses: softprops/action-gh-release@v2
341373
with:
342374
tag_name: ${{ needs.preflight.outputs.tag }}

‎docs/release.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This document covers the unified release workflow for stable and nightly desktop
1919
- Stable tags with a suffix after `X.Y.Z` (for example `1.2.3-alpha.1`) are published as GitHub prereleases.
2020
- Only plain stable `X.Y.Z` releases are marked as the repository's latest release.
2121
- Nightly runs are always GitHub prereleases and never marked latest.
22+
- Automatically generated release notes are pinned to the previous tag in the same channel, so stable compares to the previous stable tag and nightly compares to the previous nightly tag.
2223
- Includes Electron auto-update metadata (for example `latest*.yml`, `nightly*.yml`, and `*.blockmap`) in release assets.
2324
- Publishes the CLI package (`apps/server`, npm package `t3`) with OIDC trusted publishing from the same workflow file:
2425
- stable releases publish npm dist-tag `latest`
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#!/usr/bin/env node
2+
3+
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
4+
import * as NodeServices from "@effect/platform-node/NodeServices";
5+
import { Array, Config, Effect, FileSystem, Schema, Stream, String } from "effect";
6+
import { Command, Flag } from "effect/unstable/cli";
7+
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
8+
9+
const ReleaseChannel = Schema.Literals(["stable", "nightly"]);
10+
type ReleaseChannel = typeof ReleaseChannel.Type;
11+
12+
interface StableVersion {
13+
readonly major: number;
14+
readonly minor: number;
15+
readonly patch: number;
16+
readonly prerelease: ReadonlyArray<string>;
17+
}
18+
19+
interface NightlyVersion {
20+
readonly major: number;
21+
readonly minor: number;
22+
readonly patch: number;
23+
readonly date: number;
24+
readonly runNumber: number;
25+
}
26+
27+
const parseNumericIdentifier = (identifier: string): number | undefined =>
28+
/^\d+$/.test(identifier) ? Number(identifier) : undefined;
29+
30+
const comparePrereleaseIdentifiers = (left: string, right: string): number => {
31+
const leftNumeric = parseNumericIdentifier(left);
32+
const rightNumeric = parseNumericIdentifier(right);
33+
34+
if (leftNumeric !== undefined && rightNumeric !== undefined) {
35+
return leftNumeric - rightNumeric;
36+
}
37+
if (leftNumeric !== undefined) {
38+
return -1;
39+
}
40+
if (rightNumeric !== undefined) {
41+
return 1;
42+
}
43+
return left.localeCompare(right);
44+
};
45+
46+
const compareStableVersions = (left: StableVersion, right: StableVersion): number => {
47+
if (left.major !== right.major) return left.major - right.major;
48+
if (left.minor !== right.minor) return left.minor - right.minor;
49+
if (left.patch !== right.patch) return left.patch - right.patch;
50+
51+
const leftHasPrerelease = left.prerelease.length > 0;
52+
const rightHasPrerelease = right.prerelease.length > 0;
53+
if (!leftHasPrerelease && !rightHasPrerelease) return 0;
54+
if (!leftHasPrerelease) return 1;
55+
if (!rightHasPrerelease) return -1;
56+
57+
const maxLength = Math.max(left.prerelease.length, right.prerelease.length);
58+
for (let index = 0; index < maxLength; index += 1) {
59+
const leftIdentifier = left.prerelease[index];
60+
const rightIdentifier = right.prerelease[index];
61+
if (leftIdentifier === undefined) return -1;
62+
if (rightIdentifier === undefined) return 1;
63+
64+
const comparison = comparePrereleaseIdentifiers(leftIdentifier, rightIdentifier);
65+
if (comparison !== 0) return comparison;
66+
}
67+
68+
return 0;
69+
};
70+
71+
const parseStableTag = (tag: string): StableVersion | undefined => {
72+
const match = /^v(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(tag);
73+
if (!match) return undefined;
74+
75+
const [, major, minor, patch, prerelease] = match;
76+
if (!major || !minor || !patch) return undefined;
77+
78+
return {
79+
major: Number(major),
80+
minor: Number(minor),
81+
patch: Number(patch),
82+
prerelease: prerelease ? prerelease.split(".") : [],
83+
};
84+
};
85+
86+
const compareNightlyVersions = (left: NightlyVersion, right: NightlyVersion): number => {
87+
if (left.major !== right.major) return left.major - right.major;
88+
if (left.minor !== right.minor) return left.minor - right.minor;
89+
if (left.patch !== right.patch) return left.patch - right.patch;
90+
if (left.date !== right.date) return left.date - right.date;
91+
return left.runNumber - right.runNumber;
92+
};
93+
94+
const parseNightlyTag = (tag: string): NightlyVersion | undefined => {
95+
const match = /^nightly-v(\d+)\.(\d+)\.(\d+)-nightly\.(\d{8})\.(\d+)$/.exec(tag);
96+
if (!match) return undefined;
97+
98+
const [, major, minor, patch, date, runNumber] = match;
99+
if (!major || !minor || !patch || !date || !runNumber) return undefined;
100+
101+
return {
102+
major: Number(major),
103+
minor: Number(minor),
104+
patch: Number(patch),
105+
date: Number(date),
106+
runNumber: Number(runNumber),
107+
};
108+
};
109+
110+
const resolvePreviousReleaseTag = (
111+
channel: ReleaseChannel,
112+
currentTag: string,
113+
tags: ReadonlyArray<string>,
114+
): string | undefined => {
115+
if (channel === "stable") {
116+
const current = parseStableTag(currentTag);
117+
if (!current) {
118+
throw new Error(`Invalid stable release tag '${currentTag}'.`);
119+
}
120+
121+
const candidates = tags
122+
.map((tag) => ({ tag, parsed: parseStableTag(tag) }))
123+
.filter(
124+
(entry): entry is { tag: string; parsed: StableVersion } => entry.parsed !== undefined,
125+
)
126+
.filter((entry) => compareStableVersions(entry.parsed, current) < 0)
127+
.toSorted((left, right) => compareStableVersions(right.parsed, left.parsed));
128+
129+
return candidates[0]?.tag;
130+
}
131+
132+
const current = parseNightlyTag(currentTag);
133+
if (!current) {
134+
throw new Error(`Invalid nightly release tag '${currentTag}'.`);
135+
}
136+
137+
const candidates = tags
138+
.map((tag) => ({ tag, parsed: parseNightlyTag(tag) }))
139+
.filter((entry): entry is { tag: string; parsed: NightlyVersion } => entry.parsed !== undefined)
140+
.filter((entry) => compareNightlyVersions(entry.parsed, current) < 0)
141+
.toSorted((left, right) => compareNightlyVersions(right.parsed, left.parsed));
142+
143+
return candidates[0]?.tag;
144+
};
145+
146+
const listGitTags = Effect.fn("listGitTags")(function* () {
147+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
148+
const child = yield* spawner.spawn(ChildProcess.make("git", ["tag", "--list"]));
149+
const tags = yield* child.stdout.pipe(
150+
Stream.decodeText(),
151+
Stream.runFold(
152+
() => "",
153+
(acc, chunk) => acc + chunk,
154+
),
155+
Effect.map(String.split(/\r?\n/)),
156+
Effect.map(Array.map(String.trim)),
157+
Effect.map(Array.filter(String.isNonEmpty)),
158+
);
159+
return tags;
160+
});
161+
162+
const writeOutput = Effect.fn("writeOutput")(function* (
163+
previousTag: string | undefined,
164+
writeGithubOutput: boolean,
165+
) {
166+
const entry = `previous_tag=${previousTag ?? ""}\n`;
167+
168+
if (writeGithubOutput) {
169+
const fs = yield* FileSystem.FileSystem;
170+
const githubOutputPath = yield* Config.nonEmptyString("GITHUB_OUTPUT");
171+
yield* fs.writeFileString(githubOutputPath, entry, { flag: "a" });
172+
return;
173+
}
174+
175+
process.stdout.write(entry);
176+
});
177+
178+
const command = Command.make(
179+
"resolve-previous-release-tag",
180+
{
181+
channel: Flag.choice("channel", ReleaseChannel.literals).pipe(
182+
Flag.withDescription("Release channel whose previous tag should be resolved."),
183+
),
184+
currentTag: Flag.string("current-tag").pipe(
185+
Flag.withDescription("Current release tag to compare against."),
186+
),
187+
githubOutput: Flag.boolean("github-output").pipe(
188+
Flag.withDescription("Write values to GITHUB_OUTPUT instead of stdout."),
189+
Flag.withDefault(false),
190+
),
191+
},
192+
({ channel, currentTag, githubOutput }) =>
193+
listGitTags().pipe(
194+
Effect.map((tags) => resolvePreviousReleaseTag(channel, currentTag, tags)),
195+
Effect.flatMap((previousTag) => writeOutput(previousTag, githubOutput)),
196+
),
197+
).pipe(Command.withDescription("Resolve the previous release tag for a stable or nightly series."));
198+
199+
Command.run(command, { version: "0.0.0" }).pipe(
200+
Effect.scoped,
201+
Effect.provide(NodeServices.layer),
202+
NodeRuntime.runMain,
203+
);

0 commit comments

Comments
 (0)