Skip to content

Commit 98e4c2a

Browse files
committed
refactor(build): 统一编译与发布的平台清单
1 parent 01d299c commit 98e4c2a

5 files changed

Lines changed: 35 additions & 27 deletions

File tree

‎.github/workflows/release.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- '.github/workflows/release.yaml'
1111
- '.github/workflows/check.yaml'
1212
- 'scripts/compile.ts'
13+
- 'scripts/platforms.ts'
1314
- 'scripts/release.ts'
1415
- 'scripts/smoke.ts'
1516
- 'docs/installation.md'

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ docs: 说明参数传递规则
114114

115115
每个任务使用 `bun run compile` 生成一次待分发的压缩二进制,在 JDK 21 下执行完整 smoke。随后将该文件打包,不重新构建:Linux / macOS 使用 `zip`,Windows 使用 PowerShell `Compress-Archive`。实际 ZIP 会在原生环境中解压,核对其中二进制与已验收文件的字节一致,再使用 JDK 17 对解压出的文件执行 quick 启动验收。
116116

117-
每份 ZIP 包含一个 `java-run-<平台>/` 目录,目录内为固定名称的 `java-run` 或 `java-run.exe`、从 [安装指南](docs/installation.md) 复制的 `INSTALL.md`,以及存在的许可证文件。平台清单、包内目录和公开资产名称由 [发布脚本](scripts/release.ts) 统一生成。公开名称不带版本号,版本由 `/releases/download/v<版本>/` URL 表达;`/releases/latest/download/` 提供最新稳定版的固定下载入口。
117+
每份 ZIP 包含一个 `java-run-<平台>/` 目录,目录内为固定名称的 `java-run` 或 `java-run.exe`、从 [安装指南](docs/installation.md) 复制的 `INSTALL.md`,以及存在的许可证文件。编译参数、发布矩阵、包内目录和公开资产名称共用 [平台清单](scripts/platforms.ts)。公开名称不带版本号,版本由 `/releases/download/v<版本>/` URL 表达;`/releases/latest/download/` 提供最新稳定版的固定下载入口。
118118

119119
汇总步骤要求恰好包含上述五种非空 ZIP,拒绝缺失、多余或无效产物,然后生成并核对覆盖五个 ZIP 的 `SHA256SUMS`。源码 Check 的双 JDK 完整回归与发布文件的 JDK 21 full / JDK 17 quick 范围分别声明,不能将 quick 扩大为完整验收。Linux 验收采用 Ubuntu 24.04 的 glibc 环境,不代表 musl 或其他系统版本已通过验收。
120120

‎scripts/compile.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { spawnSync } from 'node:child_process';
22
import { resolve } from 'node:path';
3+
import { platforms, type BuildTarget } from './platforms';
34

45
const projectRoot = resolve(import.meta.dir, '..');
5-
const targets = [
6-
'bun-windows-x64',
7-
'bun-linux-x64',
8-
'bun-linux-arm64',
9-
'bun-darwin-arm64',
10-
'bun-darwin-x64',
11-
] as const;
126

137
/** 本机或指定平台的独立二进制构建配置 */
148
export interface CompileOptions {
15-
target?: typeof targets[number];
9+
target?: BuildTarget;
1610
outfile: string;
1711
}
1812

@@ -33,8 +27,9 @@ export function parseCompileOptions(argv: readonly string[], cwd = projectRoot):
3327
const value = separator < 0 ? '' : argument.slice(separator + 1);
3428
if (!value.trim() || /[\r\n\0]/.test(value)) throw new Error(`${name} 必须使用 ${name}=<value> 指定有效值`);
3529
if (name === '--target') {
36-
if (!targets.includes(value as typeof targets[number])) throw new Error(`--target 仅支持 ${targets.join('、')}`);
37-
options.target = value as typeof targets[number];
30+
const platform = platforms.find(platform => platform.target === value);
31+
if (!platform) throw new Error(`--target 仅支持 ${platforms.map(platform => platform.target).join('、')}`);
32+
options.target = platform.target;
3833
} else {
3934
options.outfile = resolve(cwd, value);
4035
}

