obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { asRecord } from "./json.js";
|
|
2
|
+
function parseAsset(value) {
|
|
3
|
+
const record = asRecord(value);
|
|
4
|
+
if (record === undefined || typeof record.id !== "number" || typeof record.name !== "string") {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return { id: record.id, name: record.name, size: typeof record.size === "number" ? record.size : 0, state: typeof record.state === "string" ? record.state : "" };
|
|
8
|
+
}
|
|
9
|
+
export function parseRelease(value) {
|
|
10
|
+
const record = asRecord(value);
|
|
11
|
+
if (record === undefined || typeof record.id !== "number" || typeof record.tag_name !== "string") {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const assets = Array.isArray(record.assets) ? record.assets.flatMap((asset) => parseAsset(asset) ?? []) : [];
|
|
15
|
+
return {
|
|
16
|
+
id: record.id,
|
|
17
|
+
tag: record.tag_name,
|
|
18
|
+
draft: record.draft === true,
|
|
19
|
+
prerelease: record.prerelease === true,
|
|
20
|
+
url: typeof record.html_url === "string" ? record.html_url : "",
|
|
21
|
+
body: typeof record.body === "string" ? record.body : "",
|
|
22
|
+
assets,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** The releases for a tag in one page of `GET /releases` (drafts are listed there, and not by `/releases/tags/<tag>`), and how many entries the page had. */
|
|
26
|
+
export function releasesOfTag(json, tag) {
|
|
27
|
+
const parsed = JSON.parse(json);
|
|
28
|
+
if (!Array.isArray(parsed)) {
|
|
29
|
+
throw new Error("GitHub did not return a list of releases.");
|
|
30
|
+
}
|
|
31
|
+
const found = [];
|
|
32
|
+
for (const entry of parsed) {
|
|
33
|
+
const release = parseRelease(entry);
|
|
34
|
+
if (release?.tag === tag) {
|
|
35
|
+
found.push(release);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { found, count: parsed.length };
|
|
39
|
+
}
|
|
40
|
+
/** What the release must hold: the three Obsidian files, `styles.css` only if the plugin has one. */
|
|
41
|
+
export function expectedAssets(options) {
|
|
42
|
+
const attested = ["main.js", "manifest.json", ...(options.hasCss ? ["styles.css"] : [])];
|
|
43
|
+
return { names: [...attested, ...(options.zipName === undefined ? [] : [options.zipName])], attested };
|
|
44
|
+
}
|
|
45
|
+
/** What is wrong with the asset list of a release: missing, unexpected, unfinished or empty files. */
|
|
46
|
+
export function assetProblems(release, expected) {
|
|
47
|
+
const problems = [];
|
|
48
|
+
const present = new Set(release.assets.map((asset) => asset.name));
|
|
49
|
+
for (const name of expected.names) {
|
|
50
|
+
if (!present.has(name)) {
|
|
51
|
+
problems.push(`the release has no asset ${name}.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const asset of release.assets) {
|
|
55
|
+
if (!expected.names.includes(asset.name)) {
|
|
56
|
+
problems.push(`the release has an unexpected asset ${asset.name}. Obsidian reads main.js, manifest.json and styles.css only.`);
|
|
57
|
+
}
|
|
58
|
+
else if (asset.state !== "uploaded") {
|
|
59
|
+
problems.push(`the asset ${asset.name} is in the state "${asset.state}", not "uploaded".`);
|
|
60
|
+
}
|
|
61
|
+
else if (asset.size === 0) {
|
|
62
|
+
problems.push(`the asset ${asset.name} is empty.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return problems;
|
|
66
|
+
}
|
|
67
|
+
/** The name of the optional zip asset: the plugin id and the version, as the kit's workflow names it. */
|
|
68
|
+
export const zipAssetName = (id, version) => `${id}-${version}.zip`;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Reporter } from "../cli/reporter.js";
|
|
2
|
+
import type { OpdkConfig } from "../config/types.js";
|
|
3
|
+
import { type CheckFlags } from "./check.js";
|
|
4
|
+
import { type RunGit } from "./git.js";
|
|
5
|
+
import { type InterruptHooks } from "./interrupt.js";
|
|
6
|
+
import { type VersionSpec } from "./args.js";
|
|
7
|
+
export interface ReleaseInput {
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly spec: VersionSpec;
|
|
10
|
+
readonly dryRun: boolean;
|
|
11
|
+
readonly flags: CheckFlags;
|
|
12
|
+
readonly config: OpdkConfig;
|
|
13
|
+
readonly reporter: Reporter;
|
|
14
|
+
/** Prints plain text such as the diff of a dry run. */
|
|
15
|
+
readonly stdout: (text: string) => void;
|
|
16
|
+
readonly run: RunGit;
|
|
17
|
+
/** Ctrl+C handling: the bumped files are restored and the temp folders removed before the process exits with 130. */
|
|
18
|
+
readonly interrupt?: InterruptHooks;
|
|
19
|
+
/** The clock, injected so the changelog date is fixed in tests. */
|
|
20
|
+
readonly now: () => Date;
|
|
21
|
+
/** The push flow after the tag. Without it (`--no-push`, a test) the release stops at the local tag. */
|
|
22
|
+
readonly push?: PushFlow;
|
|
23
|
+
/** Runs the plugin's `npm test` and returns its exit code. Without it (`--no-test`, a test) no tests run. */
|
|
24
|
+
readonly test?: () => Promise<number>;
|
|
25
|
+
}
|
|
26
|
+
/** What `opdk release` needs from the push flow: a check before anything changes, and the flow itself after the tag. */
|
|
27
|
+
export interface PushFlow {
|
|
28
|
+
/** Throws a `StepFailure` when the flow could not run (no gh, not signed in), so nothing is bumped for nothing. */
|
|
29
|
+
readonly ready: () => Promise<void>;
|
|
30
|
+
readonly publish: (version: string) => Promise<number>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `opdk release <patch|minor|major|X.Y.Z>`, the local part: preflight, bump the version everywhere, move the
|
|
34
|
+
* changelog entries, run the release check on the result, then commit `chore(release): X.Y.Z` and create the
|
|
35
|
+
* annotated tag `X.Y.Z`, then hands over to the push flow when there is one. With `dryRun` the files are restored and nothing reaches git.
|
|
36
|
+
*/
|
|
37
|
+
export declare function runRelease(input: ReleaseInput): Promise<number>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { formatDate, planBump } from "./bump.js";
|
|
4
|
+
import { runReleaseCheck } from "./check.js";
|
|
5
|
+
import { collectFacts } from "./git.js";
|
|
6
|
+
import { CleanupSet, guardInterrupt, INTERRUPTED_EXIT } from "./interrupt.js";
|
|
7
|
+
import { asRecord } from "./json.js";
|
|
8
|
+
import { changelogPreflight, preflightProblems } from "./preflight.js";
|
|
9
|
+
import { DEFAULT_CHANGELOG, loadProjectFiles, valueOf } from "./project-files.js";
|
|
10
|
+
import { compareVersions } from "./semver.js";
|
|
11
|
+
import { resolveVersion } from "./args.js";
|
|
12
|
+
import { StepFailure } from "./publish-state.js";
|
|
13
|
+
import { checkVersionSync } from "./version-rules.js";
|
|
14
|
+
function hasTestScript(files) {
|
|
15
|
+
const scripts = asRecord(asRecord(valueOf(files.packageJson))?.scripts);
|
|
16
|
+
return typeof scripts?.test === "string";
|
|
17
|
+
}
|
|
18
|
+
function fail(reporter, step, problems) {
|
|
19
|
+
for (const problem of problems) {
|
|
20
|
+
reporter.failure(step, problem.message, { hint: problem.hint });
|
|
21
|
+
}
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
/** Problems with the files before anything is changed: all versions agree, the new one is higher and not mapped yet. */
|
|
25
|
+
function filesProblems(files, current, next) {
|
|
26
|
+
const problems = [];
|
|
27
|
+
const minAppVersion = asRecord(valueOf(files.manifest))?.minAppVersion;
|
|
28
|
+
if (typeof minAppVersion !== "string") {
|
|
29
|
+
problems.push({ message: "manifest.json has no minAppVersion to map the new version to in versions.json.", hint: 'Add "minAppVersion" to manifest.json.' });
|
|
30
|
+
}
|
|
31
|
+
if ((compareVersions(next, current) ?? 0) <= 0) {
|
|
32
|
+
problems.push({ message: `${next} is not higher than the current version ${current}.`, hint: "Pick a higher version, or use patch, minor or major." });
|
|
33
|
+
}
|
|
34
|
+
const mapped = asRecord(valueOf(files.versions));
|
|
35
|
+
if (mapped !== undefined && Object.hasOwn(mapped, next) && mapped[next] !== minAppVersion) {
|
|
36
|
+
problems.push({ message: `versions.json already maps ${next} to ${String(mapped[next])}, but manifest.json minAppVersion is ${String(minAppVersion)}.`, hint: "An existing entry is never rewritten. Pick another version, or fix the manifest." });
|
|
37
|
+
}
|
|
38
|
+
return problems;
|
|
39
|
+
}
|
|
40
|
+
/** Writes the planned files and returns what restores them. */
|
|
41
|
+
function apply(cwd, plan) {
|
|
42
|
+
for (const file of plan) {
|
|
43
|
+
const target = path.join(cwd, file.path);
|
|
44
|
+
mkdirSync(path.dirname(target), { recursive: true });
|
|
45
|
+
writeFileSync(target, file.after);
|
|
46
|
+
}
|
|
47
|
+
return () => {
|
|
48
|
+
for (const file of plan) {
|
|
49
|
+
const target = path.join(cwd, file.path);
|
|
50
|
+
if (file.before === undefined) {
|
|
51
|
+
rmSync(target, { force: true });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
writeFileSync(target, file.before);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The diff of a plan as plain text, without touching git: a new file is shown whole. */
|
|
60
|
+
async function renderDiff(run, plan) {
|
|
61
|
+
const existing = plan.filter((file) => file.before !== undefined).map((file) => file.path);
|
|
62
|
+
// --no-optional-locks: even `git diff` may refresh the index; a dry run writes nothing to git.
|
|
63
|
+
const tracked = existing.length === 0 ? "" : await run(["--no-optional-locks", "diff", "--no-color", "--", ...existing]);
|
|
64
|
+
const created = plan.filter((file) => file.before === undefined).map((file) => `new file ${file.path}\n${file.after.trimEnd().split("\n").map((line) => `+${line}`).join("\n")}\n`);
|
|
65
|
+
return [tracked, ...created].join("");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `opdk release <patch|minor|major|X.Y.Z>`, the local part: preflight, bump the version everywhere, move the
|
|
69
|
+
* changelog entries, run the release check on the result, then commit `chore(release): X.Y.Z` and create the
|
|
70
|
+
* annotated tag `X.Y.Z`, then hands over to the push flow when there is one. With `dryRun` the files are restored and nothing reaches git.
|
|
71
|
+
*/
|
|
72
|
+
export async function runRelease(input) {
|
|
73
|
+
const { cwd, spec, dryRun, flags, config, reporter, run } = input;
|
|
74
|
+
const changelogFile = config.release?.changelog ?? DEFAULT_CHANGELOG;
|
|
75
|
+
const files = loadProjectFiles(cwd, changelogFile);
|
|
76
|
+
const manifest = asRecord(valueOf(files.manifest));
|
|
77
|
+
const current = manifest?.version;
|
|
78
|
+
if (manifest === undefined || typeof current !== "string") {
|
|
79
|
+
return fail(reporter, "bump", [{ message: "manifest.json is missing, not valid or has no version.", hint: "Run opdk from the plugin root." }]);
|
|
80
|
+
}
|
|
81
|
+
const id = typeof manifest.id === "string" ? manifest.id : "plugin";
|
|
82
|
+
const sync = checkVersionSync({ manifest: valueOf(files.manifest), packageJson: valueOf(files.packageJson), lock: valueOf(files.lock) }).filter((problem) => problem.severity === "error");
|
|
83
|
+
if (sync.length > 0) {
|
|
84
|
+
reporter.failure("bump", `${id}: the versions disagree before the bump, so there is no version to start from.`, { details: sync.map((problem) => problem.message), hint: "Make manifest.json, package.json and package-lock.json equal, commit, and rerun." });
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
const version = resolveVersion(spec, current);
|
|
88
|
+
const facts = await collectFacts({ run, version, defaultBranchOverride: config.release?.defaultBranch });
|
|
89
|
+
const gitProblems = preflightProblems(facts, version);
|
|
90
|
+
if (gitProblems.length > 0) {
|
|
91
|
+
return fail(reporter, "git", gitProblems);
|
|
92
|
+
}
|
|
93
|
+
const fileIssues = [...filesProblems(files, current, version), ...changelogPreflight(files.changelog, changelogFile)];
|
|
94
|
+
if (fileIssues.length > 0) {
|
|
95
|
+
return fail(reporter, "bump", fileIssues);
|
|
96
|
+
}
|
|
97
|
+
if (input.push !== undefined && !dryRun) {
|
|
98
|
+
try {
|
|
99
|
+
await input.push.ready();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof StepFailure) {
|
|
103
|
+
return fail(reporter, "gh", [{ message: error.message, hint: `${error.hint} Nothing was changed. Use --no-push to stop at the local tag.` }]);
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (input.test !== undefined) {
|
|
109
|
+
if (!hasTestScript(files)) {
|
|
110
|
+
reporter.warn("test", 'package.json has no "test" script, so no tests ran before the release.');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
reporter.info("test", "npm test (--no-test skips it)");
|
|
114
|
+
const exit = await input.test();
|
|
115
|
+
if (exit !== 0) {
|
|
116
|
+
reporter.failure("test", `npm test failed (exit ${String(exit)}). Nothing was changed.`, { hint: "Fix the tests and rerun. The release commit must not carry code that fails them." });
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
reporter.success("test", "npm test passed");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
reporter.info("bump", `${id}: ${current} -> ${version}${dryRun ? " (dry run)" : ""}`);
|
|
123
|
+
const plan = planBump({ files, changelogFile, version, date: formatDate(input.now()) });
|
|
124
|
+
const restore = apply(cwd, plan);
|
|
125
|
+
// From here until the commit, Ctrl+C must put the five files back and remove the build folders of the check.
|
|
126
|
+
const cleanups = new CleanupSet();
|
|
127
|
+
const unregisterRestore = cleanups.add(restore);
|
|
128
|
+
const guard = guardInterrupt(input.interrupt, cleanups, reporter);
|
|
129
|
+
let keep = false;
|
|
130
|
+
try {
|
|
131
|
+
for (const file of plan) {
|
|
132
|
+
reporter.success("bump", file.before === undefined ? `${file.path} created` : `${file.path} updated`);
|
|
133
|
+
}
|
|
134
|
+
const overlay = plan.map((file) => ({ path: file.path, content: file.after }));
|
|
135
|
+
const code = await runReleaseCheck({ cwd, config, tag: undefined, flags, reporter, cleanups, run, overlay });
|
|
136
|
+
if (guard.interrupted()) {
|
|
137
|
+
return INTERRUPTED_EXIT;
|
|
138
|
+
}
|
|
139
|
+
if (code !== 0) {
|
|
140
|
+
reporter.failure("bump", `${id}: the release check failed on the bumped files. Nothing was committed and the files are restored.`, { hint: "Fix the problems above and rerun." });
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
if (dryRun) {
|
|
144
|
+
input.stdout(`\n${await renderDiff(run, plan)}\n`);
|
|
145
|
+
reporter.info("bump", `dry run: nothing was written, the files are restored. Without --dry-run opdk commits "chore(release): ${version}" and tags ${version}.`);
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
keep = true;
|
|
149
|
+
unregisterRestore();
|
|
150
|
+
guard.stop();
|
|
151
|
+
// The files are committed from here on: Ctrl+C cannot restore them any more, so it says how to finish.
|
|
152
|
+
const unregisterCommitWindow = input.interrupt?.onInterrupt(() => {
|
|
153
|
+
reporter.failure("release", `interrupted while committing: finish the commit and the tag by hand (git commit, git tag -a ${version} -m ${version}), or restore with git`);
|
|
154
|
+
input.interrupt?.exit(INTERRUPTED_EXIT);
|
|
155
|
+
});
|
|
156
|
+
try {
|
|
157
|
+
await run(["add", "--", ...plan.map((file) => file.path)]);
|
|
158
|
+
await run(["commit", "--quiet", "-m", `chore(release): ${version}`]);
|
|
159
|
+
await run(["tag", "-a", version, "-m", version]);
|
|
160
|
+
unregisterCommitWindow?.();
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
unregisterCommitWindow?.();
|
|
164
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)}\nThe bumped files stay in the working tree (staged if \`git add\` ran). Look at \`git status\`: finish the commit and the tag ${version} by hand, or restore the files with git.`, { cause: error });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
guard.stop();
|
|
169
|
+
if (!keep) {
|
|
170
|
+
restore();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
reporter.success("git", `committed "chore(release): ${version}" and created the annotated tag ${version}`);
|
|
174
|
+
if (input.push !== undefined) {
|
|
175
|
+
return input.push.publish(version);
|
|
176
|
+
}
|
|
177
|
+
reporter.info("git", `nothing was pushed (--no-push). Push the tag, wait for the workflow, verify and publish the release, then push the branch: \`opdk release publish ${version}\``);
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A GitHub repository as `gh --repo` names it. */
|
|
2
|
+
export interface RepoSlug {
|
|
3
|
+
readonly owner: string;
|
|
4
|
+
readonly repo: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const slugText: (slug: RepoSlug) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Owner and repository from the URL in `remote.origin.url`: `https://host/o/r(.git)`, `git@host:o/r(.git)`,
|
|
9
|
+
* `ssh://git@host/o/r(.git)`. The host is ignored: `gh` asks github.com, and an SSH alias in the URL still names the
|
|
10
|
+
* right repository. Undefined for anything else (a local path, a URL with more path segments).
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseRemoteUrl(url: string): RepoSlug | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const slugText = (slug) => `${slug.owner}/${slug.repo}`;
|
|
2
|
+
const SCP_LIKE = /^(?:[\w.-]+@)?([\w.-]+):([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/;
|
|
3
|
+
const URL_LIKE = /^(?:https?|ssh|git|git\+ssh):\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/;
|
|
4
|
+
/**
|
|
5
|
+
* Owner and repository from the URL in `remote.origin.url`: `https://host/o/r(.git)`, `git@host:o/r(.git)`,
|
|
6
|
+
* `ssh://git@host/o/r(.git)`. The host is ignored: `gh` asks github.com, and an SSH alias in the URL still names the
|
|
7
|
+
* right repository. Undefined for anything else (a local path, a URL with more path segments).
|
|
8
|
+
*/
|
|
9
|
+
export function parseRemoteUrl(url) {
|
|
10
|
+
const text = url.trim();
|
|
11
|
+
const match = URL_LIKE.exec(text) ?? (text.includes("://") ? null : SCP_LIKE.exec(text));
|
|
12
|
+
const owner = match?.[2];
|
|
13
|
+
const repo = match?.[3];
|
|
14
|
+
return owner === undefined || repo === undefined || repo === "" ? undefined : { owner, repo };
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Difference {
|
|
2
|
+
/** Byte offset of the first byte that differs (or where the shorter file ends). */
|
|
3
|
+
readonly offset: number;
|
|
4
|
+
readonly line: number;
|
|
5
|
+
readonly column: number;
|
|
6
|
+
readonly first: string;
|
|
7
|
+
readonly second: string;
|
|
8
|
+
}
|
|
9
|
+
/** The first place two builds of the same file differ, or undefined when the bytes are equal. */
|
|
10
|
+
export declare function firstDifference(a: Uint8Array, b: Uint8Array): Difference | undefined;
|
|
11
|
+
/** What the committed-tree comparison can find, and what it cannot. */
|
|
12
|
+
export declare const LIKELY_CAUSES: string;
|
|
13
|
+
/** For the fallback comparison of two builds of the same working tree. */
|
|
14
|
+
export declare const LIKELY_CAUSES_SAME_TREE = "Likely causes: a timestamp or random id inlined at build time (Date.now, Math.random, crypto.randomUUID), or a dependency whose output changes between runs. This comparison cannot see files git does not hold or absolute paths: both builds ran in the same folder.";
|
|
15
|
+
/** `comparison` says what was compared, for example "the working tree and the committed tree". */
|
|
16
|
+
export declare function describeDifference(file: string, comparison: string, first: Uint8Array, second: Uint8Array, difference: Difference): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const CONTEXT = 20;
|
|
2
|
+
/** The first place two builds of the same file differ, or undefined when the bytes are equal. */
|
|
3
|
+
export function firstDifference(a, b) {
|
|
4
|
+
const shared = Math.min(a.length, b.length);
|
|
5
|
+
let offset = 0;
|
|
6
|
+
while (offset < shared && a[offset] === b[offset]) {
|
|
7
|
+
offset++;
|
|
8
|
+
}
|
|
9
|
+
if (offset === shared && a.length === b.length) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
let line = 1;
|
|
13
|
+
let lineStart = 0;
|
|
14
|
+
for (let index = 0; index < offset; index++) {
|
|
15
|
+
if (a[index] === 0x0a) {
|
|
16
|
+
line++;
|
|
17
|
+
lineStart = index + 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { offset, line, column: offset - lineStart + 1, first: around(a, offset), second: around(b, offset) };
|
|
21
|
+
}
|
|
22
|
+
function around(bytes, offset) {
|
|
23
|
+
const text = Buffer.from(bytes.subarray(Math.max(0, offset - CONTEXT), offset + CONTEXT)).toString("utf8");
|
|
24
|
+
return JSON.stringify(text);
|
|
25
|
+
}
|
|
26
|
+
/** What the committed-tree comparison can find, and what it cannot. */
|
|
27
|
+
export const LIKELY_CAUSES = "Likely causes: a file the build reads that git does not hold (untracked, or ignored by .gitignore), uncommitted changes, an absolute path of this machine in the output (process.cwd, __dirname, import.meta.url, a path in a comment), or a timestamp or random id inlined at build time (Date.now, Math.random, crypto.randomUUID). " +
|
|
28
|
+
"Not compared: the Node and esbuild versions (this machine's node_modules is reused), lockfile drift, line endings on other operating systems. The community directory rebuilds main.js from the tagged commit and compares the bytes.";
|
|
29
|
+
/** For the fallback comparison of two builds of the same working tree. */
|
|
30
|
+
export const LIKELY_CAUSES_SAME_TREE = "Likely causes: a timestamp or random id inlined at build time (Date.now, Math.random, crypto.randomUUID), or a dependency whose output changes between runs. This comparison cannot see files git does not hold or absolute paths: both builds ran in the same folder.";
|
|
31
|
+
/** `comparison` says what was compared, for example "the working tree and the committed tree". */
|
|
32
|
+
export function describeDifference(file, comparison, first, second, difference) {
|
|
33
|
+
return `${file} differs between ${comparison}: first difference at byte ${String(difference.offset)} (line ${String(difference.line)}, column ${String(difference.column)}), ${String(first.length)} and ${String(second.length)} bytes; ${difference.first} against ${difference.second}.`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the plugin's `npm test` with its output on the terminal and resolves with the exit code. A command that cannot
|
|
3
|
+
* start (no npm) rejects with the fix, so the release stops instead of tagging untested code.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createRunTests(cwd: string, command?: string): () => Promise<number>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Runs the plugin's `npm test` with its output on the terminal and resolves with the exit code. A command that cannot
|
|
4
|
+
* start (no npm) rejects with the fix, so the release stops instead of tagging untested code.
|
|
5
|
+
*/
|
|
6
|
+
export function createRunTests(cwd, command = "npm") {
|
|
7
|
+
return () => new Promise((resolve, reject) => {
|
|
8
|
+
// `npm` is a .cmd file on Windows, which spawn only starts through a shell.
|
|
9
|
+
const child = spawn(command, ["test"], { cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
10
|
+
child.once("error", (error) => {
|
|
11
|
+
reject(new Error(`Could not run \`${command} test\`: ${error.message}. Install Node.js with npm, or skip the tests with --no-test.`, { cause: error }));
|
|
12
|
+
});
|
|
13
|
+
child.once("close", (code, signal) => {
|
|
14
|
+
resolve(code ?? (signal === null ? 1 : 128));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function isPlainVersion(value: string): boolean;
|
|
2
|
+
export declare function isSemver(value: string): boolean;
|
|
3
|
+
/** Negative when `a` is lower than `b`; undefined when either is not a semver. A pre-release is lower than its release. */
|
|
4
|
+
export declare function compareVersions(a: string, b: string): number | undefined;
|
|
5
|
+
export type BumpKind = "patch" | "minor" | "major";
|
|
6
|
+
export declare function isBumpKind(value: string): value is BumpKind;
|
|
7
|
+
/** `1.2.3` becomes `1.2.4`, `1.3.0` or `2.0.0`. */
|
|
8
|
+
export declare function bumpVersion(current: string, kind: BumpKind): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** A plugin version as Obsidian needs it: three numbers. Pre-releases are not supported yet. */
|
|
2
|
+
const PLAIN_VERSION = /^\d+\.\d+\.\d+$/;
|
|
3
|
+
/** The official action's semver regex (`src/manifest.ts` of obsidianmd/obsidian-workflows): a pre-release suffix is accepted. */
|
|
4
|
+
const LOOSE_SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([\w.]+))?$/;
|
|
5
|
+
export function isPlainVersion(value) {
|
|
6
|
+
return PLAIN_VERSION.test(value);
|
|
7
|
+
}
|
|
8
|
+
export function isSemver(value) {
|
|
9
|
+
return LOOSE_SEMVER.test(value);
|
|
10
|
+
}
|
|
11
|
+
function parse(value) {
|
|
12
|
+
const match = LOOSE_SEMVER.exec(value);
|
|
13
|
+
if (match === null) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return { core: [Number(match[1]), Number(match[2]), Number(match[3])], pre: match[4] };
|
|
17
|
+
}
|
|
18
|
+
/** Negative when `a` is lower than `b`; undefined when either is not a semver. A pre-release is lower than its release. */
|
|
19
|
+
export function compareVersions(a, b) {
|
|
20
|
+
const left = parse(a);
|
|
21
|
+
const right = parse(b);
|
|
22
|
+
if (left === undefined || right === undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
for (let index = 0; index < 3; index++) {
|
|
26
|
+
const difference = (left.core[index] ?? 0) - (right.core[index] ?? 0);
|
|
27
|
+
if (difference !== 0) {
|
|
28
|
+
return difference;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (left.pre === right.pre) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
if (left.pre === undefined) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
if (right.pre === undefined) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
return left.pre < right.pre ? -1 : 1;
|
|
41
|
+
}
|
|
42
|
+
export function isBumpKind(value) {
|
|
43
|
+
return value === "patch" || value === "minor" || value === "major";
|
|
44
|
+
}
|
|
45
|
+
/** `1.2.3` becomes `1.2.4`, `1.3.0` or `2.0.0`. */
|
|
46
|
+
export function bumpVersion(current, kind) {
|
|
47
|
+
const parsed = PLAIN_VERSION.test(current) ? parse(current) : undefined;
|
|
48
|
+
if (parsed === undefined) {
|
|
49
|
+
throw new Error(`Cannot bump "${current}": it is not an x.y.z version.`);
|
|
50
|
+
}
|
|
51
|
+
const [major, minor, patch] = parsed.core;
|
|
52
|
+
switch (kind) {
|
|
53
|
+
case "major":
|
|
54
|
+
return `${String(major + 1)}.0.0`;
|
|
55
|
+
case "minor":
|
|
56
|
+
return `${String(major)}.${String(minor + 1)}.0`;
|
|
57
|
+
case "patch":
|
|
58
|
+
return `${String(major)}.${String(minor)}.${String(patch + 1)}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Problem } from "./problems.js";
|
|
2
|
+
/** Where each version lives. `undefined` means the file or the entry is not there. */
|
|
3
|
+
export interface VersionSources {
|
|
4
|
+
readonly manifest: unknown;
|
|
5
|
+
readonly packageJson: unknown;
|
|
6
|
+
/** The parsed package-lock.json, or undefined when the project has none. */
|
|
7
|
+
readonly lock: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface Entry {
|
|
10
|
+
readonly label: string;
|
|
11
|
+
readonly value: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** The versions in manifest.json, package.json and package-lock.json (root `version` and `packages[""].version`). */
|
|
14
|
+
export declare function versionEntries({ manifest, packageJson, lock }: VersionSources): {
|
|
15
|
+
entries: Entry[];
|
|
16
|
+
lockMissing: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The version rules: every place holds an `x.y.z` version, all places agree, and the tag (when one is given)
|
|
20
|
+
* is that version. The version in manifest.json is the reference, because that is what Obsidian reads.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkVersionSync(sources: VersionSources, tag?: string): Problem[];
|
|
23
|
+
/**
|
|
24
|
+
* The tag a check compares with: `--tag` first, else `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` says the run is for a
|
|
25
|
+
* tag (a branch run must not be compared with its branch name).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveTag(flag: string | undefined, env: Readonly<Record<string, string | undefined>>): string | undefined;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { errorProblem, warningProblem } from "./problems.js";
|
|
2
|
+
import { asRecord } from "./json.js";
|
|
3
|
+
import { isPlainVersion } from "./semver.js";
|
|
4
|
+
const GROUP = "versions";
|
|
5
|
+
/** The versions in manifest.json, package.json and package-lock.json (root `version` and `packages[""].version`). */
|
|
6
|
+
export function versionEntries({ manifest, packageJson, lock }) {
|
|
7
|
+
const entries = [
|
|
8
|
+
{ label: "manifest.json", value: asRecord(manifest)?.version },
|
|
9
|
+
{ label: "package.json", value: asRecord(packageJson)?.version },
|
|
10
|
+
];
|
|
11
|
+
const lockRecord = asRecord(lock);
|
|
12
|
+
if (lockRecord !== undefined) {
|
|
13
|
+
entries.push({ label: "package-lock.json version", value: lockRecord.version });
|
|
14
|
+
const root = asRecord(asRecord(lockRecord.packages)?.[""]);
|
|
15
|
+
if (root !== undefined) {
|
|
16
|
+
entries.push({ label: 'package-lock.json packages[""].version', value: root.version });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { entries, lockMissing: lock === undefined };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The version rules: every place holds an `x.y.z` version, all places agree, and the tag (when one is given)
|
|
23
|
+
* is that version. The version in manifest.json is the reference, because that is what Obsidian reads.
|
|
24
|
+
*/
|
|
25
|
+
export function checkVersionSync(sources, tag) {
|
|
26
|
+
const { entries, lockMissing } = versionEntries(sources);
|
|
27
|
+
const problems = [];
|
|
28
|
+
if (lockMissing) {
|
|
29
|
+
problems.push(warningProblem(GROUP, "package-lock.json is missing, so its version was not checked.", "Commit package-lock.json: CI installs with `npm ci`."));
|
|
30
|
+
}
|
|
31
|
+
const reference = entries[0]?.value;
|
|
32
|
+
for (const { label, value } of entries) {
|
|
33
|
+
if (typeof value !== "string" || value === "") {
|
|
34
|
+
problems.push(errorProblem(GROUP, `${label} has no version.`, 'Set "version": "x.y.z".'));
|
|
35
|
+
}
|
|
36
|
+
else if (!isPlainVersion(value)) {
|
|
37
|
+
problems.push(errorProblem(GROUP, `${label} is "${value}", not an x.y.z version.`, "Use three numbers and no prefix: Obsidian looks for a release tagged exactly like the manifest version, and pre-release versions are not supported yet."));
|
|
38
|
+
}
|
|
39
|
+
else if (typeof reference === "string" && value !== reference) {
|
|
40
|
+
problems.push(errorProblem(GROUP, `${label} is ${value} but manifest.json is ${reference}.`, "Make the versions equal in manifest.json, package.json and package-lock.json (`opdk release <patch|minor|major>` sets all of them)."));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (tag !== undefined && typeof reference === "string" && tag !== reference) {
|
|
44
|
+
if (tag === `v${reference}`) {
|
|
45
|
+
problems.push(errorProblem(GROUP, `tag "${tag}" does not match manifest.json version ${reference}: Obsidian release tags have no "v" prefix.`, `Obsidian looks for a release tagged exactly like the manifest version, so the tag must be ${reference}.`));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
problems.push(errorProblem(GROUP, `tag "${tag}" does not match manifest.json version ${reference}.`, `Tag the commit ${reference}, or fix the version in manifest.json.`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return problems;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The tag a check compares with: `--tag` first, else `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` says the run is for a
|
|
55
|
+
* tag (a branch run must not be compared with its branch name).
|
|
56
|
+
*/
|
|
57
|
+
export function resolveTag(flag, env) {
|
|
58
|
+
if (flag !== undefined) {
|
|
59
|
+
return flag;
|
|
60
|
+
}
|
|
61
|
+
const name = env.GITHUB_REF_NAME;
|
|
62
|
+
return env.GITHUB_REF_TYPE === "tag" && name !== undefined && name !== "" ? name : undefined;
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Problem } from "./problems.js";
|
|
2
|
+
import { type Loaded } from "./json.js";
|
|
3
|
+
/**
|
|
4
|
+
* The versions.json rules. The format check is the official action's (`validateVersionsJson` in
|
|
5
|
+
* obsidianmd/obsidian-workflows `src/manifest.ts`: an object of semver keys to semver values), with two more that
|
|
6
|
+
* the directory relies on: the current version maps to the manifest's `minAppVersion`, and `minAppVersion` never
|
|
7
|
+
* goes down as plugin versions go up (Obsidian installs the newest version an old app can run, and a lower
|
|
8
|
+
* mapping on a newer version would hand it a build that needs a newer app).
|
|
9
|
+
*
|
|
10
|
+
* Deviations from the action: a key or value that is not a version is a warning, as it is upstream (only the
|
|
11
|
+
* three rules above and the file itself being missing, invalid or not an object fail the check). Beyond upstream:
|
|
12
|
+
* a missing file is an error, because the directory relies on it, and the current-version and never-lower rules
|
|
13
|
+
* are errors.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkVersionsJson(loaded: Loaded, version: string, minAppVersion: string | undefined): Problem[];
|