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,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manifest.json rules of the release check.
|
|
3
|
+
*
|
|
4
|
+
* Source: the official GitHub Action obsidianmd/obsidian-workflows (v1.2.3), `src/manifest.ts`
|
|
5
|
+
* (`validatePluginManifest`, `validateDescription`, `validateAuthor`, `validateUrl`), read on 2026-11-11, with the
|
|
6
|
+
* same split between errors and warnings. Where the action is more lenient than the scanner's lint rule
|
|
7
|
+
* `obsidianmd/validate-manifest` (eslint-plugin-obsidianmd 0.5.1), the lint rule wins for the three things the
|
|
8
|
+
* developer docs (docs.obsidian.md/Reference/Manifest) call required: `author`, `minAppVersion` and `isDesktopOnly`
|
|
9
|
+
* are errors here, the action only recommends them. `helpUrl` is a known field because the lint rule accepts it.
|
|
10
|
+
*
|
|
11
|
+
* Deliberate differences from the action:
|
|
12
|
+
* - It skips the "obsidian" / "plugin" word check on the id of a plugin that is already in the directory, because an
|
|
13
|
+
* id can never change. The kit cannot know that, so an id with such a word is a warning here, and a name with one
|
|
14
|
+
* is an error as in the action.
|
|
15
|
+
* - `helpUrl` is accepted and its URL is checked like the others.
|
|
16
|
+
* - The action's `author-url-own-repo` check (authorUrl points at the plugin's own repository) needs the repository
|
|
17
|
+
* URL, which the kit does not read; the general warning "authorUrl links to a repository" covers it.
|
|
18
|
+
* - A URL field with the wrong type (`authorUrl`, `helpUrl` not a string; `fundingUrl` neither a string nor an object
|
|
19
|
+
* of strings, arrays included) is an error here.
|
|
20
|
+
*/
|
|
21
|
+
import { errorProblem, warningProblem } from "./problems.js";
|
|
22
|
+
import { asRecord } from "./json.js";
|
|
23
|
+
import { isSemver } from "./semver.js";
|
|
24
|
+
const GROUP = "manifest";
|
|
25
|
+
const KNOWN_FIELDS = new Set([
|
|
26
|
+
"id",
|
|
27
|
+
"name",
|
|
28
|
+
"version",
|
|
29
|
+
"description",
|
|
30
|
+
"minAppVersion",
|
|
31
|
+
"author",
|
|
32
|
+
"authorUrl",
|
|
33
|
+
"fundingUrl",
|
|
34
|
+
"isDesktopOnly",
|
|
35
|
+
"helpUrl",
|
|
36
|
+
]);
|
|
37
|
+
const REQUIRED_STRINGS = ["id", "name", "version", "description", "minAppVersion", "author"];
|
|
38
|
+
const BANNED_WORDS = ["obsidian", "plugin"];
|
|
39
|
+
const AUTHOR_PLACEHOLDERS = new Set(["your name", "author", "me", "unknown", "anonymous", "plugin author", "your-name"]);
|
|
40
|
+
// The lookbehind pins the local part to a run boundary; without it a long run backtracks quadratically.
|
|
41
|
+
const EMAIL = /(?<![A-Z0-9._%+-])[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i;
|
|
42
|
+
const HTTP_URL = /https?:\/\/\S+/i;
|
|
43
|
+
const RAW_IPV4 = /^(?:\d{1,3}\.){3}\d{1,3}$/;
|
|
44
|
+
const error = (message, hint) => errorProblem(GROUP, `manifest.json: ${message}`, hint);
|
|
45
|
+
const warning = (message, hint) => warningProblem(GROUP, `manifest.json: ${message}`, hint);
|
|
46
|
+
/** All findings for the parsed contents of manifest.json. */
|
|
47
|
+
export function checkManifestRules(value) {
|
|
48
|
+
const manifest = asRecord(value);
|
|
49
|
+
if (manifest === undefined) {
|
|
50
|
+
return [error("must contain a JSON object.", 'Write an object such as { "id": "my-plugin", "name": "My Plugin", ... }.')];
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
...checkRequired(manifest),
|
|
54
|
+
...checkId(manifest),
|
|
55
|
+
...checkName(manifest),
|
|
56
|
+
...checkVersion(manifest),
|
|
57
|
+
...checkDescription(manifest),
|
|
58
|
+
...checkMinAppVersion(manifest),
|
|
59
|
+
...checkAuthor(manifest),
|
|
60
|
+
...checkDesktopOnly(manifest),
|
|
61
|
+
...checkUrls(manifest),
|
|
62
|
+
...checkUnknownFields(manifest),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function checkRequired(manifest) {
|
|
66
|
+
const problems = [];
|
|
67
|
+
for (const field of REQUIRED_STRINGS) {
|
|
68
|
+
const present = Object.hasOwn(manifest, field);
|
|
69
|
+
const fieldValue = manifest[field];
|
|
70
|
+
if (!present) {
|
|
71
|
+
problems.push(error(`required field "${field}" is missing.`, `Add "${field}" to manifest.json.`));
|
|
72
|
+
}
|
|
73
|
+
else if (typeof fieldValue !== "string") {
|
|
74
|
+
problems.push(error(`"${field}" must be a string.`, `Change "${field}" to a string.`));
|
|
75
|
+
}
|
|
76
|
+
else if (fieldValue.trim() === "") {
|
|
77
|
+
problems.push(error(`"${field}" is empty.`, `Give "${field}" a value.`));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!Object.hasOwn(manifest, "isDesktopOnly")) {
|
|
81
|
+
problems.push(error('required field "isDesktopOnly" is missing.', 'Add "isDesktopOnly": false (or true when the plugin needs Node or Electron).'));
|
|
82
|
+
}
|
|
83
|
+
return problems;
|
|
84
|
+
}
|
|
85
|
+
function text(manifest, field) {
|
|
86
|
+
const fieldValue = manifest[field];
|
|
87
|
+
return typeof fieldValue === "string" && fieldValue.trim() !== "" ? fieldValue : undefined;
|
|
88
|
+
}
|
|
89
|
+
function bannedWordsIn(value) {
|
|
90
|
+
const lower = value.toLowerCase();
|
|
91
|
+
return BANNED_WORDS.filter((word) => lower.includes(word));
|
|
92
|
+
}
|
|
93
|
+
function checkId(manifest) {
|
|
94
|
+
const id = text(manifest, "id");
|
|
95
|
+
if (id === undefined) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
return bannedWordsIn(id).map((word) => warning(`id "${id}" contains "${word}".`, "The directory asks new plugins to leave it out. An id never changes after the plugin is published, so only a plugin that is not released yet should rename it."));
|
|
99
|
+
}
|
|
100
|
+
function checkName(manifest) {
|
|
101
|
+
const name = text(manifest, "name");
|
|
102
|
+
if (name === undefined) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const problems = bannedWordsIn(name).map((word) => error(`name "${name}" must not contain "${word}".`, `Rename the plugin in manifest.json ("${word}" is implied by the plugin directory).`));
|
|
106
|
+
if (name.length > 50) {
|
|
107
|
+
problems.push(warning(`name is ${String(name.length)} characters long; the maximum is 50.`, "Shorten the name."));
|
|
108
|
+
}
|
|
109
|
+
const capitals = name.match(/[A-Z]/g)?.length ?? 0;
|
|
110
|
+
if (capitals >= 2 && name === name.toUpperCase()) {
|
|
111
|
+
problems.push(warning(`name "${name}" is all capitals.`, "Write the name in normal case."));
|
|
112
|
+
}
|
|
113
|
+
return problems;
|
|
114
|
+
}
|
|
115
|
+
function checkVersion(manifest) {
|
|
116
|
+
const version = text(manifest, "version");
|
|
117
|
+
if (version === undefined) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
if (version === "0.0.0") {
|
|
121
|
+
return [error('version is the placeholder "0.0.0".', "Set the real version of the release.")];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
function checkDescription(manifest) {
|
|
126
|
+
const description = text(manifest, "description");
|
|
127
|
+
if (description === undefined) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
const trimmed = description.trim();
|
|
131
|
+
const lower = trimmed.toLowerCase();
|
|
132
|
+
const name = (text(manifest, "name") ?? "").trim().toLowerCase();
|
|
133
|
+
const problems = [];
|
|
134
|
+
if (trimmed.length < 10) {
|
|
135
|
+
problems.push(warning(`description is ${String(trimmed.length)} characters long; say what the plugin does (10 or more).`));
|
|
136
|
+
}
|
|
137
|
+
if (name !== "" && lower === name) {
|
|
138
|
+
problems.push(error("description is the same as the plugin name.", "Describe what the plugin does."));
|
|
139
|
+
}
|
|
140
|
+
else if (name !== "" && lower.startsWith(name)) {
|
|
141
|
+
problems.push(warning("description starts with the plugin name.", "Start with what the plugin does."));
|
|
142
|
+
}
|
|
143
|
+
if (/\b(?:this plugin|a plugin that|the plugin)\b/i.test(trimmed)) {
|
|
144
|
+
problems.push(warning("description refers to itself as a plugin.", 'Say what it does ("Sync notes to ...") instead of "this plugin ...".'));
|
|
145
|
+
}
|
|
146
|
+
if (trimmed.length > 250) {
|
|
147
|
+
problems.push(error(`description is ${String(trimmed.length)} characters long; the maximum is 250.`, "Shorten it."));
|
|
148
|
+
}
|
|
149
|
+
if (!/[.!?]$/.test(trimmed)) {
|
|
150
|
+
problems.push(warning("description does not end with a period, exclamation mark or question mark.", "End the sentence with punctuation."));
|
|
151
|
+
}
|
|
152
|
+
if (/obsidian/i.test(trimmed)) {
|
|
153
|
+
problems.push(error('description contains the brand name "Obsidian".', "Remove it; the directory already says it is for Obsidian."));
|
|
154
|
+
}
|
|
155
|
+
return problems;
|
|
156
|
+
}
|
|
157
|
+
function checkMinAppVersion(manifest) {
|
|
158
|
+
const minAppVersion = text(manifest, "minAppVersion");
|
|
159
|
+
if (minAppVersion === undefined || isSemver(minAppVersion)) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
return [error(`minAppVersion "${minAppVersion}" is not a version like 1.5.0.`, "Write three numbers separated by dots.")];
|
|
163
|
+
}
|
|
164
|
+
function checkAuthor(manifest) {
|
|
165
|
+
const author = text(manifest, "author");
|
|
166
|
+
if (author === undefined) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
const trimmed = author.trim();
|
|
170
|
+
const problems = [];
|
|
171
|
+
if (AUTHOR_PLACEHOLDERS.has(trimmed.toLowerCase())) {
|
|
172
|
+
problems.push(error(`author "${trimmed}" is a placeholder.`, "Put your name in author."));
|
|
173
|
+
}
|
|
174
|
+
if (EMAIL.test(trimmed)) {
|
|
175
|
+
problems.push(error("author contains an email address.", "Keep only a name in author; put links in authorUrl."));
|
|
176
|
+
}
|
|
177
|
+
if (HTTP_URL.test(trimmed)) {
|
|
178
|
+
problems.push(error("author contains a URL.", "Keep only a name in author; put the link in authorUrl."));
|
|
179
|
+
}
|
|
180
|
+
return problems;
|
|
181
|
+
}
|
|
182
|
+
function checkDesktopOnly(manifest) {
|
|
183
|
+
if (Object.hasOwn(manifest, "isDesktopOnly") && typeof manifest.isDesktopOnly !== "boolean") {
|
|
184
|
+
return [error('"isDesktopOnly" must be true or false.', 'Write it without quotes: "isDesktopOnly": false.')];
|
|
185
|
+
}
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
function checkUrls(manifest) {
|
|
189
|
+
return [...checkUrlField(manifest, "authorUrl"), ...checkFunding(manifest), ...checkUrlField(manifest, "helpUrl")];
|
|
190
|
+
}
|
|
191
|
+
/** A URL field that may be absent but, when present, must be a string holding a valid URL. */
|
|
192
|
+
function checkUrlField(manifest, field) {
|
|
193
|
+
if (!Object.hasOwn(manifest, field)) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
const url = manifest[field];
|
|
197
|
+
if (typeof url !== "string") {
|
|
198
|
+
return [error(`"${field}" must be a string.`, `Write ${field} as a text value such as "https://example.com".`)];
|
|
199
|
+
}
|
|
200
|
+
return checkUrl(url, field);
|
|
201
|
+
}
|
|
202
|
+
/** `fundingUrl` is one URL or an object of platform names to URLs; an array or anything else is refused. */
|
|
203
|
+
function checkFunding(manifest) {
|
|
204
|
+
if (!Object.hasOwn(manifest, "fundingUrl")) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
const funding = manifest.fundingUrl;
|
|
208
|
+
if (typeof funding === "string") {
|
|
209
|
+
return checkUrl(funding, "fundingUrl");
|
|
210
|
+
}
|
|
211
|
+
const labelled = asRecord(funding);
|
|
212
|
+
if (labelled === undefined) {
|
|
213
|
+
return [error('"fundingUrl" must be a string or an object of links.', 'Write "fundingUrl": "https://example.com" or "fundingUrl": { "Coffee": "https://example.com" }.')];
|
|
214
|
+
}
|
|
215
|
+
const problems = [];
|
|
216
|
+
for (const [platform, url] of Object.entries(labelled)) {
|
|
217
|
+
if (typeof url !== "string") {
|
|
218
|
+
problems.push(error(`"fundingUrl.${platform}" must be a string.`, "Give each funding platform a link as text."));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
problems.push(...checkUrl(url, `fundingUrl.${platform}`));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return problems;
|
|
225
|
+
}
|
|
226
|
+
function checkUrl(url, field) {
|
|
227
|
+
let parsed;
|
|
228
|
+
try {
|
|
229
|
+
parsed = new URL(url);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return [error(`${field} "${url}" is not a valid URL.`, "Write a full address such as https://example.com.")];
|
|
233
|
+
}
|
|
234
|
+
const problems = [];
|
|
235
|
+
if (parsed.protocol !== "https:") {
|
|
236
|
+
problems.push(error(`${field} "${url}" must use HTTPS.`, "Change the address to start with https://."));
|
|
237
|
+
}
|
|
238
|
+
if (RAW_IPV4.test(parsed.hostname)) {
|
|
239
|
+
problems.push(error(`${field} "${url}" must not use a bare IP address.`, "Use a host name."));
|
|
240
|
+
}
|
|
241
|
+
if (parsed.hostname === "obsidian.md" || parsed.hostname === "www.obsidian.md") {
|
|
242
|
+
problems.push(error(`${field} "${url}" must not point to obsidian.md.`, "Link to your own page."));
|
|
243
|
+
}
|
|
244
|
+
if (field === "authorUrl" && (parsed.hostname === "github.com" || parsed.hostname === "www.github.com")) {
|
|
245
|
+
if (parsed.pathname.split("/").filter(Boolean).length >= 2) {
|
|
246
|
+
problems.push(warning(`authorUrl "${url}" links to a repository.`, "Link to your profile page instead."));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return problems;
|
|
250
|
+
}
|
|
251
|
+
function checkUnknownFields(manifest) {
|
|
252
|
+
return Object.keys(manifest)
|
|
253
|
+
.filter((field) => !KNOWN_FIELDS.has(field))
|
|
254
|
+
.map((field) => warning(`unknown field "${field}".`, `Obsidian ignores it and the directory reports it. Known fields: ${[...KNOWN_FIELDS].join(", ")}.`));
|
|
255
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RepoFacts } from "./git.js";
|
|
2
|
+
/** One reason the release cannot start, with what to do about it. */
|
|
3
|
+
export interface PreflightProblem {
|
|
4
|
+
readonly message: string;
|
|
5
|
+
readonly hint: string;
|
|
6
|
+
}
|
|
7
|
+
/** Judges the repository state. Pure: `collectFacts` reads the repository, this decides. */
|
|
8
|
+
export declare function preflightProblems(facts: RepoFacts, version: string): PreflightProblem[];
|
|
9
|
+
/** The changelog part of preflight, kept next to the repository part so the bump reports both together. */
|
|
10
|
+
export declare function changelogPreflight(text: string | undefined, file: string): PreflightProblem[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { unreleasedProblem } from "./changelog.js";
|
|
2
|
+
const MAX_LISTED = 5;
|
|
3
|
+
/** Judges the repository state. Pure: `collectFacts` reads the repository, this decides. */
|
|
4
|
+
export function preflightProblems(facts, version) {
|
|
5
|
+
if (!facts.insideRepo) {
|
|
6
|
+
return [{ message: "this folder is not inside a git repository.", hint: "Run opdk from the plugin repository." }];
|
|
7
|
+
}
|
|
8
|
+
const problems = [];
|
|
9
|
+
if (facts.dirty.length > 0) {
|
|
10
|
+
const listed = facts.dirty.slice(0, MAX_LISTED).join(", ");
|
|
11
|
+
const more = facts.dirty.length > MAX_LISTED ? ` and ${String(facts.dirty.length - MAX_LISTED)} more` : "";
|
|
12
|
+
problems.push({ message: `the working tree is not clean (${listed}${more}).`, hint: "Commit or discard the changes first: a release commit contains only the version bump." });
|
|
13
|
+
}
|
|
14
|
+
if (!facts.hasOrigin) {
|
|
15
|
+
problems.push({ message: 'the repository has no remote called "origin".', hint: "Add it with `git remote add origin <url>`: the check for an existing tag and for new commits needs it." });
|
|
16
|
+
}
|
|
17
|
+
problems.push(...branchProblems(facts));
|
|
18
|
+
if (facts.localTag) {
|
|
19
|
+
problems.push({ message: `the tag ${version} already exists locally.`, hint: "Tags are never moved or deleted. Pick a version above the latest tag." });
|
|
20
|
+
}
|
|
21
|
+
if (facts.remoteTag === "present") {
|
|
22
|
+
problems.push({ message: `the tag ${version} already exists on origin.`, hint: "Tags are never moved or deleted. Pick a version above the latest tag." });
|
|
23
|
+
}
|
|
24
|
+
else if (facts.remoteTag === "unreachable") {
|
|
25
|
+
problems.push({ message: `could not ask origin for the tag ${version}: ${facts.remoteTagError ?? "unknown error"}`, hint: "Check the network and your access to origin, then rerun." });
|
|
26
|
+
}
|
|
27
|
+
return problems;
|
|
28
|
+
}
|
|
29
|
+
function branchProblems(facts) {
|
|
30
|
+
const problems = [];
|
|
31
|
+
if (facts.defaultBranch === undefined) {
|
|
32
|
+
if (facts.hasOrigin) {
|
|
33
|
+
problems.push({
|
|
34
|
+
message: "the default branch is unknown: origin/HEAD is not set.",
|
|
35
|
+
hint: 'Run `git remote set-head origin --auto`, or set release.defaultBranch in opdk.config.mjs.',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return problems;
|
|
39
|
+
}
|
|
40
|
+
if (facts.branch !== facts.defaultBranch) {
|
|
41
|
+
problems.push({ message: `releases are cut from ${facts.defaultBranch}, but this is ${facts.branch ?? "a detached HEAD"}.`, hint: `Switch with \`git switch ${facts.defaultBranch}\`.` });
|
|
42
|
+
}
|
|
43
|
+
if (facts.fetchError !== undefined) {
|
|
44
|
+
problems.push({ message: `could not fetch origin: ${facts.fetchError}`, hint: "Check the network and your access to origin, then rerun." });
|
|
45
|
+
}
|
|
46
|
+
else if (facts.behind === undefined) {
|
|
47
|
+
problems.push({ message: `origin has no branch ${facts.defaultBranch} to compare with.`, hint: `Push ${facts.defaultBranch} once, or set release.defaultBranch in opdk.config.mjs.` });
|
|
48
|
+
}
|
|
49
|
+
else if (facts.behind > 0) {
|
|
50
|
+
problems.push({ message: `${facts.defaultBranch} is ${String(facts.behind)} commit(s) behind origin/${facts.defaultBranch}.`, hint: "Run `git pull --ff-only` first." });
|
|
51
|
+
}
|
|
52
|
+
// The tag is pushed before the branch, so the commits behind it would reach the release workflow without ever having run in branch CI.
|
|
53
|
+
if (facts.fetchError === undefined && facts.branch === facts.defaultBranch && facts.ahead !== undefined && facts.ahead > 0) {
|
|
54
|
+
problems.push({
|
|
55
|
+
message: `${facts.defaultBranch} is ${String(facts.ahead)} commit(s) ahead of origin/${facts.defaultBranch}: CI has not seen them, and the release would tag them.`,
|
|
56
|
+
hint: "Push them through a pull request first, wait for CI, pull, and rerun.",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return problems;
|
|
60
|
+
}
|
|
61
|
+
/** The changelog part of preflight, kept next to the repository part so the bump reports both together. */
|
|
62
|
+
export function changelogPreflight(text, file) {
|
|
63
|
+
const problem = unreleasedProblem(text, file);
|
|
64
|
+
return problem === undefined ? [] : [{ message: problem, hint: "The release notes come from [Unreleased]; write them before releasing." }];
|
|
65
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The parts of a release check, in the order they run and print. */
|
|
2
|
+
export declare const CHECK_GROUPS: readonly ["versions", "versions.json", "manifest", "changelog", "kit", "build", "assets", "reproducible", "api"];
|
|
3
|
+
export type CheckGroup = (typeof CHECK_GROUPS)[number];
|
|
4
|
+
/** One thing a release check found. Errors fail the check, warnings print as `!` lines and do not. */
|
|
5
|
+
export interface Problem {
|
|
6
|
+
readonly group: CheckGroup;
|
|
7
|
+
readonly severity: "error" | "warning";
|
|
8
|
+
/** What is wrong, with the values involved. */
|
|
9
|
+
readonly message: string;
|
|
10
|
+
/** What to do about it. */
|
|
11
|
+
readonly hint?: string;
|
|
12
|
+
/** Extra lines under the problem, such as esbuild's messages. */
|
|
13
|
+
readonly details?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export declare function errorProblem(group: CheckGroup, message: string, hint?: string, details?: readonly string[]): Problem;
|
|
16
|
+
export declare function warningProblem(group: CheckGroup, message: string, hint?: string): Problem;
|
|
17
|
+
/** What one group found, plus the sentence that says it passed. */
|
|
18
|
+
export interface GroupResult {
|
|
19
|
+
readonly group: CheckGroup;
|
|
20
|
+
/** Printed after a `✓` when the group has no errors. */
|
|
21
|
+
readonly passed: string;
|
|
22
|
+
readonly problems: readonly Problem[];
|
|
23
|
+
}
|
|
24
|
+
export declare function hasErrors(problems: readonly Problem[]): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The parts of a release check, in the order they run and print. */
|
|
2
|
+
export const CHECK_GROUPS = ["versions", "versions.json", "manifest", "changelog", "kit", "build", "assets", "reproducible", "api"];
|
|
3
|
+
export function errorProblem(group, message, hint, details) {
|
|
4
|
+
return { group, severity: "error", message, ...(hint !== undefined && { hint }), ...(details !== undefined && { details }) };
|
|
5
|
+
}
|
|
6
|
+
export function warningProblem(group, message, hint) {
|
|
7
|
+
return { group, severity: "warning", message, ...(hint !== undefined && { hint }) };
|
|
8
|
+
}
|
|
9
|
+
export function hasErrors(problems) {
|
|
10
|
+
return problems.some((problem) => problem.severity === "error");
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Loaded } from "./json.js";
|
|
2
|
+
/** The files a release reads, as found in the plugin folder. */
|
|
3
|
+
export interface ProjectFiles {
|
|
4
|
+
readonly packageJson: Loaded;
|
|
5
|
+
readonly lock: Loaded;
|
|
6
|
+
readonly manifest: Loaded;
|
|
7
|
+
readonly versions: Loaded;
|
|
8
|
+
/** Text of the changelog, undefined when the file does not exist. */
|
|
9
|
+
readonly changelog: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_CHANGELOG = "CHANGELOG.md";
|
|
12
|
+
export declare function loadProjectFiles(cwd: string, changelog?: string): ProjectFiles;
|
|
13
|
+
/** The parsed value of a file that was read, else undefined. */
|
|
14
|
+
export declare function valueOf(loaded: Loaded): unknown;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { loadJson, loadText } from "./json.js";
|
|
3
|
+
export const DEFAULT_CHANGELOG = "CHANGELOG.md";
|
|
4
|
+
export function loadProjectFiles(cwd, changelog = DEFAULT_CHANGELOG) {
|
|
5
|
+
return {
|
|
6
|
+
packageJson: loadJson(path.join(cwd, "package.json")),
|
|
7
|
+
lock: loadJson(path.join(cwd, "package-lock.json")),
|
|
8
|
+
manifest: loadJson(path.join(cwd, "manifest.json")),
|
|
9
|
+
versions: loadJson(path.join(cwd, "versions.json")),
|
|
10
|
+
changelog: loadText(path.join(cwd, changelog)),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** The parsed value of a file that was read, else undefined. */
|
|
14
|
+
export function valueOf(loaded) {
|
|
15
|
+
return loaded.kind === "ok" ? loaded.value : undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Reporter } from "../cli/reporter.js";
|
|
2
|
+
import type { OpdkConfig } from "../config/types.js";
|
|
3
|
+
import type { PushOptions } from "./args.js";
|
|
4
|
+
import { type RunGit } from "./git.js";
|
|
5
|
+
import type { InterruptHooks } from "./interrupt.js";
|
|
6
|
+
import type { PushFlow } from "./release.js";
|
|
7
|
+
export interface PublishContext {
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly config: OpdkConfig;
|
|
10
|
+
readonly reporter: Reporter;
|
|
11
|
+
readonly pushing: PushOptions;
|
|
12
|
+
readonly interrupt?: InterruptHooks;
|
|
13
|
+
}
|
|
14
|
+
/** The push flow `opdk release <bump>` runs after the tag. */
|
|
15
|
+
export declare function createPushFlow(context: PublishContext): PushFlow;
|
|
16
|
+
/** `opdk release publish [X.Y.Z]`: continues the push flow from an existing local tag. */
|
|
17
|
+
export declare function runPublishCommand(context: PublishContext, version: string | undefined): Promise<number>;
|
|
18
|
+
/** `opdk release notes [X.Y.Z]`: the body of the changelog section, ready to print. Throws a message with the fix. */
|
|
19
|
+
export declare function changelogNotes(cwd: string, config: OpdkConfig, version: string | undefined): string;
|
|
20
|
+
/** The notes of `version` in the changelog as committed at that tag, which is what the workflow checks out, not the working tree. */
|
|
21
|
+
export declare function tagChangelogNotes(run: RunGit, config: OpdkConfig, version: string): Promise<string>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { resolveBuild } from "../build/options.js";
|
|
4
|
+
import { createRunGh } from "./gh.js";
|
|
5
|
+
import { checkGhAccess } from "./gh-access.js";
|
|
6
|
+
import { createRunGit } from "./git.js";
|
|
7
|
+
import { asRecord } from "./json.js";
|
|
8
|
+
import { DEFAULT_APPEAR_MS, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MINUTES, runPublish } from "./publish.js";
|
|
9
|
+
import { releaseNotes } from "./changelog.js";
|
|
10
|
+
import { DEFAULT_CHANGELOG, loadProjectFiles, valueOf } from "./project-files.js";
|
|
11
|
+
function publishInput(context, version) {
|
|
12
|
+
const { cwd, config } = context;
|
|
13
|
+
const run = createRunGit(cwd);
|
|
14
|
+
return {
|
|
15
|
+
version,
|
|
16
|
+
reporter: context.reporter,
|
|
17
|
+
run,
|
|
18
|
+
gh: createRunGh(cwd),
|
|
19
|
+
defaultBranch: config.release?.defaultBranch,
|
|
20
|
+
notes: (tag) => tagChangelogNotes(run, config, tag),
|
|
21
|
+
buildTagged: async (cleanups) => {
|
|
22
|
+
// Loaded here: the build pulls in esbuild.
|
|
23
|
+
const { buildTagged } = await import("./build-tagged.js");
|
|
24
|
+
return buildTagged({ cwd, run, version, build: resolveBuild(config.build), cleanups });
|
|
25
|
+
},
|
|
26
|
+
zip: context.pushing.zip,
|
|
27
|
+
timeoutMs: (context.pushing.timeoutMinutes ?? DEFAULT_TIMEOUT_MINUTES) * 60_000,
|
|
28
|
+
appearMs: DEFAULT_APPEAR_MS,
|
|
29
|
+
pollMs: DEFAULT_POLL_MS,
|
|
30
|
+
clock: { now: () => Date.now(), sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) },
|
|
31
|
+
...(context.interrupt !== undefined && { interrupt: context.interrupt }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** The push flow `opdk release <bump>` runs after the tag. */
|
|
35
|
+
export function createPushFlow(context) {
|
|
36
|
+
return {
|
|
37
|
+
ready: async () => {
|
|
38
|
+
await checkGhAccess(createRunGit(context.cwd), createRunGh(context.cwd));
|
|
39
|
+
},
|
|
40
|
+
publish: (version) => runPublish(publishInput(context, version)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function manifestVersion(cwd) {
|
|
44
|
+
const files = loadProjectFiles(cwd);
|
|
45
|
+
const version = asRecord(valueOf(files.manifest))?.version;
|
|
46
|
+
if (typeof version !== "string") {
|
|
47
|
+
throw new Error("manifest.json is missing, not valid or has no version. Run opdk from the plugin root, or pass the version: opdk release publish X.Y.Z");
|
|
48
|
+
}
|
|
49
|
+
return version;
|
|
50
|
+
}
|
|
51
|
+
/** `opdk release publish [X.Y.Z]`: continues the push flow from an existing local tag. */
|
|
52
|
+
export function runPublishCommand(context, version) {
|
|
53
|
+
return runPublish(publishInput(context, version ?? manifestVersion(context.cwd)));
|
|
54
|
+
}
|
|
55
|
+
/** `opdk release notes [X.Y.Z]`: the body of the changelog section, ready to print. Throws a message with the fix. */
|
|
56
|
+
export function changelogNotes(cwd, config, version) {
|
|
57
|
+
const file = changelogFile(config);
|
|
58
|
+
let text;
|
|
59
|
+
try {
|
|
60
|
+
text = readFileSync(path.join(cwd, file), "utf8");
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new Error(`Cannot read ${file}: ${error instanceof Error ? error.message : String(error)}. Run opdk from the plugin root, or set release.changelog in opdk.config.mjs.`, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
return notesOf(text, file, version ?? manifestVersion(cwd));
|
|
66
|
+
}
|
|
67
|
+
/** The notes of `version` in the changelog as committed at that tag, which is what the workflow checks out, not the working tree. */
|
|
68
|
+
export async function tagChangelogNotes(run, config, version) {
|
|
69
|
+
const file = changelogFile(config);
|
|
70
|
+
return notesOf(await run(["show", `${version}:${file}`]), file, version);
|
|
71
|
+
}
|
|
72
|
+
const changelogFile = (config) => config.release?.changelog ?? DEFAULT_CHANGELOG;
|
|
73
|
+
/** The notes of `version` in the changelog text, in the form `opdk release notes` prints them. */
|
|
74
|
+
function notesOf(text, file, wanted) {
|
|
75
|
+
const notes = releaseNotes(text, wanted);
|
|
76
|
+
if (notes === undefined) {
|
|
77
|
+
throw new Error(`${file} has no "## [${wanted}]" section. Move the entries of "## [Unreleased]" under it, or run \`opdk release <patch|minor|major>\`.`);
|
|
78
|
+
}
|
|
79
|
+
if (notes === "") {
|
|
80
|
+
throw new Error(`The "## [${wanted}]" section of ${file} is empty. Say what changed in this version.`);
|
|
81
|
+
}
|
|
82
|
+
return `${notes}\n`;
|
|
83
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RunGit } from "./git.js";
|
|
2
|
+
/** What the push flow needs to know about the local tag. */
|
|
3
|
+
export interface TagFacts {
|
|
4
|
+
readonly version: string;
|
|
5
|
+
/** The id of the annotated tag object, what `ls-remote` shows on origin. */
|
|
6
|
+
readonly tagObject: string;
|
|
7
|
+
/** The commit the tag points at. */
|
|
8
|
+
readonly commit: string;
|
|
9
|
+
readonly branch: string;
|
|
10
|
+
/** `id` of the manifest committed at the tag. */
|
|
11
|
+
readonly pluginId: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TagFactsInput {
|
|
14
|
+
readonly run: RunGit;
|
|
15
|
+
readonly version: string;
|
|
16
|
+
readonly defaultBranchOverride: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Judges the local tag before anything is pushed: it exists, it is annotated, its manifest holds the same version,
|
|
20
|
+
* the default branch is known and contains the tagged commit. The workflow refuses a tag that fails the second or
|
|
21
|
+
* the last of these, so catching them here saves a pushed tag that cannot be undone.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readTagFacts({ run, version, defaultBranchOverride }: TagFactsInput): Promise<TagFacts>;
|
|
24
|
+
/** Where the tag is on origin: not there, there with the same tag object, or there pointing elsewhere. */
|
|
25
|
+
export type RemoteTag = "absent" | "same" | "different";
|
|
26
|
+
export declare function remoteTagState(run: RunGit, facts: TagFacts): Promise<RemoteTag>;
|
|
27
|
+
/** Pushes the tag, and only the tag. No force flag exists in this module: a tag on origin is never overwritten. */
|
|
28
|
+
export declare function pushTag(run: RunGit, facts: TagFacts): Promise<"pushed" | "already-there">;
|
|
29
|
+
/**
|
|
30
|
+
* Pushes the release commit to the default branch without force, not the local branch tip: later local commits are
|
|
31
|
+
* not part of the release and stay local. When origin's branch already is that commit or contains it (an earlier run
|
|
32
|
+
* got as far, or the merge was pushed by hand after a rejection), nothing is pushed. The release is public by now, so
|
|
33
|
+
* a rejection (somebody pushed meanwhile) is reported as such, with the way out that keeps the tagged commit in the
|
|
34
|
+
* history. A protected branch is reported separately, because merging origin's commits does not get the release commit
|
|
35
|
+
* past the rule.
|
|
36
|
+
*/
|
|
37
|
+
export declare function pushBranch(run: RunGit, facts: TagFacts): Promise<"pushed" | "already-there">;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { tryGit } from "./git.js";
|
|
2
|
+
import { asRecord } from "./json.js";
|
|
3
|
+
import { StepFailure } from "./publish-state.js";
|
|
4
|
+
/**
|
|
5
|
+
* Judges the local tag before anything is pushed: it exists, it is annotated, its manifest holds the same version,
|
|
6
|
+
* the default branch is known and contains the tagged commit. The workflow refuses a tag that fails the second or
|
|
7
|
+
* the last of these, so catching them here saves a pushed tag that cannot be undone.
|
|
8
|
+
*/
|
|
9
|
+
export async function readTagFacts({ run, version, defaultBranchOverride }) {
|
|
10
|
+
const ref = `refs/tags/${version}`;
|
|
11
|
+
const tagObject = await tryGit(run, ["rev-parse", "--verify", "--quiet", ref]);
|
|
12
|
+
const commit = await tryGit(run, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
13
|
+
if (tagObject === undefined || commit === undefined || tagObject === "") {
|
|
14
|
+
throw new StepFailure(`there is no local tag ${version}.`, `Cut the release first with \`opdk release <patch|minor|major>\`, or pass the version of an existing tag: \`opdk release publish X.Y.Z\`.`);
|
|
15
|
+
}
|
|
16
|
+
if ((await tryGit(run, ["cat-file", "-t", ref])) !== "tag") {
|
|
17
|
+
throw new StepFailure(`the tag ${version} is a lightweight tag.`, `Release tags are annotated. Tags are never moved, so pick a new version with \`opdk release <patch|minor|major>\`.`, [], false);
|
|
18
|
+
}
|
|
19
|
+
const manifestText = await tryGit(run, ["show", `${ref}:manifest.json`]);
|
|
20
|
+
let manifest;
|
|
21
|
+
try {
|
|
22
|
+
manifest = manifestText === undefined ? undefined : asRecord(JSON.parse(manifestText));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
manifest = undefined;
|
|
26
|
+
}
|
|
27
|
+
if (manifest === undefined) {
|
|
28
|
+
throw new StepFailure(`manifest.json at the tag ${version} is missing or not valid JSON.`, "Tags are never moved: fix it and release a new version with `opdk release patch`.", [], false);
|
|
29
|
+
}
|
|
30
|
+
if (manifest.version !== version) {
|
|
31
|
+
throw new StepFailure(`the tag ${version} holds a manifest.json with version ${String(manifest.version)}.`, "Obsidian looks for a release tagged exactly like the manifest version. Tags are never moved: release a new version with `opdk release patch`.", [], false);
|
|
32
|
+
}
|
|
33
|
+
const symbolic = defaultBranchOverride === undefined ? await tryGit(run, ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]) : undefined;
|
|
34
|
+
const branch = defaultBranchOverride ?? symbolic?.replace(/^refs\/remotes\/origin\//, "");
|
|
35
|
+
if (branch === undefined || branch === "") {
|
|
36
|
+
throw new StepFailure("the default branch is unknown: origin/HEAD is not set.", "Run `git remote set-head origin --auto`, or set release.defaultBranch in opdk.config.mjs.");
|
|
37
|
+
}
|
|
38
|
+
if ((await tryGit(run, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`])) === undefined) {
|
|
39
|
+
throw new StepFailure(`there is no local branch ${branch}.`, `Switch to it with \`git switch ${branch}\` and rerun.`);
|
|
40
|
+
}
|
|
41
|
+
if ((await tryGit(run, ["merge-base", "--is-ancestor", commit, `refs/heads/${branch}`])) === undefined) {
|
|
42
|
+
throw new StepFailure(`the tag ${version} is not on ${branch}: ${branch} does not contain its commit.`, `The release commit must be part of ${branch}. Merge or cherry-pick it there, or release a new version from ${branch}.`);
|
|
43
|
+
}
|
|
44
|
+
const id = manifest.id;
|
|
45
|
+
return { version, tagObject, commit, branch, pluginId: typeof id === "string" ? id : "plugin" };
|
|
46
|
+
}
|
|
47
|
+
export async function remoteTagState(run, facts) {
|
|
48
|
+
const ref = `refs/tags/${facts.version}`;
|
|
49
|
+
const listed = await run(["ls-remote", "--tags", "origin", ref]);
|
|
50
|
+
const line = listed.split("\n").find((entry) => entry.endsWith(`\t${ref}`));
|
|
51
|
+
if (line === undefined) {
|
|
52
|
+
return "absent";
|
|
53
|
+
}
|
|
54
|
+
return line.startsWith(`${facts.tagObject}\t`) ? "same" : "different";
|
|
55
|
+
}
|
|
56
|
+
/** Pushes the tag, and only the tag. No force flag exists in this module: a tag on origin is never overwritten. */
|
|
57
|
+
export async function pushTag(run, facts) {
|
|
58
|
+
const state = await remoteTagState(run, facts);
|
|
59
|
+
if (state === "different") {
|
|
60
|
+
throw new StepFailure(`origin already has a tag ${facts.version} that points elsewhere.`, "Tags are never moved or deleted. Pick a version above the latest tag with `opdk release patch` (or minor, major).", [], false);
|
|
61
|
+
}
|
|
62
|
+
if (state === "same") {
|
|
63
|
+
return "already-there";
|
|
64
|
+
}
|
|
65
|
+
await run(["push", "origin", `refs/tags/${facts.version}`]);
|
|
66
|
+
return "pushed";
|
|
67
|
+
}
|
|
68
|
+
const REJECTED = /rejected|non-fast-forward|fetch first|failed to push some refs/i;
|
|
69
|
+
/**
|
|
70
|
+
* A refusal by the server rather than a non-fast-forward: git's reason in parentheses for a protected branch or a
|
|
71
|
+
* repository rule, a server hook that declined the push, or GitHub's codes `GH006` / `GH013` as whole words. Only
|
|
72
|
+
* these exact phrases count, because the error text also carries the remote URL, whose owner or name may contain any
|
|
73
|
+
* word. It also contains "rejected", so it is told apart before the non-fast-forward case: pulling cannot fix it.
|
|
74
|
+
*/
|
|
75
|
+
const PROTECTED = /\((?:protected branch hook declined|push declined due to repository rule violations|pre-receive hook declined)\)|\bGH0(?:06|13)\b/;
|
|
76
|
+
/**
|
|
77
|
+
* Pushes the release commit to the default branch without force, not the local branch tip: later local commits are
|
|
78
|
+
* not part of the release and stay local. When origin's branch already is that commit or contains it (an earlier run
|
|
79
|
+
* got as far, or the merge was pushed by hand after a rejection), nothing is pushed. The release is public by now, so
|
|
80
|
+
* a rejection (somebody pushed meanwhile) is reported as such, with the way out that keeps the tagged commit in the
|
|
81
|
+
* history. A protected branch is reported separately, because merging origin's commits does not get the release commit
|
|
82
|
+
* past the rule.
|
|
83
|
+
*/
|
|
84
|
+
export async function pushBranch(run, facts) {
|
|
85
|
+
const listed = await run(["ls-remote", "origin", `refs/heads/${facts.branch}`]);
|
|
86
|
+
const remoteTip = listed.split("\n").find((entry) => entry.endsWith(`\trefs/heads/${facts.branch}`))?.split("\t")[0];
|
|
87
|
+
if (remoteTip !== undefined && remoteTip !== facts.commit) {
|
|
88
|
+
// The ancestry test needs origin's tip as an object here: origin may hold the release commit plus newer commits this clone never fetched.
|
|
89
|
+
await run(["fetch", "--no-tags", "origin", facts.branch]);
|
|
90
|
+
}
|
|
91
|
+
if (remoteTip !== undefined && (remoteTip === facts.commit || (await tryGit(run, ["merge-base", "--is-ancestor", facts.commit, remoteTip])) !== undefined)) {
|
|
92
|
+
return "already-there";
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await run(["push", "origin", `${facts.commit}:refs/heads/${facts.branch}`]);
|
|
96
|
+
return "pushed";
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
if (PROTECTED.test(message)) {
|
|
101
|
+
throw new StepFailure(`origin refused the push of ${facts.branch} (a branch protection, a repository rule or a server hook). The release ${facts.version} is already public.`, `Get the release commit ${facts.commit} onto ${facts.branch} the way the rule allows (a pull request, or an account that may bypass it); pulling will not help. The manifest on ${facts.branch} must reach the version ${facts.version} for Obsidian to offer it. The commit itself has to land (a squash or rebase merge makes another commit).`, [message]);
|
|
102
|
+
}
|
|
103
|
+
if (REJECTED.test(message)) {
|
|
104
|
+
throw new StepFailure(`origin rejected the push of ${facts.branch}: it has commits that are not here. The release ${facts.version} is already public.`, `Merge them without rewriting the release commit: \`git pull --no-rebase origin ${facts.branch}\`, then \`git push origin ${facts.branch}\`. The manifest on ${facts.branch} must reach the version ${facts.version} for Obsidian to offer it.`, [message]);
|
|
105
|
+
}
|
|
106
|
+
throw new StepFailure(`could not push ${facts.branch}: ${message}`, `The release ${facts.version} is already public. Fix the problem above and run \`git push origin ${facts.branch}\`.`);
|
|
107
|
+
}
|
|
108
|
+
}
|