@runeditrun/rer 0.2.113 → 0.2.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/cli/contract-status.mjs +1 -1
- package/cli/contract.mjs +1 -1
- package/cli/main.mjs +1 -0
- package/cli/parse.mjs +1 -1
- package/cli/rehearse/automation.mjs +29 -0
- package/cli/rehearse/environment.mjs +14 -0
- package/cli/rehearse/metadata.mjs +84 -0
- package/cli/rehearse/options.mjs +54 -0
- package/cli/rehearse/run.mjs +94 -0
- package/cli/rehearse/snapshot.mjs +60 -0
- package/cli/rehearse/workflow.mjs +42 -0
- package/cli/rehearse.mjs +20 -0
- package/cli/release-candidate.mjs +32 -0
- package/cli/release.mjs +4 -0
- package/edition-authoring/lock.mjs +26 -4
- package/global/CHANGELOG.md +22 -0
- package/global/README.md +51 -0
- package/global/main.mjs +4 -0
- package/modules/release/README.md +29 -0
- package/modules/release/candidate.mjs +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -727,3 +727,54 @@ runtime and type dependencies. The existing
|
|
|
727
727
|
`@runeditrun/rer/modules/import-kit/d1` entry remains available. See the
|
|
728
728
|
[adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
|
|
729
729
|
for native adapters, consent, declared intake projection and reviewed apply/Undo.
|
|
730
|
+
|
|
731
|
+
## Rehearse before signing a seed release
|
|
732
|
+
|
|
733
|
+
Run `rer rehearse --cwd /path/to/seed --ref HEAD` before announcing a release.
|
|
734
|
+
It exports the selected commit into a fresh repository outside the checkout,
|
|
735
|
+
with an empty `Initial commit` and one installation commit. The installation
|
|
736
|
+
projection removes publisher automation, preserves a dispatch-only managed
|
|
737
|
+
workflow, updates its recipe/copy metadata, adds schema-1 `rer-upstream.json`
|
|
738
|
+
(repository, tag/ref, exact source SHA), and regenerates changed lock identities
|
|
739
|
+
through Base's source-lock generator while retaining the publisher's source pins.
|
|
740
|
+
Uncommitted files and publisher history are absent. The source checkout is unchanged.
|
|
741
|
+
|
|
742
|
+
This installs dependencies and builds. Signers and seed lanes must use the heavy slot:
|
|
743
|
+
|
|
744
|
+
```sh
|
|
745
|
+
python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd /path/to/seed --ref HEAD
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
Use a committed clean worktree for remote routing and make the source available
|
|
749
|
+
on that runner. The command itself uses local Git objects and creates no remote;
|
|
750
|
+
only the declared operations may acquire dependencies over the network. Supply the
|
|
751
|
+
same Node and package-manager tools as the seed's trusted build. A fresh private
|
|
752
|
+
HOME/config/cache and a restricted environment keep caller provider credentials out.
|
|
753
|
+
The operations are trusted source code, not a sandbox for an untrusted seed.
|
|
754
|
+
|
|
755
|
+
Every declared `setup`, `build`, `verify`, `artifact` command runs in that order
|
|
756
|
+
from the scratch root, in its own `bash -e -o pipefail` process. Rehearsal continues
|
|
757
|
+
after failures, so one run reports every failing operation. A later command that
|
|
758
|
+
cannot start because a prior operation left a required input unavailable is
|
|
759
|
+
reported `NOT REACHED` with the missing-input diagnostic. Recovery prose is not
|
|
760
|
+
an executable operation. Shell variables and working-directory changes do not
|
|
761
|
+
carry between operations; filesystem changes do.
|
|
762
|
+
|
|
763
|
+
The summary prints PASS/FAIL/NOT REACHED, the first cause line and the full redacted
|
|
764
|
+
capture-log path. Logs survive scratch cleanup; `--keep` retains the repository and
|
|
765
|
+
its private HOME for diagnosis. `--operation-timeout-seconds N` defaults to 900;
|
|
766
|
+
`--timeout-seconds N` bounds preparation and all operations together (default 3600).
|
|
767
|
+
Both accept integer seconds from 1 to 86400. If no dispatch-only managed workflow
|
|
768
|
+
exists, provide the platform's immutable `--workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA`.
|
|
769
|
+
`--repository OWNER/REPO` overrides the descriptor's source repository identity.
|
|
770
|
+
A branch/ref in the rehearsal upstream record identifies unreleased source; it is
|
|
771
|
+
not a signed stable-release record.
|
|
772
|
+
|
|
773
|
+
Exit codes: 0 all pass; 1 an operation failed or was not reached; 2 invalid flags;
|
|
774
|
+
3 preparation/source/declaration failure; 124 overall timeout; 130/143 interruption.
|
|
775
|
+
A per-operation timeout is FAIL and exit 1. With `--json`, stdout contains one
|
|
776
|
+
version-1 `result` event with `ok`, `exitCode`, source/install identities, elapsed
|
|
777
|
+
`seconds`, `captureLog` and every operation's command, status, cause and child
|
|
778
|
+
exit/signal. `rer rehearse --help` lists the flags. This proves local declared
|
|
779
|
+
build operations under the recorded host conditions; GitHub attestation, artifact
|
|
780
|
+
upload and provider deployment remain separate.
|
package/cli/contract-status.mjs
CHANGED
|
@@ -26,7 +26,7 @@ async function isManagedCopy(root) {
|
|
|
26
26
|
const value = JSON.parse(await readFile(path, 'utf8'));
|
|
27
27
|
return !!value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).sort().join(',') === 'commit,repository,schema,tag'
|
|
28
28
|
&& value.schema === 1 && /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/.test(value.repository)
|
|
29
|
-
&& /^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(value.tag) && /^[a-f0-9]{40}$/i.test(value.commit);
|
|
29
|
+
&& /^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(value.tag) && /^[a-f0-9]{40}$/i.test(value.commit);
|
|
30
30
|
} catch { return false; }
|
|
31
31
|
}
|
|
32
32
|
|
package/cli/contract.mjs
CHANGED
|
@@ -40,7 +40,7 @@ export const releaseFlags = ['--repo', '--project', '--repository', '--output',
|
|
|
40
40
|
export const releaseVerb = Object.freeze({
|
|
41
41
|
bootstrap: 'before', flags: [...commonFlags, ...releaseFlags],
|
|
42
42
|
// These operate on supplied files and keys, without running project code.
|
|
43
|
-
subcommands: Object.freeze({ sign: { bootstrap: 'never' }, receipt: { bootstrap: 'never' }, keygen: { bootstrap: 'never' } }),
|
|
43
|
+
subcommands: Object.freeze({ candidate: { bootstrap: 'never' }, sign: { bootstrap: 'never' }, receipt: { bootstrap: 'never' }, keygen: { bootstrap: 'never' } }),
|
|
44
44
|
});
|
|
45
45
|
// All checkout commands, including those supplied by rer rather than declared
|
|
46
46
|
// as seed operations. Bootstrap belongs to the selected command: before
|
package/cli/main.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { selectNodeRuntime } from './node-runtime.mjs';
|
|
|
9
9
|
import { resolve } from 'node:path';
|
|
10
10
|
|
|
11
11
|
export async function main(argv = process.argv.slice(2)) {
|
|
12
|
+
if (argv[0] === 'rehearse') return (await import('./rehearse.mjs')).rehearseCommand(argv.slice(1));
|
|
12
13
|
if (argv[0] === 'door' && argv[1] === 'clauses') return (await import('./door-clauses.mjs')).doorClausesCommand(argv.slice(2));
|
|
13
14
|
if (argv[0] === 'business') return (await import('./business/command.mjs')).businessCommand(argv.slice(1));
|
|
14
15
|
if (argv[0] === 'companion') return (await import('./companion/command.mjs')).companionCommand(argv.slice(1));
|
package/cli/parse.mjs
CHANGED
|
@@ -109,7 +109,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export function help(verb) {
|
|
112
|
-
if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, size, release, listing\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
|
|
112
|
+
if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, size, release, listing, rehearse\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
|
|
113
113
|
const known = verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : verb === 'size' ? sizeVerb : undefined);
|
|
114
114
|
const door = ['export', 'import'].includes(verb) ? 'To move records, start the app and open its signed-in owner import door:\n\n rer dev\n\nOpen /app/import, then export or upload and review supported records there.\n\nTo back up or restore this installation:\n' : '';
|
|
115
115
|
return `${door}Usage: rer ${verb}${verb === 'refresh-base' ? ' --ref FULL_COMMIT' : ''} [FLAGS]\nFlags: ${(known?.flags ?? commonFlags).join(', ')}\n${known?.effects ?? 'Execute the declared OPERATIONS v2 argv with explicit arguments after --.'}\n`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Mirrors platform repository-automation.ts (bbf6ca98); keep installation projection behavior aligned.
|
|
2
|
+
export const MANAGED_WORKFLOW = '.github/workflows/rer-managed.yml'
|
|
3
|
+
|
|
4
|
+
/** Repository automation belongs to the publisher, not to each installed app. Application runtime
|
|
5
|
+
* schedules (Wrangler, deployment specs and scheduled handlers) are application source and stay intact. */
|
|
6
|
+
export function repositoryAutomation(path ) {
|
|
7
|
+
return path === '.github' || path === '.github/workflows' || path.startsWith('.github/workflows/')
|
|
8
|
+
|| /^(?:\.github\/)?(?:dependabot\.ya?ml|\.?renovate(?:rc)?(?:\.json5?)?)$/.test(path)
|
|
9
|
+
|| /^(?:\.circleci|\.buildkite|\.teamcity|\.gitlab)(?:\/|$)/.test(path)
|
|
10
|
+
|| /^(?:\.gitlab-ci\.ya?ml|azure-pipelines\.ya?ml|bitbucket-pipelines\.ya?ml|\.travis\.yml|\.drone\.ya?ml|\.woodpecker\.ya?ml|Jenkinsfile)$/.test(path)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A publisher's own delivery entry is kept verbatim, as installs did before automation was stripped, when GitHub
|
|
14
|
+
* can start it only by an explicit dispatch: its sole `on` event is workflow_dispatch. Anything else (push,
|
|
15
|
+
* pull_request, schedule, a flow mapping RER does not read) is replaced by RER's generated entry. */
|
|
16
|
+
export function dispatchOnlyWorkflow(bytes ) {
|
|
17
|
+
const lines = new TextDecoder().decode(bytes).split(/\r?\n/)
|
|
18
|
+
const top = lines.flatMap((line, index) => /^[^\s#]/.test(line) ? [{line, index}] : [])
|
|
19
|
+
const on = top.filter(({line}) => /^(?:on|'on'|"on")\s*:/.test(line))
|
|
20
|
+
if (on.length !== 1) return false
|
|
21
|
+
const inline = on[0].line.replace(/^[^:]+:/, '').replace(/\s#.*$/, '').trim()
|
|
22
|
+
if (inline) return /^(?:workflow_dispatch|\[\s*workflow_dispatch\s*\])$/.test(inline)
|
|
23
|
+
const end = top.find(({index}) => index > on[0].index)?.index ?? lines.length
|
|
24
|
+
const body = lines.slice(on[0].index + 1, end).filter(line => line.trim() && !/^\s*#/.test(line))
|
|
25
|
+
const depth = (line ) => line.length - line.trimStart().length
|
|
26
|
+
const indent = Math.min(...body.map(depth))
|
|
27
|
+
const events = body.filter(line => depth(line) === indent).map(line => line.trim().replace(/\s*:.*$/, ''))
|
|
28
|
+
return events.length === 1 && events[0] === 'workflow_dispatch'
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {join} from 'node:path';
|
|
2
|
+
|
|
3
|
+
// An allowlist keeps provider credentials, Git config and caller startup hooks out.
|
|
4
|
+
// HOME/config/cache are private and fresh; PATH supplies the caller's build tools.
|
|
5
|
+
export function rehearsalEnvironment(home, artifactFile) {
|
|
6
|
+
return {PATH: process.env.PATH ?? '', HOME: home, TMPDIR: home, TMP: home, TEMP: home,
|
|
7
|
+
XDG_CONFIG_HOME: join(home, 'config'), XDG_CACHE_HOME: join(home, 'cache'),
|
|
8
|
+
CI: 'true', ARTIFACT_FILE: artifactFile, VERIFICATION_PROFILE: 'full',
|
|
9
|
+
LANG: 'C.UTF-8', TZ: 'UTC', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: join(home, 'gitconfig'),
|
|
10
|
+
GIT_TERMINAL_PROMPT: '0', GIT_NO_LAZY_FETCH: '1', GIT_NO_REPLACE_OBJECTS: '1',
|
|
11
|
+
GIT_AUTHOR_NAME: 'Rehearsal', GIT_AUTHOR_EMAIL: 'rehearsal@example.invalid',
|
|
12
|
+
GIT_COMMITTER_NAME: 'Rehearsal', GIT_COMMITTER_EMAIL: 'rehearsal@example.invalid',
|
|
13
|
+
WRANGLER_SEND_METRICS: 'false', RER_UPDATE_CHECK: '0'};
|
|
14
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Mirrors platform install-metadata.ts (bbf6ca98); keep installation projection behavior aligned.
|
|
2
|
+
import {MANAGED_WORKFLOW, repositoryAutomation} from './automation.mjs'
|
|
3
|
+
|
|
4
|
+
/** The edition-authoring recipe; its local component paths must all be tracked for the seed's source check. */
|
|
5
|
+
export const RECIPE = 'edition.json'
|
|
6
|
+
/** Generated metadata is JSON: the recipe, and Base copy records and object proofs wherever a seed keeps them
|
|
7
|
+
* (edition-authoring's default `base-copies.json`, or any `--record` file), recognised by shape rather than name. */
|
|
8
|
+
export const metadataCandidate = (path ) => path.endsWith('.json')
|
|
9
|
+
|
|
10
|
+
const within = (name , prefix ) => name === prefix || name.startsWith(prefix + '/')
|
|
11
|
+
const encode = (value ) => new TextEncoder().encode(JSON.stringify(value, null, 2) + '\n')
|
|
12
|
+
// Unreadable metadata (a merge conflict, a publisher defect) passes through unchanged for the seed's own check to report.
|
|
13
|
+
const parse = (bytes ) => { try { return JSON.parse(new TextDecoder().decode(bytes)) } catch { return null } }
|
|
14
|
+
|
|
15
|
+
/** A Base copy record names each verbatim copy, and the seed's own verify checks every recorded file is on disk with
|
|
16
|
+
* its recorded bytes. The installation's record drops removed automation (and rer-managed.yml when RER replaced it,
|
|
17
|
+
* since its bytes are no longer Base's). Returns null when nothing changes, keeping the publisher's bytes. */
|
|
18
|
+
const copyRecord = (record ) => record?.schemaVersion === 1 && Array.isArray(record.copies)
|
|
19
|
+
&& record.copies.every((copy ) => typeof copy?.path === 'string' && copy.files && typeof copy.files === 'object')
|
|
20
|
+
const removedCopy = (name , keptWorkflow ) => repositoryAutomation(name) && !(keptWorkflow && name === MANAGED_WORKFLOW)
|
|
21
|
+
|
|
22
|
+
function installationCopyRecord(record , keptWorkflow ) {
|
|
23
|
+
if (!copyRecord(record)) return null
|
|
24
|
+
let changed = false
|
|
25
|
+
const copies = record.copies.flatMap((copy ) => {
|
|
26
|
+
const names = Object.keys(copy?.files ?? {}), kept = names.filter(name => !removedCopy(name, keptWorkflow))
|
|
27
|
+
if (kept.length === names.length) return [copy]
|
|
28
|
+
changed = true
|
|
29
|
+
if (!kept.length) return []
|
|
30
|
+
const pick = (map ) => Object.fromEntries(Object.entries(map).filter(([name]) => kept.includes(name)))
|
|
31
|
+
return [{...copy, files: pick(copy.files), ...(copy.modes ? {modes: pick(copy.modes)} : {})}]
|
|
32
|
+
})
|
|
33
|
+
return changed ? encode({...record, copies}) : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The recipe's local component paths (and their mappings) drop the automation RER removed; RER's entry stays. */
|
|
37
|
+
function installationRecipe(recipe ) {
|
|
38
|
+
if (!Array.isArray(recipe?.components)) return null
|
|
39
|
+
const removed = (path ) => typeof path === 'string' && repositoryAutomation(path) && !within(MANAGED_WORKFLOW, path)
|
|
40
|
+
let changed = false
|
|
41
|
+
const components = recipe.components.map((component ) => {
|
|
42
|
+
const source = component?.source
|
|
43
|
+
if (source?.kind !== 'local' || !Array.isArray(source.paths) || !source.paths.some(removed)) return component
|
|
44
|
+
changed = true
|
|
45
|
+
const paths = source.paths.filter((path ) => !removed(path))
|
|
46
|
+
const mappings = source.mappings?.filter((mapping ) => typeof mapping?.path === 'string' && paths.some((path ) => within(mapping.path, path)))
|
|
47
|
+
return {...component, source: {...source, paths, ...(source.mappings ? {mappings} : {})}}
|
|
48
|
+
})
|
|
49
|
+
return changed ? encode({...recipe, components}) : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Blob ids that only the dropped copy records name, from every metadata file given (non-records are ignored);
|
|
53
|
+
* `blob` maps a publisher path to its blob id. A recorded copy's bytes equal its Base origin's (the seed's check
|
|
54
|
+
* compares both), so these are the origin blobs a retained Base object proof holds only for dropped records. */
|
|
55
|
+
export function droppedCopyBlobs(files , blob , keptWorkflow ) {
|
|
56
|
+
const dropped = new Set (), named = new Set ()
|
|
57
|
+
for (const bytes of files) {
|
|
58
|
+
const record = parse(bytes)
|
|
59
|
+
if (copyRecord(record)) for (const copy of record.copies) for (const name of Object.keys(copy.files)) {
|
|
60
|
+
const id = blob(name)
|
|
61
|
+
if (id) (removedCopy(name, keptWorkflow) ? dropped : named).add(id)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const id of named) dropped.delete(id)
|
|
65
|
+
return dropped
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A retained Base object proof (native Git objects by id, standing in for the Base repository) admits exactly the
|
|
69
|
+
* objects its copy records require, so it drops the origin blobs of the dropped records. */
|
|
70
|
+
function installationObjectProof(proof , dropped ) {
|
|
71
|
+
const objects = proof?.objects
|
|
72
|
+
if (!dropped.size || !Array.isArray(proof?.revisions) || !objects || typeof objects !== 'object' || Array.isArray(objects)
|
|
73
|
+
|| !Object.keys(objects).every(id => /^[a-f0-9]{40}$/.test(id))) return null
|
|
74
|
+
const kept = Object.entries(objects).filter(([id]) => !dropped.has(id))
|
|
75
|
+
return kept.length === Object.keys(objects).length ? null : encode({...proof, objects: Object.fromEntries(kept)})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The installation's bytes for one publisher metadata file, or null when it stays as published. `keptWorkflow`:
|
|
79
|
+
* the installation carries the publisher's own rer-managed.yml; `dropped`: droppedCopyBlobs of the same tree. */
|
|
80
|
+
export function installationMetadata(path , bytes , keptWorkflow , dropped = new Set()) {
|
|
81
|
+
if (!metadataCandidate(path)) return null
|
|
82
|
+
const value = parse(bytes)
|
|
83
|
+
return path === RECIPE ? installationRecipe(value) : installationCopyRecord(value, keptWorkflow) ?? installationObjectProof(value, dropped)
|
|
84
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {resolve} from 'node:path';
|
|
2
|
+
import {invalid} from '../errors.mjs';
|
|
3
|
+
|
|
4
|
+
export const rehearseHelp = `Usage: rer rehearse [--cwd DIR] [--ref REF] [--json] [FLAGS]
|
|
5
|
+
|
|
6
|
+
Rehearse the first managed build in a fresh two-commit copy, outside this checkout.
|
|
7
|
+
Runs every declared setup, build, verify and artifact operation, in that order,
|
|
8
|
+
continuing after failures. No provider credentials are passed to the operations.
|
|
9
|
+
|
|
10
|
+
--ref REF Committed source to rehearse (default HEAD).
|
|
11
|
+
--repository OWNER/REPO Upstream identity (default rer-project.json sourceRepository).
|
|
12
|
+
--workflow-ref WORKFLOW@SHA Platform trusted workflow pin, required only when the seed
|
|
13
|
+
has no dispatch-only .github/workflows/rer-managed.yml.
|
|
14
|
+
--operation-timeout-seconds N Deadline for each operation (default 900).
|
|
15
|
+
--timeout-seconds N Overall deadline, including preparation (default 3600).
|
|
16
|
+
--keep Keep the scratch repository and its private HOME for diagnosis.
|
|
17
|
+
--json One version-1 result event with every operation, cause,
|
|
18
|
+
child exit/signal, elapsed seconds and captureLog path.
|
|
19
|
+
--help Show help without running anything.
|
|
20
|
+
|
|
21
|
+
Exit 0: all operations pass; 1: any FAIL or NOT REACHED; 2: invalid arguments;
|
|
22
|
+
3: source/declaration/scratch preparation failed; 124: overall timeout;
|
|
23
|
+
130/143: interrupted by SIGINT/SIGTERM. Per-operation timeouts are FAIL (exit 1).
|
|
24
|
+
The redacted capture log survives cleanup. NOT REACHED names a missing prerequisite
|
|
25
|
+
following a failed operation, or the overall deadline/interruption that prevented a start.
|
|
26
|
+
Operations are trusted seed code and can install packages and contact the network.
|
|
27
|
+
This is a local build rehearsal; it does not attest, upload or deploy an artifact.
|
|
28
|
+
|
|
29
|
+
Heavy work: signers and seed lanes must run through .tools/heavy-slot.py:
|
|
30
|
+
python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd SEED
|
|
31
|
+
Use a clean committed worktree when routing remotely; the selected source must be local
|
|
32
|
+
on that runner. Only declared operations may acquire dependencies over the network.
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export function rehearseOptions(args) {
|
|
36
|
+
const options = {cwd:process.cwd(), ref:'HEAD', operationTimeoutSeconds:900, timeoutSeconds:3600};
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
for (let index=0; index<args.length; index++) {
|
|
39
|
+
const flag=args[index];
|
|
40
|
+
if (seen.has(flag)) throw invalid(`Repeated flag ${flag}.`); seen.add(flag);
|
|
41
|
+
if (['--json','--keep','--help','--non-interactive'].includes(flag)) options[flag.slice(2)] = true;
|
|
42
|
+
else if (['--cwd','--ref','--repository','--workflow-ref','--operation-timeout-seconds','--timeout-seconds'].includes(flag)) {
|
|
43
|
+
const value=args[++index];if (!value || value.startsWith('--')) throw invalid(`Provide a value for ${flag}.`);
|
|
44
|
+
const key=flag.slice(2).replace(/-([a-z])/g,(_,letter)=>letter.toUpperCase());
|
|
45
|
+
if (flag.endsWith('seconds')) {
|
|
46
|
+
if (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value)) || Number(value)>86400) throw invalid(`${flag} takes integer seconds from 1 to 86400.`);
|
|
47
|
+
options[key]=Number(value);
|
|
48
|
+
} else options[key]=value;
|
|
49
|
+
} else throw invalid(`Unsupported rehearsal flag ${flag}. Run rer rehearse --help.`);
|
|
50
|
+
}
|
|
51
|
+
options.cwd=resolve(options.cwd);
|
|
52
|
+
if (options.ref.startsWith('-')) throw invalid('--ref must name a Git commit or reference.');
|
|
53
|
+
return options;
|
|
54
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {mkdtemp, mkdir, readFile, rm} from 'node:fs/promises';
|
|
2
|
+
import {join, relative, isAbsolute} from 'node:path';
|
|
3
|
+
import {tmpdir} from 'node:os';
|
|
4
|
+
import {execFile} from 'node:child_process';
|
|
5
|
+
import {promisify} from 'node:util';
|
|
6
|
+
import {shared} from '../shared.mjs';
|
|
7
|
+
import {projectInstallation, restoreArchive} from './snapshot.mjs';
|
|
8
|
+
import {rehearsalEnvironment} from './environment.mjs';
|
|
9
|
+
|
|
10
|
+
const execute=promisify(execFile), order=['setup','build','verify','artifact'];
|
|
11
|
+
const firstLine=value=>String(value).split(/\r?\n/).map(line=>line.trim()).find(Boolean);
|
|
12
|
+
const missingInput=/(?:ENOENT|Cannot find (?:module|package)|command not found|No such file or directory|cannot (?:open|access)|missing (?:build|artifact|output))/i;
|
|
13
|
+
const causeLine=text=>text.split(/\r?\n/).map(line=>line.trim()).find(line=>/error|failed|missing|cannot|not found|ERR_|contract_anchor/i.test(line)) ?? firstLine(text);
|
|
14
|
+
|
|
15
|
+
export async function rehearse(options, progress) {
|
|
16
|
+
const started=performance.now(), controller=new AbortController();
|
|
17
|
+
const timer=setTimeout(()=>controller.abort('Overall rehearsal deadline reached.'),options.timeoutSeconds*1000);
|
|
18
|
+
const handlers=new Map(['SIGINT','SIGTERM'].map(signal=>[signal,()=>controller.abort(signal)]));
|
|
19
|
+
for (const [signal,handler] of handlers) process.on(signal,handler);
|
|
20
|
+
let scratch,store,captureDirectory,currentOutput='',phase='Preparing managed copy';
|
|
21
|
+
const operations=[], result={sourceRef:options.ref, runtime:{node:process.version,platform:process.platform,arch:process.arch}, operations};
|
|
22
|
+
const elapsed=()=>Number(((performance.now()-started)/1000).toFixed(3));
|
|
23
|
+
try {
|
|
24
|
+
scratch=await mkdtemp(join(tmpdir(),'rer-rehearse-'));
|
|
25
|
+
// Logs live separately so cleanup does not discard the reason a signer needs.
|
|
26
|
+
captureDirectory=await mkdtemp(join(tmpdir(),'rer-rehearse-log-'));
|
|
27
|
+
const home=join(scratch,'home'), root=join(scratch,'repository');await mkdir(home);await mkdir(root);
|
|
28
|
+
const env=rehearsalEnvironment(home,'rer-worker-artifact.json');
|
|
29
|
+
const {createCommands}=await shared('commands.mjs');
|
|
30
|
+
store=await createCommands(captureDirectory,{logs:[]},{terminal:text=>{currentOutput=(currentOutput+text).slice(-65536);}});
|
|
31
|
+
result.captureLog=store.logPath;
|
|
32
|
+
const git=async (cwd,...args)=>(await execute('git',['-C',cwd,...args],{env,signal:controller.signal,maxBuffer:64*1024*1024})).stdout;
|
|
33
|
+
const sourceRoot=(await git(options.cwd,'rev-parse','--show-toplevel')).trim();
|
|
34
|
+
const inside=relative(sourceRoot,scratch);
|
|
35
|
+
if (!inside || (!inside.startsWith('..') && !isAbsolute(inside))) throw Error('The temporary directory must be outside the source checkout. Set TMPDIR to an external directory.');
|
|
36
|
+
result.sourceCommit=(await git(sourceRoot,'rev-parse','--verify',`${options.ref}^{commit}`)).trim();
|
|
37
|
+
const sourceCommit=result.sourceCommit;
|
|
38
|
+
const entries=(await git(sourceRoot,'ls-tree','-rz','--full-tree',sourceCommit)).split('\0').filter(Boolean).map(row=>{
|
|
39
|
+
const tab=row.indexOf('\t'), [mode,type,id]=row.slice(0,tab).split(' ');if(type!=='blob')throw Error('Unsupported external Git objects in source tree.');
|
|
40
|
+
return {mode,id,path:row.slice(tab+1)};
|
|
41
|
+
});
|
|
42
|
+
const run=(name,command,args,cwd=root,signal=controller.signal)=>store.run(name,command,args,{cwd,env,signal,display:[command,...args].join(' ')});
|
|
43
|
+
await run(phase,'git',['-C',sourceRoot,'archive','--format=tar',`--output=${join(scratch,'source.tar')}`,sourceCommit]);
|
|
44
|
+
await run(phase,'tar',['-xf',join(scratch,'source.tar'),'-C',root]);
|
|
45
|
+
await restoreArchive(root,entries,async id=>(await execute('git',['-C',sourceRoot,'cat-file','blob',id],{env,signal:controller.signal,encoding:'buffer',maxBuffer:64*1024*1024})).stdout);
|
|
46
|
+
const descriptor=JSON.parse(await readFile(join(root,'rer-project.json'),'utf8'));
|
|
47
|
+
if (descriptor.schema!==1 || descriptor.deployment?.target!=='cloudflare-workers' || !descriptor.operations ||
|
|
48
|
+
!['build','verify'].every(name=>typeof descriptor.operations[name]==='string' && descriptor.operations[name].trim())) throw Error('rer-project.json must declare schema 1, cloudflare-workers, build and verify operations.');
|
|
49
|
+
for (const name of order) if (descriptor.operations[name]!==undefined && (typeof descriptor.operations[name]!=='string' || !descriptor.operations[name].trim())) throw Error(`rer-project.json operations.${name} must be a nonempty shell command.`);
|
|
50
|
+
const artifactFile=descriptor.deployment.artifactFile??'rer-worker-artifact.json';
|
|
51
|
+
if (!/^[\w.-]+\.json$/.test(artifactFile)) throw Error('Invalid deployment artifact filename.');
|
|
52
|
+
env.ARTIFACT_FILE=artifactFile;
|
|
53
|
+
const repository=(options.repository??descriptor.sourceRepository??'').replace(/^https:\/\/github\.com\//,'').replace(/\.git$/,'').replace(/\/$/,'');
|
|
54
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/.test(repository)) throw Error('Provide --repository OWNER/REPO or declare sourceRepository in rer-project.json.');
|
|
55
|
+
result.repository=repository;
|
|
56
|
+
await run(phase,'git',['init','-q','--initial-branch=main']);
|
|
57
|
+
await run(phase,'git',['-c','core.hooksPath=/dev/null','commit','-q','--allow-empty','-m','Initial commit']);
|
|
58
|
+
await projectInstallation(root,entries,{repository,ref:options.ref,sourceCommit,workflowRef:options.workflowRef,artifactFile});
|
|
59
|
+
await run(phase,'git',['add','--all','--force']);
|
|
60
|
+
await run(phase,'git',['-c','core.hooksPath=/dev/null','commit','-q','-m',`Install ${descriptor.projectId??repository} from ${repository}@${sourceCommit}\n\n[skip ci]\n`]);
|
|
61
|
+
result.installCommit=(await git(root,'rev-parse','HEAD')).trim();
|
|
62
|
+
result.installTree=(await git(root,'rev-parse','HEAD^{tree}')).trim();
|
|
63
|
+
if (options.keep) result.scratch=root;
|
|
64
|
+
for (const name of order.filter(name=>descriptor.operations[name]!==undefined)) {
|
|
65
|
+
const command=descriptor.operations[name], operationStarted=performance.now();
|
|
66
|
+
if (controller.signal.aborted) {operations.push({name,command,status:'NOT REACHED',cause:String(controller.signal.reason),seconds:0});continue;}
|
|
67
|
+
progress?.(`Rehearsing ${name}…`); phase=name;currentOutput='';
|
|
68
|
+
const deadline=AbortSignal.timeout(options.operationTimeoutSeconds*1000), signal=AbortSignal.any([controller.signal,deadline]);
|
|
69
|
+
try {
|
|
70
|
+
await run(name,'/bin/bash',['-e','-o','pipefail','-c',command],root,signal);
|
|
71
|
+
operations.push({name,command,status:'PASS',exitCode:0,seconds:Number(((performance.now()-operationStarted)/1000).toFixed(3))});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const output=store.redact(currentOutput), earlier=operations.filter(row=>row.status!=='PASS').map(row=>row.name);
|
|
74
|
+
const unavailable=earlier.length>0 && missingInput.test(output);
|
|
75
|
+
const cause=controller.signal.aborted?String(controller.signal.reason):deadline.aborted?`Operation exceeded ${options.operationTimeoutSeconds} seconds.`:causeLine(output.replace(new RegExp(`^${name}\\s*\\n`),''))??firstLine(error.message);
|
|
76
|
+
operations.push({name,command,status:unavailable?'NOT REACHED':'FAIL',cause:unavailable?`Missing prerequisite after ${earlier.join(', ')} failed: ${cause}`:cause,exitCode:error.childExitCode??null,signal:error.signal??null,seconds:Number(((performance.now()-operationStarted)/1000).toFixed(3))});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
result.exitCode=operations.every(row=>row.status==='PASS')?0:1;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
result.exitCode=3;
|
|
82
|
+
const cause=error.step ? causeLine(error.step.output.join('\n'))??firstLine(error.message) : firstLine(error.message);
|
|
83
|
+
result.cause=store?.redact(cause)??cause;
|
|
84
|
+
store?.report(`${phase}: ${error.message}`,{logOnly:true});
|
|
85
|
+
} finally {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
for (const [signal,handler] of handlers) process.off(signal,handler);
|
|
88
|
+
try {await store?.closeCommands();} catch(error) {result.exitCode=3;result.cause=store?.redact(firstLine(error.message));}
|
|
89
|
+
if (controller.signal.aborted) result.exitCode=controller.signal.reason==='SIGINT'?130:controller.signal.reason==='SIGTERM'?143:124;
|
|
90
|
+
if (scratch && !options.keep) await rm(scratch,{recursive:true,force:true});
|
|
91
|
+
result.seconds=elapsed();result.ok=result.exitCode===0;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {readFile, writeFile, readdir, rm, chmod, mkdir, lstat} from 'node:fs/promises';
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import {join, dirname} from 'node:path';
|
|
4
|
+
import {installationLock} from '../../edition-authoring/lock.mjs';
|
|
5
|
+
import {MANAGED_WORKFLOW, repositoryAutomation, dispatchOnlyWorkflow} from './automation.mjs';
|
|
6
|
+
import {droppedCopyBlobs, installationMetadata} from './metadata.mjs';
|
|
7
|
+
import {managedWorkflow} from './workflow.mjs';
|
|
8
|
+
|
|
9
|
+
const json = value => JSON.stringify(value, null, 2) + '\n';
|
|
10
|
+
export async function projectInstallation(root, entries, {repository, ref, sourceCommit, workflowRef, artifactFile}) {
|
|
11
|
+
const sources = new Map(), ids = new Map(entries.map(entry => [entry.path, entry.id]));
|
|
12
|
+
for (const {path} of entries) if (path.endsWith('.json') || path === MANAGED_WORKFLOW) sources.set(path, await readFile(join(root,path)));
|
|
13
|
+
const kept = sources.has(MANAGED_WORKFLOW) && dispatchOnlyWorkflow(sources.get(MANAGED_WORKFLOW));
|
|
14
|
+
if (!kept && !workflowRef) throw Error('Provide --workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA: the seed has no dispatch-only managed workflow.');
|
|
15
|
+
const workflow = kept ? sources.get(MANAGED_WORKFLOW) : managedWorkflow(workflowRef, artifactFile);
|
|
16
|
+
const dropped = droppedCopyBlobs(sources.values(), path => ids.get(path), kept), changed = {};
|
|
17
|
+
const replace = async (path, bytes, executable = false) => {
|
|
18
|
+
await mkdir(dirname(join(root,path)), {recursive:true});
|
|
19
|
+
await writeFile(join(root,path), bytes); await chmod(join(root,path), executable ? 0o755 : 0o644);
|
|
20
|
+
changed[path] = {data: Buffer.from(bytes).toString('base64'), executable};
|
|
21
|
+
};
|
|
22
|
+
for (const {path} of entries) if (repositoryAutomation(path)) await rm(join(root,path), {force:true});
|
|
23
|
+
let recipe;
|
|
24
|
+
for (const [path,bytes] of sources) {
|
|
25
|
+
if (repositoryAutomation(path) || path === 'sources.lock.json') continue;
|
|
26
|
+
const body = installationMetadata(path, bytes, kept, dropped);
|
|
27
|
+
if (body) {
|
|
28
|
+
await replace(path, body, entries.find(entry => entry.path === path).mode === '100755');
|
|
29
|
+
if (path === 'edition.json') recipe = JSON.parse(Buffer.from(body).toString('utf8'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
await replace(MANAGED_WORKFLOW, workflow, kept && entries.find(entry => entry.path === MANAGED_WORKFLOW).mode === '100755');
|
|
33
|
+
await replace('rer-upstream.json', json({schema:1, repository, tag:ref, commit:sourceCommit}));
|
|
34
|
+
if (sources.has('sources.lock.json')) await writeFile(join(root,'sources.lock.json'),json(installationLock(JSON.parse(sources.get('sources.lock.json')), {removed:repositoryAutomation, changed, recipe})));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Archive attributes may omit/substitute bytes. Restore those from local Git objects,
|
|
38
|
+
// just as the platform verifies its downloaded archive against the exact source tree.
|
|
39
|
+
export async function restoreArchive(root, entries, readBlob) {
|
|
40
|
+
const names = new Set(entries.map(entry => entry.path));
|
|
41
|
+
async function prune(directory, prefix = '') {
|
|
42
|
+
for (const item of await readdir(directory, {withFileTypes:true})) {
|
|
43
|
+
const name = prefix + item.name, path = join(directory,item.name);
|
|
44
|
+
if (item.isDirectory()) { await prune(path,name+'/'); continue; }
|
|
45
|
+
if (!names.has(name)) await rm(path,{force:true});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
await prune(root);
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
if (!['100644','100755'].includes(entry.mode)) throw Error(`Unsupported source mode: ${entry.path}`);
|
|
51
|
+
const path = join(root,entry.path), stat = await lstat(path).catch(() => null);
|
|
52
|
+
const bytes = stat?.isFile() ? await readFile(path) : null;
|
|
53
|
+
const id = bytes && createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
|
|
54
|
+
if (id !== entry.id) {
|
|
55
|
+
if (stat) await rm(path,{force:true,recursive:true});
|
|
56
|
+
await mkdir(dirname(path),{recursive:true});await writeFile(path,await readBlob(entry.id));
|
|
57
|
+
}
|
|
58
|
+
await chmod(path,entry.mode === '100755' ? 0o755 : 0o644);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Mirrors platform managed-workflow.ts (bbf6ca98); keep installation projection behavior aligned.
|
|
2
|
+
/** RER's delivery entry for a publisher without its own dispatch-only rer-managed.yml: the Base producer shape, one
|
|
3
|
+
* dispatch-only job calling the trusted build, which runs the project's declared setup, build, verify and artifact. */
|
|
4
|
+
export function managedWorkflow(trusted , artifactFile ) {
|
|
5
|
+
if (!/^[\w.-]+\/[\w.-]+\/\.github\/workflows\/[\w.-]+\.ya?ml@[a-f0-9]{40}$/.test(trusted)
|
|
6
|
+
|| !/^[\w.-]+\.json$/.test(artifactFile)) throw Error('Invalid managed workflow configuration')
|
|
7
|
+
return new TextEncoder().encode(`name: Managed release
|
|
8
|
+
on:
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
inputs:
|
|
11
|
+
installation_id:
|
|
12
|
+
required: true
|
|
13
|
+
type: string
|
|
14
|
+
broker_url:
|
|
15
|
+
required: true
|
|
16
|
+
type: string
|
|
17
|
+
environment:
|
|
18
|
+
required: true
|
|
19
|
+
default: preview
|
|
20
|
+
type: choice
|
|
21
|
+
options: [preview, production]
|
|
22
|
+
verification_profile:
|
|
23
|
+
required: true
|
|
24
|
+
default: full
|
|
25
|
+
type: choice
|
|
26
|
+
options: [full]
|
|
27
|
+
permissions:
|
|
28
|
+
contents: read
|
|
29
|
+
actions: read
|
|
30
|
+
id-token: write
|
|
31
|
+
jobs:
|
|
32
|
+
release:
|
|
33
|
+
uses: ${trusted}
|
|
34
|
+
with:
|
|
35
|
+
installation_id: \${{ inputs.installation_id }}
|
|
36
|
+
broker_url: \${{ inputs.broker_url }}
|
|
37
|
+
environment: \${{ inputs.environment }}
|
|
38
|
+
verification_profile: \${{ inputs.verification_profile }}
|
|
39
|
+
artifact_file: ${artifactFile}
|
|
40
|
+
build_profile: project
|
|
41
|
+
`)
|
|
42
|
+
}
|
package/cli/rehearse.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {rehearseOptions, rehearseHelp} from './rehearse/options.mjs';
|
|
2
|
+
import {rehearse} from './rehearse/run.mjs';
|
|
3
|
+
import {output} from './output.mjs';
|
|
4
|
+
|
|
5
|
+
export async function rehearseCommand(args) {
|
|
6
|
+
let options={verb:'rehearse',json:args.includes('--json')}, out=output(options);
|
|
7
|
+
try {
|
|
8
|
+
options={...rehearseOptions(args),verb:'rehearse'};out=output(options);
|
|
9
|
+
if(options.help){if(options.json)out.event('help',{usage:rehearseHelp});else out.human(rehearseHelp);return 0;}
|
|
10
|
+
const result=await rehearse(options,options.json?undefined:text=>out.progress(text+'\n'));
|
|
11
|
+
if(!options.json){
|
|
12
|
+
for(const row of result.operations)out.human(`${row.status} ${row.name}${row.cause?`: ${row.cause}`:''}`);
|
|
13
|
+
if(result.cause)out.human(`Could not prepare rehearsal: ${result.cause}`);
|
|
14
|
+
if(result.captureLog)out.human(`Capture log: ${result.captureLog}`);
|
|
15
|
+
if(result.scratch)out.human(`Kept scratch copy: ${result.scratch}`);
|
|
16
|
+
out.human(`Elapsed: ${result.seconds}s`);
|
|
17
|
+
}
|
|
18
|
+
const {ok,exitCode,...details}=result;out.result(ok,exitCode,details);return exitCode;
|
|
19
|
+
} catch(error){const code=error.exitCode??2;out.error({code:error.code??'invalid_invocation',message:error.message,exitCode:code});out.result(false,code);return code;}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {resolve} from 'node:path';
|
|
2
|
+
import {prepareCandidate} from '../modules/release/candidate.mjs';
|
|
3
|
+
|
|
4
|
+
export const candidateHelp = `Usage: rer release candidate --tag vVERSION-PRERELEASE [--cwd DIR] [--json]
|
|
5
|
+
|
|
6
|
+
Prepare stage-only version metadata in one local commit on the caller's checkout.
|
|
7
|
+
Updates only version in seed.json, package.json and RELEASE.json; requires a clean
|
|
8
|
+
checkout with matching committed versions and the caller's Git commit identity.
|
|
9
|
+
Repeating the same tag is a no-op. Accepts the current version core or the next
|
|
10
|
+
patch core. Stable tags require the normal release metadata path.
|
|
11
|
+
|
|
12
|
+
The output version always contains a SemVer pre-release suffix (for example
|
|
13
|
+
0.4.25-rc1); production consumers must refuse pre-release tags. Stage only: do not
|
|
14
|
+
publish a GitHub Release, Site or registry entry, or expose it to outside users.
|
|
15
|
+
Creates no tag, artifact, push, signature or deployment. Existing producer gates
|
|
16
|
+
still apply to the returned commit; run its two-commit rehearsal before stage use.
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export async function candidateCommand(args) {
|
|
20
|
+
try {
|
|
21
|
+
let cwd=process.cwd(), tag; const seen=new Set();
|
|
22
|
+
for (let index=0; index<args.length; index++) {
|
|
23
|
+
const flag=args[index];
|
|
24
|
+
if (seen.has(flag)) throw Error(`Repeated candidate flag ${flag}.`); seen.add(flag);
|
|
25
|
+
if (flag==='--help') {console.log(candidateHelp);return 0;}
|
|
26
|
+
if (flag==='--json' || flag==='--non-interactive') continue;
|
|
27
|
+
if (!['--cwd','--tag'].includes(flag) || !args[index+1]?.trim() || args[index+1].startsWith('--')) throw Error('Use rer release candidate --tag vVERSION-PRERELEASE [--cwd DIR] [--json].');
|
|
28
|
+
const value=args[++index]; if(flag==='--cwd')cwd=resolve(value);else tag=value;
|
|
29
|
+
}
|
|
30
|
+
console.log(JSON.stringify(prepareCandidate(cwd, tag), null, 2));return 0;
|
|
31
|
+
} catch(error) {console.error(error.message);return 2;}
|
|
32
|
+
}
|
package/cli/release.mjs
CHANGED
|
@@ -38,6 +38,9 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
|
|
|
38
38
|
--no-queue Bypass the job queue only in the original CI environment.
|
|
39
39
|
--help Print this help without performing release work.
|
|
40
40
|
|
|
41
|
+
Stage-only metadata preparation:
|
|
42
|
+
rer release candidate --tag vVERSION-PRERELEASE [--cwd DIR] [--json]
|
|
43
|
+
|
|
41
44
|
Signing and receipt commands:
|
|
42
45
|
rer release sign --artifact DIR (--key-file FILE | --key-stdin) [--scope test|rer] [--publisher NAMESPACE]
|
|
43
46
|
rer release receipt --artifact DIR --anchors FILE [--environment test] [--after VERSION:SHA256]
|
|
@@ -52,6 +55,7 @@ Key generation requires non-terminal stdout; --key-stdin requires non-terminal s
|
|
|
52
55
|
|
|
53
56
|
export async function dispatchRelease(args) {
|
|
54
57
|
if (args.length === 1 && args[0] === '--help') { console.log(releaseHelp); return 0; }
|
|
58
|
+
if (args[0] === 'candidate') return (await import('./release-candidate.mjs')).candidateCommand(args.slice(1));
|
|
55
59
|
if (Object.hasOwn(releaseVerb.subcommands, args[0])) return (await import('../modules/release/signing-cli.mjs')).dispatchSigning(args[0], args.slice(1));
|
|
56
60
|
try {
|
|
57
61
|
const options = {};
|
|
@@ -14,6 +14,30 @@ function toolsIdentity() {
|
|
|
14
14
|
function includes(files, selected) {
|
|
15
15
|
return Object.keys(files).some(p => p === selected || p.startsWith(selected + '/'));
|
|
16
16
|
}
|
|
17
|
+
// Regenerate projected identities with the same hashing/serialization as normal source locks.
|
|
18
|
+
export function fileIdentities(files) {
|
|
19
|
+
return Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([name, value]) => [name, {
|
|
20
|
+
sha256: hash(Buffer.from(value.data, 'base64')), executable: value.executable,
|
|
21
|
+
}]));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Managed copies retain the publisher's toolchain and source pins. Only the installation's
|
|
25
|
+
// changed metadata/automation is regenerated; unchanged application identities stay bound.
|
|
26
|
+
export function installationLock(lock, {removed, changed, recipe}) {
|
|
27
|
+
if (lock.schemaVersion !== 1 || !lock.files || Array.isArray(lock.files) ||
|
|
28
|
+
Object.values(lock.files).some(value => !value || !/^[a-f0-9]{64}$/.test(value.sha256) || typeof value.executable !== 'boolean'))
|
|
29
|
+
throw Error('Unsupported source lock; provide an edition-authoring file lock.');
|
|
30
|
+
const files = Object.fromEntries(Object.entries(lock.files).filter(([name]) => !removed(name)));
|
|
31
|
+
Object.assign(files, fileIdentities(changed));
|
|
32
|
+
lock = {...lock, files: Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)))};
|
|
33
|
+
if (recipe && 'manifest' in lock) lock.manifest = hash(json(recipe));
|
|
34
|
+
if (recipe && Array.isArray(lock.components)) lock.components = lock.components.map(component => {
|
|
35
|
+
const selected = recipe.components.find(entry => entry.id === component?.id);
|
|
36
|
+
return selected && 'source' in component ? {...component, source: selected.source} : component;
|
|
37
|
+
});
|
|
38
|
+
return lock;
|
|
39
|
+
}
|
|
40
|
+
|
|
17
41
|
export function resolveSources(root, retain = false, diagnostics = false, additionalFiles = {}) {
|
|
18
42
|
const recipe = manifest(root);
|
|
19
43
|
const files = Object.assign(tracked(root, diagnostics), additionalFiles);
|
|
@@ -37,12 +61,10 @@ export function resolveSources(root, retain = false, diagnostics = false, additi
|
|
|
37
61
|
components.push({id: component.id, source: selected, baseline: baseline ? {key: baseline.key, digest: baseline.digest, sha256: hash(json(baseline))} : null});
|
|
38
62
|
}
|
|
39
63
|
const parent = recipe.parent ? snapshot(root, {...recipe.parent, excludeSnapshots: true}, retain) : null;
|
|
40
|
-
const identities =
|
|
41
|
-
sha256: hash(Buffer.from(value.data, 'base64')), executable: value.executable,
|
|
42
|
-
}]);
|
|
64
|
+
const identities = fileIdentities(files);
|
|
43
65
|
return {
|
|
44
66
|
schemaVersion: 1, parent: parent ? {key: parent.key, digest: parent.digest, sha256: hash(json(parent))} : null,
|
|
45
67
|
edition: recipe.id, manifest: hash(json(recipe)), toolchain: toolsIdentity(),
|
|
46
|
-
components, files:
|
|
68
|
+
components, files: identities,
|
|
47
69
|
};
|
|
48
70
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.115
|
|
4
|
+
|
|
5
|
+
### Stage candidate metadata and installed-copy recognition
|
|
6
|
+
|
|
7
|
+
- New `rer release candidate --tag vVERSION-PRERELEASE --cwd DIR` prepares stage-only metadata in one local commit using the caller's Git identity. It changes only the top-level `version` in `seed.json`, `package.json` and `RELEASE.json`, preserving other metadata and formatting. A clean checkout with matching committed versions is required; the candidate must use the current version core or its next patch. Repeating the same tag is a no-op. Dirty checkouts, stable tags, malformed labels and unrelated cores are refused before writing.
|
|
8
|
+
- The command runs without project bootstrap and returns the exact commit, version, tag, `stageOnly: true` and whether it changed. It creates no tag, artifact, push, signature or deployment. Candidates require rehearsal and the existing producer gates before stage use; they are not for GitHub Release, Site/registry publication or outside-user resolution. Production consumers must refuse pre-release tags. Stable producer metadata, tag matching, verification, scans and receipts remain unchanged.
|
|
9
|
+
- Installed-copy checks now recognize valid SemVer pre-release upstream labels. A managed installation projection can omit publisher `.github` automation evidence during its two-commit rehearsal, as stable installed copies already can. Authoring checkouts still require publisher evidence, and other evidence paths remain required in installed copies. The global launcher and regenerated default-seed CLI expose the candidate command.
|
|
10
|
+
|
|
11
|
+
0.2.114 added `rer rehearse`; it was published but did not complete release qualification. 0.2.115 adds the candidate metadata and installed-copy recognition changes above and carries that rehearsal support forward. This prepares CLI support only: seed lanes and signers must adopt the rer and rehearse their own committed sources. No seed adoption, deployed behavior or production result is established here.
|
|
12
|
+
|
|
13
|
+
Code and documentation only: the actual diff since rer-v0.2.114 adds no migrations and touches neither modules/import-kit nor modules/portability. No provider calls are needed for candidate metadata preparation.
|
|
14
|
+
|
|
15
|
+
## 0.2.114
|
|
16
|
+
|
|
17
|
+
### Pre-install rehearsal
|
|
18
|
+
|
|
19
|
+
- New `rer rehearse --cwd DIR --ref REF` runs the selected committed seed's declared setup, build, verify and artifact operations, in order, in a fresh two-commit installation copy outside the source checkout. It removes publisher automation, retains or generates a dispatch-only managed workflow, updates installation metadata and source-lock identities while preserving publisher source pins, and leaves the source checkout unchanged.
|
|
20
|
+
- Rehearsal continues after operation failures and reports PASS, FAIL or NOT REACHED with the first cause, elapsed time and a redacted capture-log path. Per-operation and overall deadlines bound execution; `--json` provides the structured result and `--keep` retains the scratch copy for diagnosis. A fresh private HOME/config/cache and restricted environment keep caller provider credentials out. Declared operations are trusted seed code and may acquire dependencies over the network; signers and seed lanes must run this heavy work through their supported heavy slot.
|
|
21
|
+
- The global launcher and refreshed default-seed CLI expose the command and its help. This releases CLI support: each signer or seed lane must adopt this rer and run rehearsal against its own committed seed. A local rehearsal does not establish GitHub attestation, artifact upload, provider deployment, seed adoption or production behavior.
|
|
22
|
+
|
|
23
|
+
Code and documentation only: the actual diff adds no migrations and touches neither modules/import-kit nor modules/portability. No deployed seed behavior is changed by preparing this release.
|
|
24
|
+
|
|
3
25
|
## 0.2.113
|
|
4
26
|
|
|
5
27
|
### Recovery output and archive restore
|
package/global/README.md
CHANGED
|
@@ -727,3 +727,54 @@ runtime and type dependencies. The existing
|
|
|
727
727
|
`@runeditrun/rer/modules/import-kit/d1` entry remains available. See the
|
|
728
728
|
[adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
|
|
729
729
|
for native adapters, consent, declared intake projection and reviewed apply/Undo.
|
|
730
|
+
|
|
731
|
+
## Rehearse before signing a seed release
|
|
732
|
+
|
|
733
|
+
Run `rer rehearse --cwd /path/to/seed --ref HEAD` before announcing a release.
|
|
734
|
+
It exports the selected commit into a fresh repository outside the checkout,
|
|
735
|
+
with an empty `Initial commit` and one installation commit. The installation
|
|
736
|
+
projection removes publisher automation, preserves a dispatch-only managed
|
|
737
|
+
workflow, updates its recipe/copy metadata, adds schema-1 `rer-upstream.json`
|
|
738
|
+
(repository, tag/ref, exact source SHA), and regenerates changed lock identities
|
|
739
|
+
through Base's source-lock generator while retaining the publisher's source pins.
|
|
740
|
+
Uncommitted files and publisher history are absent. The source checkout is unchanged.
|
|
741
|
+
|
|
742
|
+
This installs dependencies and builds. Signers and seed lanes must use the heavy slot:
|
|
743
|
+
|
|
744
|
+
```sh
|
|
745
|
+
python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd /path/to/seed --ref HEAD
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
Use a committed clean worktree for remote routing and make the source available
|
|
749
|
+
on that runner. The command itself uses local Git objects and creates no remote;
|
|
750
|
+
only the declared operations may acquire dependencies over the network. Supply the
|
|
751
|
+
same Node and package-manager tools as the seed's trusted build. A fresh private
|
|
752
|
+
HOME/config/cache and a restricted environment keep caller provider credentials out.
|
|
753
|
+
The operations are trusted source code, not a sandbox for an untrusted seed.
|
|
754
|
+
|
|
755
|
+
Every declared `setup`, `build`, `verify`, `artifact` command runs in that order
|
|
756
|
+
from the scratch root, in its own `bash -e -o pipefail` process. Rehearsal continues
|
|
757
|
+
after failures, so one run reports every failing operation. A later command that
|
|
758
|
+
cannot start because a prior operation left a required input unavailable is
|
|
759
|
+
reported `NOT REACHED` with the missing-input diagnostic. Recovery prose is not
|
|
760
|
+
an executable operation. Shell variables and working-directory changes do not
|
|
761
|
+
carry between operations; filesystem changes do.
|
|
762
|
+
|
|
763
|
+
The summary prints PASS/FAIL/NOT REACHED, the first cause line and the full redacted
|
|
764
|
+
capture-log path. Logs survive scratch cleanup; `--keep` retains the repository and
|
|
765
|
+
its private HOME for diagnosis. `--operation-timeout-seconds N` defaults to 900;
|
|
766
|
+
`--timeout-seconds N` bounds preparation and all operations together (default 3600).
|
|
767
|
+
Both accept integer seconds from 1 to 86400. If no dispatch-only managed workflow
|
|
768
|
+
exists, provide the platform's immutable `--workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA`.
|
|
769
|
+
`--repository OWNER/REPO` overrides the descriptor's source repository identity.
|
|
770
|
+
A branch/ref in the rehearsal upstream record identifies unreleased source; it is
|
|
771
|
+
not a signed stable-release record.
|
|
772
|
+
|
|
773
|
+
Exit codes: 0 all pass; 1 an operation failed or was not reached; 2 invalid flags;
|
|
774
|
+
3 preparation/source/declaration failure; 124 overall timeout; 130/143 interruption.
|
|
775
|
+
A per-operation timeout is FAIL and exit 1. With `--json`, stdout contains one
|
|
776
|
+
version-1 `result` event with `ok`, `exitCode`, source/install identities, elapsed
|
|
777
|
+
`seconds`, `captureLog` and every operation's command, status, cause and child
|
|
778
|
+
exit/signal. `rer rehearse --help` lists the flags. This proves local declared
|
|
779
|
+
build operations under the recorded host conditions; GitHub attestation, artifact
|
|
780
|
+
upload and provider deployment remain separate.
|
package/global/main.mjs
CHANGED
|
@@ -25,6 +25,8 @@ else its vendored scripts/rer.mjs.
|
|
|
25
25
|
RER_READY and a sign-in link. Without a terminal it returns once the app is
|
|
26
26
|
ready and leaves it running (--detach and --foreground override); allow up
|
|
27
27
|
to 10 minutes on a first launch, or rerun it to reattach. rer dev --stop stops it.
|
|
28
|
+
rer rehearse [--cwd DIR] [--ref REF]
|
|
29
|
+
Rehearse every managed build operation in a two-commit scratch copy.
|
|
28
30
|
rer run SCRIPT [ARGS]
|
|
29
31
|
Run a package.json script with the pnpm and Node the checkout pins (rer keeps
|
|
30
32
|
them off PATH): where a project's docs say pnpm run X, run rer run X.
|
|
@@ -59,6 +61,8 @@ export async function main(argv) {
|
|
|
59
61
|
handleBrokenPipes();
|
|
60
62
|
const [verb] = argv;
|
|
61
63
|
const installsFirst = checkoutBootstrap(argv) === 'before';
|
|
64
|
+
if (verb === 'release' && argv[1] === 'candidate') return (await import('../cli/release-candidate.mjs')).candidateCommand(argv.slice(2));
|
|
65
|
+
if (verb === 'rehearse') return (await import('../cli/rehearse.mjs')).rehearseCommand(argv.slice(1));
|
|
62
66
|
if (verb === '--version' || verb === '-v') return (await import('./version.mjs')).versionCommand(argv);
|
|
63
67
|
if (verb === 'queue' && argv.length === 2 && argv[1] === '--help') {
|
|
64
68
|
process.stdout.write('Usage: rer queue NAME -- COMMAND [ARGS]\nRun COMMAND once this computer\'s job queue admits it.\n');
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# `rer release`
|
|
2
2
|
|
|
3
|
+
For a stage-only candidate from a landed seed commit, use a clean checkout on
|
|
4
|
+
its candidate branch:
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
rer release candidate --cwd /path/to/seed --tag v0.4.25-rc1
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This writes only the top-level `version` fields in committed `seed.json`,
|
|
11
|
+
`package.json` and `RELEASE.json`, preserving other metadata and formatting,
|
|
12
|
+
and commits them together using the caller's Git identity. It requires their
|
|
13
|
+
existing versions to agree and accepts a SemVer pre-release of the current core
|
|
14
|
+
or its immediately following patch (for example, `0.4.24` to `0.4.25-rc1`).
|
|
15
|
+
Minor and major versions use the normal explicit metadata preparation. Repeating
|
|
16
|
+
the same tag succeeds without another commit. Dirty checkouts, stable tags,
|
|
17
|
+
malformed labels and unrelated version cores are refused before any write.
|
|
18
|
+
`--json` returns `stageOnly: true`, the version, tag, exact commit and whether
|
|
19
|
+
it changed. No project code, install, producer, tag or remote action runs.
|
|
20
|
+
|
|
21
|
+
The committed version always contains the SemVer pre-release suffix; production
|
|
22
|
+
consumers must refuse pre-release tags. These candidates are stage only: no
|
|
23
|
+
GitHub Release, Site/registry publication or outside-user release resolution.
|
|
24
|
+
Run `rer rehearse --cwd /path/to/seed --ref <candidate-commit>` and the existing
|
|
25
|
+
producer gates on the returned commit before stage use. To rehearse the exact
|
|
26
|
+
candidate label, use that label as `--ref` once it resolves locally. Installed
|
|
27
|
+
copies with a valid pre-release `rer-upstream.json` get the same narrowly scoped
|
|
28
|
+
publisher-automation evidence exception as stable installed copies. Authoring
|
|
29
|
+
checkouts still enforce every evidence file. The ordinary stable producer's
|
|
30
|
+
metadata, tag matching, verification, scans and receipts are unchanged.
|
|
31
|
+
|
|
3
32
|
Before a Base release, run `pnpm verify:scale` for the full import-kit datasets. It
|
|
4
33
|
is not part of `pnpm verify`: run it on a machine with at least 16 GB of memory and
|
|
5
34
|
nothing else heavy running, because its D1 datasets are large.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {writeFileSync} from 'node:fs';
|
|
2
|
+
import {execFileSync} from 'node:child_process';
|
|
3
|
+
import {resolve} from 'node:path';
|
|
4
|
+
import {git, inspectSource} from './source.mjs';
|
|
5
|
+
|
|
6
|
+
const core = '(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)';
|
|
7
|
+
const identifier = '(?:0|[1-9]\\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)';
|
|
8
|
+
const version = new RegExp(`^${core}(?:-${identifier}(?:\\.${identifier})*)?$`);
|
|
9
|
+
const candidate = new RegExp(`^v${core}-${identifier}(?:\\.${identifier})*$`);
|
|
10
|
+
const files = ['seed.json', 'package.json', 'RELEASE.json'];
|
|
11
|
+
|
|
12
|
+
// A candidate uses the current core or the immediately following patch.
|
|
13
|
+
// Minor and major releases keep their normal explicit metadata preparation.
|
|
14
|
+
function allowedCore(current, requested) {
|
|
15
|
+
const [major, minor, patch] = current;
|
|
16
|
+
return [current, [major, minor, patch + 1]]
|
|
17
|
+
.some(parts => parts.every((part, index) => part === requested[index]));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function prepareCandidate(cwd, tag) {
|
|
21
|
+
const wanted = candidate.exec(tag ?? '');
|
|
22
|
+
if (!wanted) throw Error('Candidate requires --tag vMAJOR.MINOR.PATCH-PRERELEASE; stable tags use the normal release metadata path.');
|
|
23
|
+
const repo = git(resolve(cwd), 'rev-parse', '--show-toplevel').toString().trim();
|
|
24
|
+
const source = inspectSource(repo, 'HEAD'), current = version.exec(source.seed.version);
|
|
25
|
+
const requested = wanted.slice(1, 4).map(Number), previous = current?.slice(1, 4).map(Number);
|
|
26
|
+
if (!previous || ![...previous, ...requested].every(Number.isSafeInteger) || !allowedCore(previous, requested))
|
|
27
|
+
throw Error('Candidate must be a pre-release of the current version or its next patch version.');
|
|
28
|
+
const next = tag.slice(1);
|
|
29
|
+
if (source.seed.version === next) return {stageOnly:true, tag, version:next, commit:source.commit, changed:false};
|
|
30
|
+
// Preserve the caller's configured identity; the source reader deliberately
|
|
31
|
+
// ignores global Git config, so it must not be used to create this commit.
|
|
32
|
+
const commitGit = (...args) => execFileSync('git', ['-C', repo, '-c', 'core.hooksPath=/dev/null', '-c', 'commit.gpgSign=false', ...args], {stdio:['ignore','pipe','pipe']});
|
|
33
|
+
commitGit('var', 'GIT_AUTHOR_IDENT'); commitGit('var', 'GIT_COMMITTER_IDENT');
|
|
34
|
+
const changes = files.map(path => {
|
|
35
|
+
const bytes = source.bytes(path).toString(), value = JSON.parse(bytes);
|
|
36
|
+
// Preserve all other metadata and the caller's formatting. The committed
|
|
37
|
+
// top-level version is the only JSON value that may change.
|
|
38
|
+
const before = JSON.stringify(value);
|
|
39
|
+
let depth = 0, result = '', end = 0;
|
|
40
|
+
const strings = /"(?:[^"\\]|\\.)*"|[{}\[\]]/g;
|
|
41
|
+
for (const token of bytes.matchAll(strings)) {
|
|
42
|
+
if (['{','['].includes(token[0])) depth++;
|
|
43
|
+
else if (['}',']'].includes(token[0])) depth--;
|
|
44
|
+
else if (depth === 1 && JSON.parse(token[0]) === 'version') {
|
|
45
|
+
const tail = bytes.slice(token.index + token[0].length), match = /^\s*:\s*("(?:[^"\\]|\\.)*")/.exec(tail);
|
|
46
|
+
if (!match) continue;
|
|
47
|
+
const start = token.index + token[0].length + match[0].length - match[1].length;
|
|
48
|
+
result += bytes.slice(end, start) + JSON.stringify(next); end = start + match[1].length;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
result += bytes.slice(end);
|
|
52
|
+
value.version = next;
|
|
53
|
+
if (before === JSON.stringify(value) || JSON.stringify(JSON.parse(result)) !== JSON.stringify(value)) throw Error(`Cannot update only ${path} version.`);
|
|
54
|
+
return {path, bytes:result};
|
|
55
|
+
});
|
|
56
|
+
for (const {path, bytes} of changes) writeFileSync(resolve(repo, path), bytes);
|
|
57
|
+
git(repo, 'add', '--', ...files);
|
|
58
|
+
commitGit('commit', '-m', `Prepare stage-only candidate ${tag}`);
|
|
59
|
+
return {stageOnly:true, tag, version:next, commit:git(repo, 'rev-parse', 'HEAD').toString().trim(), changed:true};
|
|
60
|
+
}
|