Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
135e6d6d92 | ||
|
|
a950edfb13 |
@@ -29,7 +29,7 @@ The [development guide](docs/development.md#architecture) maps the source folder
|
||||
| `pnpm build:browser-engine --release-url <url> --version <version>` | Browser engine ZIP and its pin. See [Build the browser engine](docs/builds.md#build-the-browser-engine). |
|
||||
| `pnpm package:plugin <compiled-folder> [output-folder]` | Plugin ZIP |
|
||||
| `pnpm sdk:build` | Build the plugin SDK in `packages/plugin-sdk/` |
|
||||
| `pnpm release:sdk --version <version>` | Prepare an SDK release in the public SDK clone. It never pushes. See [SDK releases](docs/releases.md). |
|
||||
| `pnpm release:sdk --release-url <url> --version <version>` | SDK package file and its record. It never uploads. See [SDK releases](docs/releases.md#sdk-releases). |
|
||||
|
||||
A source edit needs the checks that cover it. A prose-only change needs only the lint and a link check.
|
||||
|
||||
@@ -75,13 +75,13 @@ Rules from the owner:
|
||||
|
||||
- Versions use `zz.yy.xx`. A hotfix adds a lowercase letter suffix: `0.2.28a`, then `0.2.28b`.
|
||||
- Keep the current version during source edits, fixes, documentation, and checks. Instruction-only edits never change it.
|
||||
- Set the next version only when you produce a build: a RuneStone installer, a browser engine ZIP, or a plugin ZIP.
|
||||
- Set the next version only when you produce a build: a RuneStone installer, a browser engine ZIP, an SDK package, or a plugin ZIP.
|
||||
A regular build increases `xx` by one. A hotfix build increases only the suffix.
|
||||
- If the build fails, restore the previous version fields. Failed attempts do not use up a version.
|
||||
- Increase `yy` or `zz` only when the owner directs a release.
|
||||
- Report a new version only after its artifact exists. Report the full artifact path.
|
||||
- Completed builds go in `releases/`, outside Git. Never overwrite a release with different contents.
|
||||
- Repository releases contain only installers, browser engine ZIPs, or plugin ZIPs, with an empty description.
|
||||
- Repository releases contain only installers, browser engine ZIPs, SDK packages, or plugin ZIPs, with an empty description.
|
||||
|
||||
## Windows installer
|
||||
|
||||
|
||||
+1
-1
@@ -211,7 +211,7 @@ The SDK source must not import host files. It must use only TypeScript syntax th
|
||||
| Command | Result |
|
||||
| --- | --- |
|
||||
| `pnpm sdk:build` | Compiles the SDK into `packages/plugin-sdk/dist/` with declaration files. The folder is outside Git. |
|
||||
| `pnpm release:sdk --version <version> [--dry-run]` | Builds the SDK, then commits and tags it in a local clone of the public repository. See [SDK releases](releases.md#sdk-releases). |
|
||||
| `pnpm release:sdk --release-url <url> --version <version> [--dry-run]` | Builds the SDK and writes its package file and `sdk.json` in `releases/plugin-sdk/<version>/`. See [SDK releases](releases.md#sdk-releases). |
|
||||
|
||||
`pnpm check` type checks the SDK with `packages/plugin-sdk/tsconfig.json` and the example plugin with `fixtures/plugins/tsconfig.json`.
|
||||
`pnpm test` runs the SDK tests in `tests/unit/sdk/` and the release script tests in `tests/unit/release/releaseSdk.spec.ts`.
|
||||
|
||||
@@ -20,14 +20,15 @@ This reference gives the package contract, the build procedure, and the API for
|
||||
## Install the SDK
|
||||
|
||||
The plugin SDK `@runestone/plugin-sdk` gives the API types, the feature checks, and the RuneStone icons and tooltip.
|
||||
Install it in each plugin project from a release tag of its public repository. The SDK is not on the npm registry.
|
||||
Install it in each plugin project from the URL of its package file on the RuneStone releases page.
|
||||
|
||||
```sh
|
||||
pnpm add -D "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.1"
|
||||
pnpm add -D "https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/plugin-sdk-v0.1.2/runestone-plugin-sdk-0.1.2.tgz"
|
||||
```
|
||||
|
||||
- The repository is public. The installation needs no access token and no `.npmrc` file.
|
||||
- Always give a tag. To change the SDK version, change the tag in `package.json`.
|
||||
- Always give the full URL. The SDK is not on the npm registry, and another account owns the `@runestone` scope there.
|
||||
- npm accepts the same URL. The installation needs no access token and no `.npmrc` file.
|
||||
- To change the SDK version, change the version in both parts of the URL: the tag and the file name.
|
||||
- Bundle the SDK helpers into the entry module. A type-only import adds no code.
|
||||
- Do not copy RuneStone source files into a plugin, and do not import them from a RuneStone checkout. Use the SDK types and the host APIs.
|
||||
|
||||
|
||||
+37
-44
@@ -14,7 +14,7 @@ RuneStone, the browser engine, and each plugin keep separate version numbers. Ea
|
||||
| `yy` | A deliberate release that is ready for build testing, by direction of the project owner | `xx` to zero |
|
||||
| `zz` | A full release, by direction of the project owner | `yy` and `xx` to zero |
|
||||
|
||||
A build is a RuneStone installer, a browser engine ZIP, or a plugin ZIP, unless the project owner asks for a different distributable.
|
||||
A build is a RuneStone installer, a browser engine ZIP, an SDK package, or a plugin ZIP, unless the project owner asks for a different distributable.
|
||||
Development servers, test runs, and intermediate compilation output are not builds.
|
||||
|
||||
- Keep routine implementation work in the current `zz.yy` series.
|
||||
@@ -69,6 +69,7 @@ These rules apply to the main app, all existing plugins, and all new plugins.
|
||||
| --- | --- |
|
||||
| RuneStone installer | `releases/<version>/` at the RuneStone project root |
|
||||
| Browser engine ZIP | `releases/browser-engine/<version>/` at the RuneStone project root |
|
||||
| SDK package | `releases/plugin-sdk/<version>/` at the RuneStone project root |
|
||||
| Plugin ZIP | `releases/` at the root of that plugin project |
|
||||
|
||||
- Keep release notes, checksums, and build metadata with the release they describe, in the local release folder.
|
||||
@@ -82,15 +83,15 @@ These rules apply to the main app, all existing plugins, and all new plugins.
|
||||
- Report a filename conflict before you change a file name.
|
||||
- After each completed build, report the full path of the build file.
|
||||
|
||||
`pnpm build:installer`, `pnpm build:browser-engine`, and `pnpm package:plugin` obey these rules for their own output.
|
||||
The installer and engine scripts stop if the release file exists. The plugin packager reuses an identical ZIP and stops if the existing ZIP has different contents.
|
||||
`pnpm build:installer`, `pnpm build:browser-engine`, `pnpm release:sdk`, and `pnpm package:plugin` obey these rules for their own output.
|
||||
The installer, engine, and SDK scripts stop if the release file exists. The plugin packager reuses an identical ZIP and stops if the existing ZIP has different contents.
|
||||
|
||||
## Publish an installer
|
||||
|
||||
Publish RuneStone installers on the [public releases page](https://git.knottywyvern.com/kwyvern/RuneStone_Releases/releases), beside the browser engine ZIPs.
|
||||
Publish RuneStone installers on the [RuneStone releases page](https://git.knottywyvern.com/kwyvern/RuneStone/releases). Browser engine ZIPs and SDK packages use the same page.
|
||||
|
||||
1. Build the installer and complete the [installer checks](builds.md#installer-checks).
|
||||
2. Create a release with the tag `v<version>`.
|
||||
2. Create a release with the tag `v<version>` on the commit that sets the version.
|
||||
3. Attach only installer binaries.
|
||||
4. Leave the release description empty.
|
||||
5. Publish the release.
|
||||
@@ -105,14 +106,13 @@ Keep the other build records in the local release folder.
|
||||
|
||||
## Publish a browser engine
|
||||
|
||||
Each host build downloads the URL in its pin, so the engine ZIP needs a public release location that answers without a sign-in.
|
||||
Until that location exists, the pin stays empty, and an installer cannot download the engine.
|
||||
Each host build downloads the URL in its pin, so the engine ZIP must download without a sign-in.
|
||||
|
||||
1. Build the engine ZIP with the URL of its public release folder. See [Build the browser engine](builds.md#build-the-browser-engine).
|
||||
2. In the public release location, create a release with the tag `browser-engine-v<version>`.
|
||||
3. Attach only the engine ZIP. Leave the release description empty. The ZIP is about 164 MB, so the location must accept files of that size.
|
||||
4. Make sure that the `url` in `engine.json` downloads the ZIP without a sign-in, and that its size matches.
|
||||
5. Commit `src-tauri/browser-engine.json` and the engine version fields.
|
||||
1. Build the engine ZIP with the URL of its release folder on the RuneStone releases page. See [Build the browser engine](builds.md#build-the-browser-engine).
|
||||
2. Commit `src-tauri/browser-engine.json` and the engine version fields.
|
||||
3. Create a release with the tag `browser-engine-v<version>` on that commit.
|
||||
4. Attach only the engine ZIP. Leave the release description empty. The ZIP is about 164 MB, so the server must accept files of that size.
|
||||
5. Make sure that the `url` in `engine.json` downloads the ZIP without a sign-in, and that its size matches.
|
||||
6. Build the installer that pins this engine.
|
||||
|
||||
Keep each published engine ZIP. Installed RuneStone versions download the engine that they pin.
|
||||
@@ -171,50 +171,43 @@ For GitHub publication steps, see [GitHub's release instructions](https://docs.g
|
||||
|
||||
## SDK releases
|
||||
|
||||
The plugin SDK `@runestone/plugin-sdk` has its own version, in `packages/plugin-sdk/package.json`. The first release is `0.1.0`.
|
||||
The plugin SDK `@runestone/plugin-sdk` has its own version, in `packages/plugin-sdk/package.json`.
|
||||
The [version rules](#versions) and the [hotfix rules](#hotfix-versions) apply.
|
||||
An SDK release is a commit and a tag in the public SDK repository. It is not a ZIP or an installer.
|
||||
An SDK release is one package file, `runestone-plugin-sdk-<version>.tgz`, on the RuneStone releases page with the tag `plugin-sdk-v<version>`.
|
||||
Plugin authors install the SDK from the URL of that file. See [Install the SDK](plugin-development.md#install-the-sdk).
|
||||
`pnpm sdk:build` output in `packages/plugin-sdk/dist/` is compilation output, not a release.
|
||||
|
||||
The source stays in this repository. The public repository is [RuneStone_Plugin_SDK](https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK).
|
||||
It holds only the released files: `dist/`, `package.json`, `README.md`, `LICENSE`, and `NOTICE`.
|
||||
Plugin authors install the SDK from a tag of that repository. See [Install the SDK](plugin-development.md#install-the-sdk).
|
||||
|
||||
### Prepare the clone
|
||||
|
||||
Do these steps one time.
|
||||
|
||||
1. On the Gitea server, create the public repository `kwyvern/RuneStone_Plugin_SDK`. It can be empty.
|
||||
2. Clone it beside the RuneStone repository, as `RuneStone_Plugin_SDK`.
|
||||
For a different folder, set `RUNESTONE_SDK_REPO` to the clone.
|
||||
Without that variable, the script uses `RuneStone_Plugin_SDK` in the `RUNESTONE_PLUGIN_REPOS` folder, or else in the parent folder of RuneStone.
|
||||
3. Set the Git user name and email in the clone, if your global Git configuration does not have them.
|
||||
|
||||
### Release the SDK
|
||||
|
||||
1. Commit the SDK changes in RuneStone. Run `pnpm check` and `pnpm test`.
|
||||
2. In the clone, get the latest commits and tags: `git pull --tags`.
|
||||
3. Run `pnpm release:sdk --version <version> --dry-run`. Read the plan.
|
||||
4. Run `pnpm release:sdk --version <version>`.
|
||||
5. Run the push commands that the script prints. The script never pushes.
|
||||
6. In RuneStone, commit the new version in `packages/plugin-sdk/package.json`.
|
||||
7. Install the tag in a plugin project, build the plugin, and test it in RuneStone.
|
||||
2. Run `pnpm release:sdk --release-url <folder URL> --version <version> --dry-run`. Read the plan.
|
||||
The folder URL is the download folder of the release, for example `https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/plugin-sdk-v0.1.2`.
|
||||
3. Run the same command without `--dry-run`.
|
||||
4. On the RuneStone releases page, create a release with the tag `plugin-sdk-v<version>` on the `source` commit in `sdk.json`.
|
||||
5. Attach only the `.tgz` file. Leave the release description empty.
|
||||
6. Make sure that the `url` in `sdk.json` downloads the file without a sign-in, and that its SHA-256 matches.
|
||||
7. Commit the new version in `packages/plugin-sdk/package.json`.
|
||||
|
||||
The script builds the SDK, then replaces the released files in the clone. It commits them with the RuneStone commit in the message.
|
||||
Then it creates the annotated tag `v<version>`.
|
||||
The new version goes into `packages/plugin-sdk/package.json` only after the tag exists.
|
||||
If a step fails, the script restores that version field. It also resets the clone to its commit before the attempt.
|
||||
The script builds the SDK and writes two files in `releases/plugin-sdk/<version>/`:
|
||||
|
||||
| File | Contents |
|
||||
| --- | --- |
|
||||
| `runestone-plugin-sdk-<version>.tgz` | The package: `dist/`, `package.json`, `README.md`, `LICENSE`, and `NOTICE`, in a `package/` folder |
|
||||
| `sdk.json` | The URL, the size, the SHA-256, the npm integrity value, and the source commit |
|
||||
|
||||
The package files have a fixed time and mode, so the same files give the same package bytes.
|
||||
The new version goes into `packages/plugin-sdk/package.json` only after both files exist.
|
||||
If a step fails, the script restores that version field and removes the files of that attempt.
|
||||
|
||||
The script stops before it changes a file in these conditions:
|
||||
|
||||
| Condition | Action |
|
||||
| --- | --- |
|
||||
| The version is not greater than the version in `packages/plugin-sdk/package.json` or in the clone | Give a greater version. |
|
||||
| The version is not greater than the version in `packages/plugin-sdk/package.json` | Give a greater version. |
|
||||
| `packages/plugin-sdk/` has no `LICENSE` or `README.md` file | Add the file. The SDK uses the Apache License 2.0. |
|
||||
| `packages/plugin-sdk/` has changes that are not committed | Commit them, so that the release has a source commit. |
|
||||
| The clone is missing or is not the root of a Git repository | Clone the public repository, or set `RUNESTONE_SDK_REPO`. |
|
||||
| The clone has changes, or it is not on a branch | Commit or remove the changes. Check out the release branch. |
|
||||
| The tag `v<version>` exists in the clone | Give a new version. Never move or replace a published tag. |
|
||||
| The release URL is not HTTPS, or it has credentials, a query, or a fragment | Give the plain HTTPS URL of the release folder. |
|
||||
| A file exists in `releases/plugin-sdk/<version>/` | Give a new version. Never replace a published package. |
|
||||
|
||||
The tag is the release. Do not attach files to a repository release for the SDK, and do not put SDK files in `releases/`.
|
||||
To move the SDK to another service, or to mirror it, push the same commits and tags. Plugin authors then change only the repository URL.
|
||||
Keep each published SDK package unchanged. A plugin lock file records the integrity value of the package, so a different file at the same URL stops its installation.
|
||||
To move the SDK to another service, upload the same files there. Plugin authors then change only the URL.
|
||||
|
||||
@@ -14,10 +14,10 @@ The SDK does not run plugins and does not call RuneStone. RuneStone gives the `a
|
||||
|
||||
## Install
|
||||
|
||||
Install the SDK from a release tag of its Git repository. The SDK is not on the npm registry.
|
||||
Install the SDK from the URL of its package file on the RuneStone releases page.
|
||||
|
||||
```sh
|
||||
pnpm add -D "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.1"
|
||||
pnpm add -D "https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/plugin-sdk-v0.1.2/runestone-plugin-sdk-0.1.2.tgz"
|
||||
```
|
||||
|
||||
The result in `package.json`:
|
||||
@@ -25,13 +25,14 @@ The result in `package.json`:
|
||||
```json
|
||||
{
|
||||
"devDependencies": {
|
||||
"@runestone/plugin-sdk": "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.1"
|
||||
"@runestone/plugin-sdk": "https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/plugin-sdk-v0.1.2/runestone-plugin-sdk-0.1.2.tgz"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The repository is public, so you need no access token and no `.npmrc` file. npm and Yarn accept the same URL.
|
||||
Always give a tag. Without a tag, the package manager uses the latest commit, and your build can change without notice.
|
||||
Always give the full URL. The SDK is not on the npm registry, and another account owns the `@runestone` scope there.
|
||||
The download needs no access token and no `.npmrc` file. npm accepts the same URL.
|
||||
Your lock file records the integrity value of the package, so the installation stops if the file changes.
|
||||
The package contains compiled JavaScript and declaration files, so the installation runs no build step.
|
||||
|
||||
Use TypeScript 5.0 or later, with `moduleResolution` set to `bundler`, `node16`, or `nodenext`. Include the `DOM` library.
|
||||
@@ -119,7 +120,7 @@ For menus, call `api.ui.showActionMenu`. RuneStone draws the menu, so the SDK co
|
||||
|
||||
## Versions
|
||||
|
||||
The SDK has its own version number in the form `zz.yy.xx`, for example `0.1.0`. Each release has the tag `v<version>`.
|
||||
The SDK has its own version number in the form `zz.yy.xx`, for example `0.1.0`. Each release has the tag `plugin-sdk-v<version>` on the RuneStone releases page.
|
||||
A hotfix adds a lowercase letter to the version, for example `0.1.0a`.
|
||||
|
||||
`API_VERSION` is the `apiVersion` value of `plugin.json`. The SDK version and the RuneStone version are different numbers.
|
||||
@@ -133,7 +134,6 @@ A new SDK release can add types for new RuneStone features. Use the feature chec
|
||||
- [Release policy](https://git.knottywyvern.com/kwyvern/RuneStone/src/branch/master/docs/releases.md#sdk-releases)
|
||||
|
||||
The SDK source is in the `packages/plugin-sdk` folder of the [RuneStone repository](https://git.knottywyvern.com/kwyvern/RuneStone). Report problems there.
|
||||
This repository holds only the released files.
|
||||
|
||||
Knotty Wyvern maintains RuneStone and the SDK.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@runestone/plugin-sdk",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"description": "Types and helpers for RuneStone plugins",
|
||||
"license": "Apache-2.0",
|
||||
|
||||
+105
-92
@@ -1,29 +1,33 @@
|
||||
// Releases the plugin SDK into a local clone of its public repository. See docs/releases.md#sdk-releases.
|
||||
// Usage: node scripts/releaseSdk.mjs --version <version> [--dry-run]
|
||||
// The script commits and tags in the clone. It never pushes. It prints the push commands.
|
||||
// Packs the plugin SDK into a release file that plugins install from its URL. See docs/releases.md#sdk-releases.
|
||||
// Usage: node scripts/releaseSdk.mjs --release-url <folder URL> --version <version> [--dry-run]
|
||||
// The script writes releases/plugin-sdk/<version>/. It never uploads. It prints the dependency line for plugins.
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import zlib from 'node:zlib';
|
||||
import { execFile } from 'node:child_process';
|
||||
import { realpathSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { compareReleases, releaseVersion } from './releaseVersion.mjs';
|
||||
import { buildSdk, sdkFolder } from './buildSdk.mjs';
|
||||
|
||||
const exists = file => fs.access(file).then(() => true, () => false);
|
||||
export const packageName = '@runestone/plugin-sdk';
|
||||
export const repositoryName = 'RuneStone_Plugin_SDK';
|
||||
export const publicRepository = 'https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git';
|
||||
// The files that the release puts at the root of the public repository. LICENSE is required. NOTICE is optional.
|
||||
export const releaseFiles = ['dist', 'package.json', 'README.md', 'LICENSE', 'NOTICE'];
|
||||
// The files beside dist/ and package.json in the package. LICENSE and README.md are required. NOTICE is optional.
|
||||
export const packageFiles = ['README.md', 'LICENSE', 'NOTICE'];
|
||||
// The fixed file time of npm packages, 1985-10-26 08:15 UTC, in seconds.
|
||||
export const packageTime = 499162500;
|
||||
|
||||
export function parseArguments(args) {
|
||||
const options = { version: undefined, dryRun: false };
|
||||
const options = { version: undefined, releaseUrl: undefined, dryRun: false };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--dry-run') options.dryRun = true;
|
||||
else if (args[i] === '--version' && args[i + 1] && !options.version) options.version = args[++i];
|
||||
else throw Error('Use --version followed by the SDK version, and optionally --dry-run.');
|
||||
else if (args[i] === '--release-url' && args[i + 1] && !options.releaseUrl) options.releaseUrl = args[++i];
|
||||
else throw Error('Use --release-url followed by the release folder URL, --version followed by the SDK version, and optionally --dry-run.');
|
||||
}
|
||||
if (!options.version) throw Error('Use --version followed by the SDK version, for example --version 0.1.0.');
|
||||
if (!options.releaseUrl) throw Error('Use --release-url followed by the URL of the folder that will hold the SDK package.');
|
||||
if (!options.version) throw Error('Use --version followed by the SDK version, for example --version 0.1.2.');
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -36,13 +40,6 @@ export function git(cwd, args) {
|
||||
});
|
||||
});
|
||||
}
|
||||
const gitOptional = (cwd, args) => git(cwd, args).catch(() => null);
|
||||
|
||||
// The local clone of the public repository: RUNESTONE_SDK_REPO, or RuneStone_Plugin_SDK beside the plugin checkouts.
|
||||
export function clonePath(root, env = process.env) {
|
||||
if (env.RUNESTONE_SDK_REPO) return path.resolve(env.RUNESTONE_SDK_REPO);
|
||||
return path.join(path.resolve(env.RUNESTONE_PLUGIN_REPOS || path.dirname(root)), repositoryName);
|
||||
}
|
||||
|
||||
// The package.json of the release: the source fields with the new version, without build scripts or development dependencies.
|
||||
export function releasePackageJson(source, version) {
|
||||
@@ -52,9 +49,55 @@ export function releasePackageJson(source, version) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** The file name that `npm pack` gives a package: `@scope/name` becomes `scope-name-<version>.tgz`. */
|
||||
export function packageFileName(name, version) {
|
||||
return `${name.replace(/^@/, '').replace('/', '-')}-${version}.tgz`;
|
||||
}
|
||||
|
||||
/** A gzip tar of the entries under `package/`, in name order, with a fixed time and mode. The same entries give the same bytes. */
|
||||
export function packEntries(entries) {
|
||||
const blocks = [];
|
||||
const sorted = [...entries].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
||||
for (let i = 1; i < sorted.length; i++) if (sorted[i].name === sorted[i - 1].name) throw Error('The SDK package has two files with the name ' + sorted[i].name);
|
||||
for (const { name, data } of sorted) {
|
||||
const full = Buffer.from('package/' + name, 'utf8');
|
||||
if (full.length > 100) throw Error('The SDK has a file name that is too long for the package: ' + name);
|
||||
if (data.length >= 8 ** 11) throw Error('The SDK has a file that is too large for the package: ' + name);
|
||||
// A ustar header: name, mode, owner, group, size, time, checksum, type, and the magic value.
|
||||
const header = Buffer.alloc(512);
|
||||
full.copy(header, 0);
|
||||
const octal = (value, offset, size) => header.write(value.toString(8).padStart(size - 1, '0') + '\0', offset, size, 'ascii');
|
||||
octal(0o644, 100, 8); octal(0, 108, 8); octal(0, 116, 8); octal(data.length, 124, 12); octal(packageTime, 136, 12);
|
||||
header.write(' ', 148, 8, 'ascii');
|
||||
header.write('0', 156, 1, 'ascii');
|
||||
header.write('ustar\0' + '00', 257, 8, 'ascii');
|
||||
let sum = 0;
|
||||
for (const byte of header) sum += byte;
|
||||
header.write(sum.toString(8).padStart(6, '0') + '\0 ', 148, 8, 'ascii');
|
||||
blocks.push(header, data, Buffer.alloc((512 - data.length % 512) % 512));
|
||||
}
|
||||
blocks.push(Buffer.alloc(1024));
|
||||
return zlib.gzipSync(Buffer.concat(blocks), { level: 9 });
|
||||
}
|
||||
|
||||
/** The SHA-512 value that npm and pnpm record in a lock file. */
|
||||
export const integrity = data => 'sha512-' + createHash('sha512').update(data).digest('base64');
|
||||
|
||||
async function listFiles(folder, prefix = '') {
|
||||
const result = [];
|
||||
for (const entry of await fs.readdir(path.join(folder, prefix), { withFileTypes: true })) {
|
||||
const name = prefix ? `${prefix}/${entry.name}` : entry.name;
|
||||
if (entry.isDirectory()) result.push(...await listFiles(folder, name));
|
||||
else if (entry.isFile()) result.push(name);
|
||||
else throw Error('The SDK build contains a link or a special file: ' + name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Checks the preconditions and returns the release plan. Changes no file.
|
||||
export async function planSdkRelease(root, requestedVersion, env = process.env) {
|
||||
const next = releaseVersion(requestedVersion);
|
||||
/** @param {string} root @param {{ version: string, releaseUrl: string }} options */
|
||||
export async function planSdkRelease(root, { version, releaseUrl }) {
|
||||
const next = releaseVersion(version);
|
||||
const packageDir = path.join(root, sdkFolder);
|
||||
const sourceFile = path.join(packageDir, 'package.json');
|
||||
const source = JSON.parse(await fs.readFile(sourceFile, 'utf8'));
|
||||
@@ -65,101 +108,71 @@ export async function planSdkRelease(root, requestedVersion, env = process.env)
|
||||
if (!(await exists(path.join(packageDir, file)))) throw Error(`The SDK package has no ${file} file. Add ${path.join(sdkFolder, file)} before a release.`);
|
||||
}
|
||||
const copies = [];
|
||||
for (const file of releaseFiles) if (file !== 'dist' && file !== 'package.json' && await exists(path.join(packageDir, file))) copies.push(file);
|
||||
for (const file of packageFiles) if (await exists(path.join(packageDir, file))) copies.push(file);
|
||||
if ((await git(root, ['status', '--porcelain', '--untracked-files=all', '--', sdkFolder])) !== '') {
|
||||
throw Error(`${sdkFolder} has changes that are not committed. Commit them first, so that the release has a source commit.`);
|
||||
}
|
||||
const hostCommit = await git(root, ['rev-parse', 'HEAD']);
|
||||
|
||||
const clone = clonePath(root, env);
|
||||
if (!(await exists(clone))) throw Error(`The SDK repository clone is missing: ${clone}. Clone ${publicRepository} there, or set RUNESTONE_SDK_REPO.`);
|
||||
const top = await gitOptional(clone, ['rev-parse', '--show-toplevel']);
|
||||
if (!top || realpathSync.native(top) !== realpathSync.native(clone)) throw Error(`${clone} is not the root of a Git repository.`);
|
||||
if ((await git(clone, ['status', '--porcelain', '--untracked-files=all'])) !== '') throw Error(`The SDK repository clone has changes: ${clone}. Commit or remove them first.`);
|
||||
const branch = await gitOptional(clone, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
||||
if (!branch) throw Error(`The SDK repository clone is not on a branch: ${clone}.`);
|
||||
const head = await gitOptional(clone, ['rev-parse', '--verify', '--quiet', 'HEAD']);
|
||||
const tag = 'v' + next.version;
|
||||
if (await gitOptional(clone, ['rev-parse', '--verify', '--quiet', 'refs/tags/' + tag])) throw Error(`The tag ${tag} exists in ${clone}. A release never replaces a tag.`);
|
||||
const published = await fs.readFile(path.join(clone, 'package.json'), 'utf8').then(text => JSON.parse(text).version, () => null);
|
||||
if (published && compareReleases(next.version, published) <= 0) throw Error(`The SDK version must be greater than the version ${published} in the clone.`);
|
||||
const remotes = (await git(clone, ['remote'])).split(/\r?\n/).filter(Boolean);
|
||||
|
||||
const quoted = `"${clone}"`;
|
||||
const folder = new URL(releaseUrl.endsWith('/') ? releaseUrl : releaseUrl + '/');
|
||||
if (folder.protocol !== 'https:' || folder.username || folder.password || folder.search || folder.hash) {
|
||||
throw Error('Use an HTTPS release URL without credentials, a query, or a fragment.');
|
||||
}
|
||||
const file = packageFileName(packageName, next.version);
|
||||
const releaseDir = path.join(root, 'releases', 'plugin-sdk', next.version);
|
||||
const artifacts = { archive: path.join(releaseDir, file), metadata: path.join(releaseDir, 'sdk.json') };
|
||||
for (const artifact of Object.values(artifacts)) if (await exists(artifact)) throw Error('The release file already exists: ' + artifact);
|
||||
return {
|
||||
root, packageDir, sourceFile, source, current, next, clone, branch, head, tag, hostCommit, copies,
|
||||
root, packageDir, sourceFile, source, current, next, copies, file, releaseDir, artifacts,
|
||||
url: new URL(file, folder).href,
|
||||
hostCommit: await git(root, ['rev-parse', 'HEAD']),
|
||||
packageJson: releasePackageJson(source, next.version),
|
||||
commitMessage: `Release ${packageName} ${next.version}\n\nBuilt from RuneStone ${hostCommit}.`,
|
||||
pushCommands: [
|
||||
...(remotes.includes('origin') ? [] : [`git -C ${quoted} remote add origin ${publicRepository}`]),
|
||||
`git -C ${quoted} push origin ${branch}`,
|
||||
`git -C ${quoted} push origin ${tag}`,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function describePlan(plan) {
|
||||
const relative = file => path.relative(plan.root, file);
|
||||
return [
|
||||
`SDK version: ${plan.next.version} (current ${plan.current.version})`,
|
||||
`Source: ${path.relative(plan.root, plan.packageDir) || '.'} at RuneStone ${plan.hostCommit}`,
|
||||
`Clone: ${plan.clone} (branch ${plan.branch}${plan.head ? '' : ', no commits'})`,
|
||||
`Source: ${relative(plan.packageDir) || '.'} at RuneStone ${plan.hostCommit}`,
|
||||
`1. Build ${sdkFolder}/dist.`,
|
||||
`2. Replace ${['dist', 'package.json', ...plan.copies].join(', ')} in the clone.`,
|
||||
`3. Commit "${plan.commitMessage.split('\n')[0]}" and create the tag ${plan.tag}.`,
|
||||
`4. Write the version ${plan.next.version} to ${sdkFolder}/package.json.`,
|
||||
'The script does not push. After the release, run:',
|
||||
...plan.pushCommands.map(command => ' ' + command),
|
||||
`2. Write ${relative(plan.artifacts.archive)} with dist, package.json, ${plan.copies.join(', ')}, and ${relative(plan.artifacts.metadata)}.`,
|
||||
`3. Write the version ${plan.next.version} to ${sdkFolder}/package.json.`,
|
||||
`Plugins then use: "${packageName}": "${plan.url}"`,
|
||||
'The script does not upload the file.',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
async function copyFolder(from, to) {
|
||||
await fs.mkdir(to, { recursive: true });
|
||||
for (const entry of await fs.readdir(from, { withFileTypes: true })) {
|
||||
const source = path.join(from, entry.name), target = path.join(to, entry.name);
|
||||
if (entry.isDirectory()) await copyFolder(source, target);
|
||||
else if (entry.isFile()) await fs.copyFile(source, target);
|
||||
else throw Error('The SDK build contains a link or a special file: ' + source);
|
||||
}
|
||||
}
|
||||
|
||||
// Puts the clone back to its state before the release. The clone was clean at the start, so this removes only release changes.
|
||||
async function restoreClone(plan, tagged) {
|
||||
const { clone, head, tag } = plan;
|
||||
if (tagged) await gitOptional(clone, ['tag', '-d', tag]);
|
||||
if (head) await gitOptional(clone, ['reset', '--quiet', '--hard', head]);
|
||||
else {
|
||||
await gitOptional(clone, ['update-ref', '-d', 'HEAD']);
|
||||
await gitOptional(clone, ['rm', '-r', '-q', '--cached', '--ignore-unmatch', '.']);
|
||||
}
|
||||
await gitOptional(clone, ['clean', '-f', '-d', '-q']);
|
||||
}
|
||||
|
||||
// Runs the release. build(root) returns the dist folder. The source version changes only when the tag exists.
|
||||
// Runs the release. build(root) returns the dist folder. The source version changes only when the release files exist.
|
||||
export async function runSdkRelease(plan, build = buildSdk) {
|
||||
const before = await fs.readFile(plan.sourceFile, 'utf8');
|
||||
let changedClone = false, tagged = false, complete = false;
|
||||
const written = [];
|
||||
let complete = false;
|
||||
try {
|
||||
const dist = await build(plan.root);
|
||||
for (const file of ['index.js', 'index.d.ts']) await fs.access(path.join(dist, file));
|
||||
changedClone = true;
|
||||
await fs.rm(path.join(plan.clone, 'dist'), { recursive: true, force: true });
|
||||
await copyFolder(dist, path.join(plan.clone, 'dist'));
|
||||
await fs.writeFile(path.join(plan.clone, 'package.json'), JSON.stringify(plan.packageJson, null, 2) + '\n');
|
||||
for (const file of plan.copies) await fs.copyFile(path.join(plan.packageDir, file), path.join(plan.clone, file));
|
||||
// -f adds the files also when a .gitignore file in the clone lists dist/.
|
||||
await git(plan.clone, ['add', '-A', '-f', '--', 'dist', 'package.json', ...plan.copies]);
|
||||
await git(plan.clone, ['commit', '--quiet', '-m', plan.commitMessage]);
|
||||
await git(plan.clone, ['tag', '-a', plan.tag, '-m', `${packageName} ${plan.next.version}`]);
|
||||
tagged = true;
|
||||
const entries = [{ name: 'package.json', data: Buffer.from(JSON.stringify(plan.packageJson, null, 2) + '\n') }];
|
||||
for (const file of plan.copies) entries.push({ name: file, data: await fs.readFile(path.join(plan.packageDir, file)) });
|
||||
for (const file of await listFiles(dist)) entries.push({ name: 'dist/' + file, data: await fs.readFile(path.join(dist, ...file.split('/'))) });
|
||||
const archive = packEntries(entries);
|
||||
await fs.mkdir(plan.releaseDir, { recursive: true });
|
||||
await fs.writeFile(plan.artifacts.archive, archive, { flag: 'wx' });
|
||||
written.push(plan.artifacts.archive);
|
||||
const metadata = {
|
||||
name: packageName, version: plan.next.version, file: plan.file, url: plan.url, bytes: archive.length,
|
||||
sha256: createHash('sha256').update(archive).digest('hex'), integrity: integrity(archive), source: plan.hostCommit,
|
||||
};
|
||||
await fs.writeFile(plan.artifacts.metadata, JSON.stringify(metadata, null, 2) + '\n', { flag: 'wx' });
|
||||
written.push(plan.artifacts.metadata);
|
||||
await fs.writeFile(plan.sourceFile, before.replace(/("version":\s*")[^"]+(")/, `$1${plan.next.version}$2`));
|
||||
if (JSON.parse(await fs.readFile(plan.sourceFile, 'utf8')).version !== plan.next.version) throw Error('The SDK version field did not change.');
|
||||
complete = true;
|
||||
return { tag: plan.tag, commit: await git(plan.clone, ['rev-parse', 'HEAD']) };
|
||||
return { archive: plan.artifacts.archive, ...metadata };
|
||||
} finally {
|
||||
if (!complete) {
|
||||
if ((await fs.readFile(plan.sourceFile, 'utf8').catch(() => null)) !== before) await fs.writeFile(plan.sourceFile, before);
|
||||
if (changedClone) await restoreClone(plan, tagged);
|
||||
console.error('The SDK release did not complete. The version and the clone are restored.');
|
||||
// Only the files of this attempt go. A failed attempt does not use up the version.
|
||||
for (const file of written) await fs.rm(file, { force: true });
|
||||
await fs.rmdir(plan.releaseDir).catch(() => {});
|
||||
console.error('The SDK release did not complete. The version is restored, and the files of this attempt are removed.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,16 +180,16 @@ export async function runSdkRelease(plan, build = buildSdk) {
|
||||
async function main() {
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const options = parseArguments(process.argv.slice(2));
|
||||
const plan = await planSdkRelease(root, options.version);
|
||||
const plan = await planSdkRelease(root, options);
|
||||
console.log(describePlan(plan));
|
||||
if (options.dryRun) {
|
||||
console.log('Dry run: no file changed.');
|
||||
return;
|
||||
}
|
||||
const result = await runSdkRelease(plan);
|
||||
console.log(`\n${packageName} ${plan.next.version} is committed and tagged ${result.tag} (${result.commit}) in ${plan.clone}.`);
|
||||
console.log('Push the branch and the tag:');
|
||||
for (const command of plan.pushCommands) console.log(' ' + command);
|
||||
console.log(`\nSDK package: ${result.archive}\n${result.bytes} bytes, SHA-256 ${result.sha256}\nIntegrity: ${result.integrity}`);
|
||||
console.log(`Upload it to ${result.url}`);
|
||||
console.log(`Plugins use: "${packageName}": "${result.url}"`);
|
||||
console.log(`Then commit the new version in ${sdkFolder}/package.json in RuneStone.`);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,50 +3,37 @@ import assert from "node:assert/strict";
|
||||
import { mkdtemp, mkdir, readFile, writeFile, copyFile, rm, access, readdir } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { clonePath, describePlan, git, parseArguments, planSdkRelease, releasePackageJson, runSdkRelease } from "../../../scripts/releaseSdk.mjs";
|
||||
import zlib from "node:zlib";
|
||||
import { createHash } from "node:crypto";
|
||||
import { describePlan, git, integrity, packEntries, packageFileName, packageTime, parseArguments, planSdkRelease, releasePackageJson, runSdkRelease } from "../../../scripts/releaseSdk.mjs";
|
||||
|
||||
// These tests use temporary Git repositories. They need no network and never push.
|
||||
// These tests use a temporary Git repository. They need no network and upload nothing.
|
||||
const repository = path.resolve(".");
|
||||
const sdk = "packages/plugin-sdk";
|
||||
const releaseUrl = "https://example.com/releases/download/plugin-sdk-v0.1.0";
|
||||
const exists = (file: string) => access(file).then(() => true, () => false);
|
||||
const identity = async (folder: string) => {
|
||||
await git(folder, ["config", "user.name", "SDK test"]);
|
||||
await git(folder, ["config", "user.email", "[email protected]"]);
|
||||
};
|
||||
|
||||
type Setup = { base: string; root: string; clone: string; remote: string; env: Record<string, string> };
|
||||
type Setup = { base: string; root: string };
|
||||
|
||||
// A host repository with the SDK package files, a clone of the public repository, and a bare remote for that clone.
|
||||
async function fixture(options: { empty?: boolean; origin?: boolean } = {}): Promise<Setup> {
|
||||
// A host repository with the SDK package files at version 0.0.0.
|
||||
async function fixture(): Promise<Setup> {
|
||||
const base = await mkdtemp(path.join(tmpdir(), "runestone-sdk-release-"));
|
||||
const root = path.join(base, "RuneStone");
|
||||
await mkdir(path.join(root, sdk), { recursive: true });
|
||||
for (const file of ["package.json", "README.md", "LICENSE", "NOTICE"]) await copyFile(path.join(repository, sdk, file), path.join(root, sdk, file));
|
||||
const source = JSON.parse(await readFile(path.join(root, sdk, "package.json"), "utf8"));
|
||||
await writeFile(path.join(root, sdk, "package.json"), JSON.stringify({ ...source, version: "0.0.0", scripts: { build: "tsc" }, devDependencies: { typescript: "6" } }, null, 2) + "\n");
|
||||
await writeFile(path.join(root, ".gitignore"), "dist/\n");
|
||||
await writeFile(path.join(root, ".gitignore"), "dist/\nreleases/\n");
|
||||
await git(root, ["init", "-q", "-b", "master"]);
|
||||
await identity(root);
|
||||
await git(root, ["config", "user.name", "SDK test"]);
|
||||
await git(root, ["config", "user.email", "[email protected]"]);
|
||||
await git(root, ["add", "-A"]);
|
||||
await git(root, ["commit", "-q", "-m", "host"]);
|
||||
|
||||
const remote = path.join(base, "remote.git");
|
||||
await git(base, ["init", "-q", "--bare", remote]);
|
||||
const clone = path.join(base, "RuneStone_Plugin_SDK");
|
||||
await mkdir(clone);
|
||||
await git(clone, ["init", "-q", "-b", "main"]);
|
||||
await identity(clone);
|
||||
if (options.origin !== false) await git(clone, ["remote", "add", "origin", remote]);
|
||||
if (!options.empty) {
|
||||
await writeFile(path.join(clone, ".gitignore"), "dist/\nnode_modules/\n");
|
||||
await git(clone, ["add", "-A"]);
|
||||
await git(clone, ["commit", "-q", "-m", "Start"]);
|
||||
}
|
||||
return { base, root, clone, remote, env: { RUNESTONE_PLUGIN_REPOS: base } };
|
||||
return { base, root };
|
||||
}
|
||||
|
||||
async function withFixture(options: { empty?: boolean; origin?: boolean }, body: (setup: Setup) => Promise<void>) {
|
||||
const setup = await fixture(options);
|
||||
async function withFixture(body: (setup: Setup) => Promise<void>) {
|
||||
const setup = await fixture();
|
||||
try { await body(setup); } finally { await rm(setup.base, { recursive: true, force: true }); }
|
||||
}
|
||||
|
||||
@@ -61,32 +48,38 @@ const fakeBuild = async (root: string) => {
|
||||
};
|
||||
const failingBuild = async () => { throw Error("The compiler failed."); };
|
||||
|
||||
async function state(setup: Setup) {
|
||||
return {
|
||||
source: await readFile(path.join(setup.root, sdk, "package.json"), "utf8"),
|
||||
head: await git(setup.clone, ["rev-parse", "--verify", "--quiet", "HEAD"]).catch(() => null),
|
||||
status: await git(setup.clone, ["status", "--porcelain", "--untracked-files=all"]),
|
||||
tags: await git(setup.clone, ["tag", "--list"]),
|
||||
files: (await readdir(setup.clone)).sort(),
|
||||
};
|
||||
// Reads the files of a gzip tar: the name, mode, time, and contents of each entry.
|
||||
function unpack(archive: Buffer) {
|
||||
const tar = zlib.gunzipSync(archive);
|
||||
const entries: { name: string; mode: number; time: number; type: string; data: string }[] = [];
|
||||
for (let offset = 0; offset + 512 <= tar.length; ) {
|
||||
const header = tar.subarray(offset, offset + 512);
|
||||
if (header.every(byte => byte === 0)) break;
|
||||
const field = (start: number, size: number) => header.subarray(start, start + size).toString("ascii").replace(/\0.*$/s, "").trim();
|
||||
let sum = 0;
|
||||
for (let i = 0; i < 512; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
|
||||
assert.equal(parseInt(field(148, 8), 8), sum, "The header checksum must match.");
|
||||
assert.equal(field(257, 6), "ustar");
|
||||
const size = parseInt(field(124, 12), 8);
|
||||
entries.push({ name: field(0, 100), mode: parseInt(field(100, 8), 8), time: parseInt(field(136, 12), 8), type: field(156, 1),
|
||||
data: tar.subarray(offset + 512, offset + 512 + size).toString("utf8") });
|
||||
offset += 512 + Math.ceil(size / 512) * 512;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
const quiet = async <T>(work: () => Promise<T>) => {
|
||||
const error = console.error;
|
||||
console.error = () => {};
|
||||
try { return await work(); } finally { console.error = error; }
|
||||
};
|
||||
|
||||
test("the SDK release script reads --version and --dry-run", () => {
|
||||
assert.deepEqual(parseArguments(["--version", "0.1.0"]), { version: "0.1.0", dryRun: false });
|
||||
assert.deepEqual(parseArguments(["--dry-run", "--version", "0.1.0a"]), { version: "0.1.0a", dryRun: true });
|
||||
for (const args of [[], ["--dry-run"], ["--version"], ["0.1.0"], ["--version", "0.1.0", "--version", "0.1.1"], ["--push"]]) assert.throws(() => parseArguments(args));
|
||||
});
|
||||
|
||||
test("the clone path comes from RUNESTONE_SDK_REPO, then RUNESTONE_PLUGIN_REPOS, then the parent folder", () => {
|
||||
const root = path.resolve("/work/RuneStone");
|
||||
assert.equal(clonePath(root, { RUNESTONE_SDK_REPO: "/elsewhere/sdk", RUNESTONE_PLUGIN_REPOS: "/plugins" }), path.resolve("/elsewhere/sdk"));
|
||||
assert.equal(clonePath(root, { RUNESTONE_PLUGIN_REPOS: "/plugins" }), path.join(path.resolve("/plugins"), "RuneStone_Plugin_SDK"));
|
||||
assert.equal(clonePath(root, {}), path.join(path.resolve("/work"), "RuneStone_Plugin_SDK"));
|
||||
test("the SDK release script reads --release-url, --version, and --dry-run", () => {
|
||||
assert.deepEqual(parseArguments(["--release-url", releaseUrl, "--version", "0.1.0"]), { version: "0.1.0", releaseUrl, dryRun: false });
|
||||
assert.deepEqual(parseArguments(["--dry-run", "--version", "0.1.0a", "--release-url", releaseUrl]), { version: "0.1.0a", releaseUrl, dryRun: true });
|
||||
for (const args of [[], ["--version", "0.1.0"], ["--release-url", releaseUrl], ["--version"], ["0.1.0"], ["--release-url", releaseUrl, "--version", "0.1.0", "--version", "0.1.1"], ["--push"]]) {
|
||||
assert.throws(() => parseArguments(args));
|
||||
}
|
||||
});
|
||||
|
||||
test("the release package.json has the version and no build scripts or development dependencies", () => {
|
||||
@@ -95,102 +88,102 @@ test("the release package.json has the version and no build scripts or developme
|
||||
assert.throws(() => releasePackageJson({ ...source, license: undefined }, "0.1.0"), /license/);
|
||||
});
|
||||
|
||||
test("a dry run plans the release, prints the push commands, and changes no file", () => withFixture({}, async setup => {
|
||||
const before = await state(setup);
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
test("the package file has the npm pack name", () => {
|
||||
assert.equal(packageFileName("@runestone/plugin-sdk", "0.1.0"), "runestone-plugin-sdk-0.1.0.tgz");
|
||||
assert.equal(packageFileName("plain", "1.0.0a"), "plain-1.0.0a.tgz");
|
||||
});
|
||||
|
||||
test("the package is a tar under package/ in name order, with a fixed time, and the same entries give the same bytes", () => {
|
||||
const entries = [
|
||||
{ name: "package.json", data: Buffer.from('{"name":"x"}\n') },
|
||||
{ name: "dist/index.js", data: Buffer.alloc(700, 97) },
|
||||
{ name: "README.md", data: Buffer.from("") },
|
||||
];
|
||||
const archive = packEntries(entries);
|
||||
assert.deepEqual(archive, packEntries([...entries].reverse()));
|
||||
const files = unpack(archive);
|
||||
assert.deepEqual(files.map(file => file.name), ["package/README.md", "package/dist/index.js", "package/package.json"]);
|
||||
for (const file of files) {
|
||||
assert.equal(file.mode, 0o644);
|
||||
assert.equal(file.time, packageTime);
|
||||
assert.equal(file.type, "0");
|
||||
}
|
||||
assert.equal(files[1].data, "a".repeat(700));
|
||||
assert.equal(integrity(archive), "sha512-" + createHash("sha512").update(archive).digest("base64"));
|
||||
assert.throws(() => packEntries([{ name: "x".repeat(93), data: Buffer.from("") }]), /too long/);
|
||||
assert.throws(() => packEntries([{ name: "a", data: Buffer.from("1") }, { name: "a", data: Buffer.from("2") }]), /two files/);
|
||||
});
|
||||
|
||||
test("a dry run plans the release, gives the plugin dependency line, and changes no file", () => withFixture(async setup => {
|
||||
const before = await readFile(path.join(setup.root, sdk, "package.json"), "utf8");
|
||||
const plan = await planSdkRelease(setup.root, { version: "0.1.0", releaseUrl });
|
||||
const text = describePlan(plan);
|
||||
assert.match(text, /SDK version: 0\.1\.0 \(current 0\.0\.0\)/);
|
||||
assert.match(text, /Replace dist, package\.json, README\.md, LICENSE, NOTICE in the clone/);
|
||||
assert.match(text, /create the tag v0\.1\.0/);
|
||||
assert.deepEqual(plan.pushCommands, [`git -C "${setup.clone}" push origin main`, `git -C "${setup.clone}" push origin v0.1.0`]);
|
||||
assert.match(text, /with dist, package\.json, README\.md, LICENSE, NOTICE, and/);
|
||||
assert.equal(plan.url, `${releaseUrl}/runestone-plugin-sdk-0.1.0.tgz`);
|
||||
assert.match(text, /Plugins then use: "@runestone\/plugin-sdk": "https:\/\/example\.com\/releases\/download\/plugin-sdk-v0\.1\.0\/runestone-plugin-sdk-0\.1\.0\.tgz"/);
|
||||
assert.equal(plan.packageJson.version, "0.1.0");
|
||||
assert.equal(plan.packageJson.scripts, undefined);
|
||||
assert.equal(plan.packageJson.devDependencies, undefined);
|
||||
assert.deepEqual(await state(setup), before);
|
||||
assert.equal(await readFile(path.join(setup.root, sdk, "package.json"), "utf8"), before);
|
||||
assert.equal(await exists(path.join(setup.root, "releases")), false);
|
||||
}));
|
||||
|
||||
test("a clone without an origin remote gets the command that adds it", () => withFixture({ origin: false }, async setup => {
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
assert.match(plan.pushCommands[0], /remote add origin https:\/\/git\.knottywyvern\.com\/kwyvern\/RuneStone_Plugin_SDK\.git$/);
|
||||
test("the release refuses an HTTP URL, a URL with credentials, an earlier version, and an existing release file", () => withFixture(async setup => {
|
||||
for (const url of ["http://example.com/r", "https://user:[email protected]/r", "https://example.com/r?x=1", "https://example.com/r#x"]) {
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "0.1.0", releaseUrl: url }), /HTTPS release URL/);
|
||||
}
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "0.0.0", releaseUrl }), /greater than the current version 0\.0\.0/);
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "1.0", releaseUrl }), /release version/);
|
||||
await mkdir(path.join(setup.root, "releases/plugin-sdk/0.1.0"), { recursive: true });
|
||||
await writeFile(path.join(setup.root, "releases/plugin-sdk/0.1.0/sdk.json"), "{}");
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "0.1.0", releaseUrl }), /already exists/);
|
||||
}));
|
||||
|
||||
test("the release refuses a missing, unrelated, dirty, or detached clone", () => withFixture({}, async setup => {
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", { RUNESTONE_SDK_REPO: path.join(setup.base, "missing") }), /clone is missing/);
|
||||
const plain = path.join(setup.root, sdk);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", { RUNESTONE_SDK_REPO: plain }), /not the root of a Git repository/);
|
||||
await writeFile(path.join(setup.clone, "notes.txt"), "draft");
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /clone has changes/);
|
||||
await rm(path.join(setup.clone, "notes.txt"));
|
||||
await git(setup.clone, ["checkout", "-q", "--detach"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /not on a branch/);
|
||||
}));
|
||||
|
||||
test("the release never replaces a tag and never goes back to an earlier version", () => withFixture({}, async setup => {
|
||||
await git(setup.clone, ["tag", "v0.1.0"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /The tag v0\.1\.0 exists/);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.0.0", setup.env), /greater than the current version 0\.0\.0/);
|
||||
await assert.rejects(planSdkRelease(setup.root, "1.0", setup.env), /release version/);
|
||||
await writeFile(path.join(setup.clone, "package.json"), JSON.stringify({ version: "0.2.0" }));
|
||||
await git(setup.clone, ["add", "-A"]);
|
||||
await git(setup.clone, ["commit", "-q", "-m", "Earlier release"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.1", setup.env), /greater than the version 0\.2\.0 in the clone/);
|
||||
}));
|
||||
|
||||
test("the release refuses a package without a license file or with source changes that are not committed", () => withFixture({}, async setup => {
|
||||
test("the release refuses a package without a license file or with source changes that are not committed", () => withFixture(async setup => {
|
||||
await rm(path.join(setup.root, sdk, "LICENSE"));
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /no LICENSE file/);
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "0.1.0", releaseUrl }), /no LICENSE file/);
|
||||
await git(setup.root, ["checkout", "-q", "--", sdk]);
|
||||
await writeFile(path.join(setup.root, sdk, "README.md"), "changed");
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /not committed/);
|
||||
await assert.rejects(planSdkRelease(setup.root, { version: "0.1.0", releaseUrl }), /not committed/);
|
||||
}));
|
||||
|
||||
test("a completed release commits and tags in the clone, sets the source version, and pushes nothing", () => withFixture({}, async setup => {
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
test("a completed release writes the package and its record, then sets the source version", () => withFixture(async setup => {
|
||||
const plan = await planSdkRelease(setup.root, { version: "0.1.0", releaseUrl });
|
||||
const result = await runSdkRelease(plan, fakeBuild);
|
||||
assert.equal(result.tag, "v0.1.0");
|
||||
assert.equal(await git(setup.clone, ["status", "--porcelain", "--untracked-files=all"]), "");
|
||||
assert.equal(await git(setup.clone, ["cat-file", "-t", "v0.1.0"]), "tag");
|
||||
assert.equal(await git(setup.clone, ["rev-parse", "v0.1.0^{commit}"]), result.commit);
|
||||
const tracked = (await git(setup.clone, ["ls-files"])).split("\n").sort();
|
||||
assert.deepEqual(tracked, [".gitignore", "LICENSE", "NOTICE", "README.md", "dist/index.d.ts", "dist/index.js", "dist/nested/extra.js", "package.json"]);
|
||||
const published = JSON.parse(await readFile(path.join(setup.clone, "package.json"), "utf8"));
|
||||
assert.equal(published.version, "0.1.0");
|
||||
assert.equal(published.license, "Apache-2.0");
|
||||
assert.equal(published.scripts, undefined);
|
||||
assert.equal(await readFile(path.join(setup.clone, "LICENSE"), "utf8"), await readFile(path.join(setup.root, sdk, "LICENSE"), "utf8"));
|
||||
assert.match(await git(setup.clone, ["log", "-1", "--format=%B"]), new RegExp(`^Release @runestone/plugin-sdk 0\\.1\\.0\\n\\nBuilt from RuneStone ${plan.hostCommit}\\.`));
|
||||
const folder = path.join(setup.root, "releases/plugin-sdk/0.1.0");
|
||||
assert.deepEqual((await readdir(folder)).sort(), ["runestone-plugin-sdk-0.1.0.tgz", "sdk.json"]);
|
||||
const archive = await readFile(path.join(folder, "runestone-plugin-sdk-0.1.0.tgz"));
|
||||
const files = unpack(archive);
|
||||
assert.deepEqual(files.map(file => file.name), ["package/LICENSE", "package/NOTICE", "package/README.md", "package/dist/index.d.ts", "package/dist/index.js", "package/dist/nested/extra.js", "package/package.json"]);
|
||||
const packed = JSON.parse(files.find(file => file.name === "package/package.json")!.data);
|
||||
assert.equal(packed.version, "0.1.0");
|
||||
assert.equal(packed.scripts, undefined);
|
||||
assert.equal(files.find(file => file.name === "package/LICENSE")!.data, await readFile(path.join(setup.root, sdk, "LICENSE"), "utf8"));
|
||||
const record = JSON.parse(await readFile(path.join(folder, "sdk.json"), "utf8"));
|
||||
assert.deepEqual(record, {
|
||||
name: "@runestone/plugin-sdk", version: "0.1.0", file: "runestone-plugin-sdk-0.1.0.tgz", url: plan.url, bytes: archive.length,
|
||||
sha256: createHash("sha256").update(archive).digest("hex"), integrity: integrity(archive), source: plan.hostCommit,
|
||||
});
|
||||
assert.equal(result.sha256, record.sha256);
|
||||
assert.equal(JSON.parse(await readFile(path.join(setup.root, sdk, "package.json"), "utf8")).version, "0.1.0");
|
||||
assert.equal(await git(setup.remote, ["for-each-ref"]), "", "The release must not push.");
|
||||
|
||||
// The next release replaces dist/ and removes files that the new build does not contain.
|
||||
await git(setup.root, ["commit", "-q", "-am", "Record 0.1.0"]);
|
||||
const next = await planSdkRelease(setup.root, "0.1.1", setup.env);
|
||||
await runSdkRelease(next, async root => { const dist = await fakeBuild(root); await rm(path.join(dist, "nested"), { recursive: true }); return dist; });
|
||||
assert.equal(await exists(path.join(setup.clone, "dist/nested/extra.js")), false);
|
||||
assert.deepEqual((await git(setup.clone, ["tag", "--list"])).split("\n"), ["v0.1.0", "v0.1.1"]);
|
||||
}));
|
||||
|
||||
test("a failed build restores the version and leaves the clone unchanged", () => withFixture({}, async setup => {
|
||||
const before = await state(setup);
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
test("a failed build restores the version and writes no release file", () => withFixture(async setup => {
|
||||
const before = await readFile(path.join(setup.root, sdk, "package.json"), "utf8");
|
||||
const plan = await planSdkRelease(setup.root, { version: "0.1.0", releaseUrl });
|
||||
await quiet(() => assert.rejects(runSdkRelease(plan, failingBuild), /compiler failed/));
|
||||
assert.deepEqual(await state(setup), before);
|
||||
assert.equal(await readFile(path.join(setup.root, sdk, "package.json"), "utf8"), before);
|
||||
assert.equal(await exists(path.join(setup.root, "releases/plugin-sdk/0.1.0")), false);
|
||||
}));
|
||||
|
||||
test("a failed commit restores the clone, also in a clone without commits", async () => {
|
||||
for (const empty of [false, true]) {
|
||||
await withFixture({ empty }, async setup => {
|
||||
const before = await state(setup);
|
||||
await writeFile(path.join(setup.clone, ".git/hooks/pre-commit"), "#!/bin/sh\nexit 1\n");
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
assert.equal(plan.head, empty ? null : before.head);
|
||||
await quiet(() => assert.rejects(runSdkRelease(plan, fakeBuild), /git commit/));
|
||||
assert.deepEqual(await state(setup), before);
|
||||
await rm(path.join(setup.clone, ".git/hooks/pre-commit"));
|
||||
if (empty) {
|
||||
await runSdkRelease(await planSdkRelease(setup.root, "0.1.0", setup.env), fakeBuild);
|
||||
assert.equal(await git(setup.clone, ["rev-list", "--count", "HEAD"]), "1");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
test("a failure after the package is written removes the files of that attempt only", () => withFixture(async setup => {
|
||||
const before = await readFile(path.join(setup.root, sdk, "package.json"), "utf8");
|
||||
const plan = await planSdkRelease(setup.root, { version: "0.1.0", releaseUrl });
|
||||
// A record that appears after the plan makes the record write fail.
|
||||
await mkdir(plan.releaseDir, { recursive: true });
|
||||
await writeFile(plan.artifacts.metadata, "kept");
|
||||
await quiet(() => assert.rejects(runSdkRelease(plan, fakeBuild), /EEXIST/));
|
||||
assert.equal(await readFile(path.join(setup.root, sdk, "package.json"), "utf8"), before);
|
||||
assert.equal(await exists(plan.artifacts.archive), false);
|
||||
assert.equal(await readFile(plan.artifacts.metadata, "utf8"), "kept");
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user