Initial release
This commit is contained in:
1 parent
8ceb3c8be8
commit
f2cefdd429
5 files changed
+80
-22
No files matched your search
@@ -0,0 +1,33 @@
|
|||||||
|
// Print one version's section of CHANGELOG.md, for use as release notes.
|
||||||
|
//
|
||||||
|
// node changelog.mjs <tag> [CHANGELOG.md]
|
||||||
|
//
|
||||||
|
// The section starts at a "## v0.1.0" heading (the "v" is optional) and runs
|
||||||
|
// to the next "## " heading. Exits non-zero if it's missing or empty, so a
|
||||||
|
// release can't go out without notes.
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
|
||||||
|
function fail(msg) {
|
||||||
|
console.error(`::error::${msg}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [tag, path = "CHANGELOG.md"] = process.argv.slice(2);
|
||||||
|
if (!tag) fail("usage: changelog.mjs <tag> [CHANGELOG.md]");
|
||||||
|
|
||||||
|
const version = tag.replace(/^v/, "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
|
const heading = new RegExp(`^##\\s+v?${version}(\\s|$)`);
|
||||||
|
const lines = readFileSync(path, "utf8").split(/\r?\n/);
|
||||||
|
|
||||||
|
const start = lines.findIndex((l) => heading.test(l));
|
||||||
|
if (start < 0) {
|
||||||
|
fail(
|
||||||
|
`${path} has no "## ${tag}" section. Add one, commit it, then move the tag to that commit and push it again.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let end = lines.findIndex((l, i) => i > start && /^##\s/.test(l));
|
||||||
|
if (end < 0) end = lines.length;
|
||||||
|
|
||||||
|
const notes = lines.slice(start + 1, end).join("\n").trim();
|
||||||
|
if (!notes) fail(`The "## ${tag}" section of ${path} is empty.`);
|
||||||
|
process.stdout.write(`${notes}\n`);
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
// Create (or reuse) the Gitea release for a tag and upload files to it.
|
// Create (or reuse) the Gitea release for a tag and upload files to it.
|
||||||
//
|
//
|
||||||
// node gitea-release.mjs <tag> <file>...
|
// node gitea-release.mjs <tag> <notes.md> <file>...
|
||||||
//
|
//
|
||||||
// Reads GITHUB_SERVER_URL, GITHUB_REPOSITORY and GITHUB_SHA (set by Gitea
|
// The release notes are the contents of <notes.md>. Reads GITHUB_SERVER_URL
|
||||||
// Actions) and GITEA_TOKEN. Safe to re-run: an existing release is reused and
|
// and GITHUB_REPOSITORY (set by Gitea Actions) and GITEA_TOKEN. Safe to
|
||||||
// assets with the same name are replaced.
|
// re-run: an existing release is reused, its notes are updated, and assets
|
||||||
import { openAsBlob } from "node:fs";
|
// with the same name are replaced.
|
||||||
|
import { openAsBlob, readFileSync } from "node:fs";
|
||||||
import { basename } from "node:path";
|
import { basename } from "node:path";
|
||||||
|
|
||||||
function fail(msg) {
|
function fail(msg) {
|
||||||
@@ -13,11 +14,14 @@ function fail(msg) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [tag, ...files] = process.argv.slice(2);
|
const [tag, notesFile, ...files] = process.argv.slice(2);
|
||||||
if (!tag || files.length === 0) fail("usage: gitea-release.mjs <tag> <file>...");
|
if (!tag || !notesFile || files.length === 0) {
|
||||||
|
fail("usage: gitea-release.mjs <tag> <notes.md> <file>...");
|
||||||
|
}
|
||||||
|
const notes = readFileSync(notesFile, "utf8").trim();
|
||||||
|
if (!notes) fail(`${notesFile} is empty`);
|
||||||
|
|
||||||
const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: repo, GITHUB_SHA: sha, GITEA_TOKEN: token } =
|
const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: repo, GITEA_TOKEN: token } = process.env;
|
||||||
process.env;
|
|
||||||
if (!server || !repo || !token) fail("GITHUB_SERVER_URL, GITHUB_REPOSITORY and GITEA_TOKEN must be set");
|
if (!server || !repo || !token) fail("GITHUB_SERVER_URL, GITHUB_REPOSITORY and GITEA_TOKEN must be set");
|
||||||
|
|
||||||
const api = `${server.replace(/\/+$/, "")}/api/v1/repos/${repo}`;
|
const api = `${server.replace(/\/+$/, "")}/api/v1/repos/${repo}`;
|
||||||
@@ -37,16 +41,13 @@ async function call(method, path, { json, form, allow404 = false } = {}) {
|
|||||||
return res.status === 204 ? null : res.json();
|
return res.status === 204 ? null : res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
const archive = files.map((f) => basename(f)).find((n) => n.endsWith(".tar.gz"));
|
|
||||||
const notes = [
|
|
||||||
"Static Linux binary with the web UI built in.",
|
|
||||||
sha ? `\nBuilt from ${sha}.` : "",
|
|
||||||
archive ? `\nCheck the download with \`sha256sum -c ${archive}.sha256\`.` : "",
|
|
||||||
].join("");
|
|
||||||
|
|
||||||
let release = await call("GET", `/releases/tags/${encodeURIComponent(tag)}`, { allow404: true });
|
let release = await call("GET", `/releases/tags/${encodeURIComponent(tag)}`, { allow404: true });
|
||||||
if (release) {
|
if (release) {
|
||||||
console.log(`Reusing release ${tag} (id ${release.id})`);
|
console.log(`Reusing release ${tag} (id ${release.id})`);
|
||||||
|
if ((release.body ?? "").trim() !== notes) {
|
||||||
|
release = await call("PATCH", `/releases/${release.id}`, { json: { body: notes } });
|
||||||
|
console.log("Updated the release notes");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
release = await call("POST", "/releases", {
|
release = await call("POST", "/releases", {
|
||||||
json: { tag_name: tag, name: tag, body: notes, draft: false, prerelease: tag.includes("-") },
|
json: { tag_name: tag, name: tag, body: notes, draft: false, prerelease: tag.includes("-") },
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ name: Release
|
|||||||
|
|
||||||
# Push a tag such as v0.1.0 to build a static Linux binary (web UI included)
|
# Push a tag such as v0.1.0 to build a static Linux binary (web UI included)
|
||||||
# and publish it as a Gitea release. The tag must match the version in
|
# and publish it as a Gitea release. The tag must match the version in
|
||||||
# Cargo.toml's [workspace.package].
|
# Cargo.toml's [workspace.package], and CHANGELOG.md must have a section for
|
||||||
|
# it: that section becomes the release notes.
|
||||||
#
|
#
|
||||||
# Written for Gitea Actions (act_runner). It lives in .github/workflows so the
|
# Written for Gitea Actions (act_runner). It lives in .github/workflows so the
|
||||||
# CI workflow next to it keeps running too: Gitea ignores .github/workflows
|
# CI workflow next to it keeps running too: Gitea ignores .github/workflows
|
||||||
@@ -36,6 +37,14 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with: { node-version: 22, cache: npm, cache-dependency-path: ui/package-lock.json }
|
with: { node-version: 22, cache: npm, cache-dependency-path: ui/package-lock.json }
|
||||||
|
|
||||||
|
# Before the long build, so a missing entry fails in seconds.
|
||||||
|
- name: Read the release notes from CHANGELOG.md
|
||||||
|
run: |
|
||||||
|
mkdir -p dist
|
||||||
|
node .github/scripts/changelog.mjs "$GITHUB_REF_NAME" > dist/release-notes.md
|
||||||
|
cat dist/release-notes.md
|
||||||
|
|
||||||
- name: Build the UI
|
- name: Build the UI
|
||||||
run: |
|
run: |
|
||||||
npm --prefix ui ci
|
npm --prefix ui ci
|
||||||
@@ -74,4 +83,6 @@ jobs:
|
|||||||
- name: Publish the release
|
- name: Publish the release
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: node .github/scripts/gitea-release.mjs "$GITHUB_REF_NAME" "$ASSET" "$ASSET.sha256"
|
run: >-
|
||||||
|
node .github/scripts/gitea-release.mjs "$GITHUB_REF_NAME" dist/release-notes.md
|
||||||
|
"$ASSET" "$ASSET.sha256"
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## v0.1.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Initial release.**
|
||||||
@@ -91,16 +91,22 @@ Interrupted transfers resume after a restart.
|
|||||||
|
|
||||||
### Making a release
|
### Making a release
|
||||||
|
|
||||||
`.github/workflows/release.yml` runs on Gitea Actions. To cut a release, bump
|
`.github/workflows/release.yml` runs on Gitea Actions. To cut a release:
|
||||||
`version` in the root `Cargo.toml`, commit, then push a matching tag:
|
|
||||||
|
1. Bump `version` in the root `Cargo.toml`.
|
||||||
|
2. Add a `## v0.1.1` section to the top of `CHANGELOG.md`, using whichever of
|
||||||
|
`### Added`, `### Updated`, `### Fixed` and `### Removed` apply.
|
||||||
|
3. Commit, then push a matching tag:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git tag v0.1.1 && git push origin v0.1.1
|
git tag v0.1.1 && git push origin v0.1.1
|
||||||
```
|
```
|
||||||
|
|
||||||
The workflow runs the tests, builds the UI and binary, and attaches the
|
The workflow runs the tests, builds the UI and binary, and attaches the
|
||||||
tarball and its `.sha256` to a Gitea release for that tag. Re-running it
|
tarball and its `.sha256` to a Gitea release for that tag. The release notes
|
||||||
replaces the files. Tags with a `-` (`v0.2.0-rc1`) are marked pre-release.
|
are that version's section of `CHANGELOG.md`; the workflow stops straight
|
||||||
|
away if there isn't one. Re-running it replaces the files and refreshes the
|
||||||
|
notes. Tags with a `-` (`v0.2.0-rc1`) are marked pre-release.
|
||||||
|
|
||||||
### Library mapping
|
### Library mapping
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user