‎scripts/platforms.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const definitions = [
2+
{ name: 'windows-x64', runner: 'windows-2025', target: 'bun-windows-x64', binary: 'java-run.exe', label: 'Windows x64' },
3+
{ name: 'linux-x64', runner: 'ubuntu-24.04', target: 'bun-linux-x64', binary: 'java-run', label: 'Linux x64' },
4+
{ name: 'linux-arm64', runner: 'ubuntu-24.04-arm', target: 'bun-linux-arm64', binary: 'java-run', label: 'Linux ARM64' },
5+
{ name: 'darwin-arm64', runner: 'macos-15', target: 'bun-darwin-arm64', binary: 'java-run', label: 'macOS Apple Silicon' },
6+
{ name: 'darwin-x64', runner: 'macos-15-intel', target: 'bun-darwin-x64', binary: 'java-run', label: 'macOS Intel' },
7+
] as const;
8+
9+
/** 编译、发布矩阵、归档和下载说明共用的平台清单 */
10+
export const platforms = definitions.map(platform => ({
11+
...platform,
12+
folder: `java-run-${platform.name}`,
13+
archive: `java-run-${platform.name}.zip`,
14+
}));
15+
16+
/** 支持的 Bun 编译目标 */
17+
export type BuildTarget = typeof platforms[number]['target'];
18+
19+
/** 查找发布平台,未知名称时拒绝继续构建或打包 */
20+
export function platformFor(name: string) {
21+
const platform = platforms.find(platform => platform.name === name);
22+
if (!platform) throw new Error(`不支持的发布平台:${name}`);
23+
return platform;
24+
}

‎scripts/release.ts‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile
44
import { tmpdir } from 'node:os';
55
import { join, resolve } from 'node:path';
66
import { spawnSync } from 'node:child_process';
7+
import { platforms, platformFor } from './platforms';
78

89
const projectRoot = resolve(import.meta.dir, '..');
9-
const platforms = [
10-
{ name: 'windows-x64', runner: 'windows-2025', target: 'bun-windows-x64', binary: 'java-run.exe', label: 'Windows x64' },
11-
{ name: 'linux-x64', runner: 'ubuntu-24.04', target: 'bun-linux-x64', binary: 'java-run', label: 'Linux x64' },
12-
{ name: 'linux-arm64', runner: 'ubuntu-24.04-arm', target: 'bun-linux-arm64', binary: 'java-run', label: 'Linux ARM64' },
13-
{ name: 'darwin-arm64', runner: 'macos-15', target: 'bun-darwin-arm64', binary: 'java-run', label: 'macOS Apple Silicon' },
14-
{ name: 'darwin-x64', runner: 'macos-15-intel', target: 'bun-darwin-x64', binary: 'java-run', label: 'macOS Intel' },
15-
] as const;
1610
const licenseNames = ['LICENSE', 'LICENSE.md', 'LICENSE.txt'];
1711
const repository = 'https://github.com/Vanisper/java-run';
1812

@@ -38,16 +32,16 @@ export function releaseMetadata(version: string, requestedTag?: string): Release
3832
version, tag, prerelease: match[4] !== undefined,
3933
matrix: { include: platforms.map(platform => ({
4034
name: platform.name, runner: platform.runner, target: platform.target,
41-
binary: platform.binary, archive: `java-run-${platform.name}.zip`,
35+
binary: platform.binary, archive: platform.archive,
4236
})) },
4337
};
4438
}
4539

4640
/** 为当前版本生成固定下载链接、安装要求和升级说明 */
4741
export function releaseNotes(version: string): string {
48-
const { tag, matrix } = releaseMetadata(version);
42+
const { tag } = releaseMetadata(version);
4943
const download = `${repository}/releases/download/${encodeURIComponent(tag)}`;
50-
const rows = matrix.include.map((platform, index) => `| ${platforms[index]!.label} | [${platform.archive}](${download}/${platform.archive}) |`);
44+
const rows = platforms.map(platform => `| ${platform.label} | [${platform.archive}](${download}/${platform.archive}) |`);
5145
return `## 下载与安装
5246
5347
下载对应系统与处理器的 ZIP 后解压,无需安装 Bun。本机需要满足 Java 项目要求的 JDK;优先使用项目的 Maven / Gradle Wrapper,没有 Wrapper 时需安装对应构建工具。
@@ -66,12 +60,6 @@ ${rows.join('\n')}
6660
`;
6761
}
6862

69-
function platformFor(name: string) {
70-
const platform = platforms.find(platform => platform.name === name);
71-
if (!platform) throw new Error(`不支持的发布平台:${name}`);
72-
return { ...platform, folder: `java-run-${platform.name}`, archive: `java-run-${platform.name}.zip` };
73-
}
74-
7563
async function assertFile(path: string): Promise<void> {
7664
const stat = await lstat(path);
7765
if (!stat.isFile() || stat.size === 0) throw new Error(`文件不是非空普通文件:${path}`);

0 commit comments

Comments
 (0)