Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ignore": [
"@taskless/vale-darwin-arm64",
"@taskless/vale-darwin-x64",
"@taskless/vale-grammars",
"@taskless/vale-linux-arm64",
"@taskless/vale-linux-x64",
"@taskless/vale-win32-arm64",
Expand Down
9 changes: 9 additions & 0 deletions .github/scripts/release-notes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ async function fetchRelease(repository, reference) {
tag: release.tag_name,
notes: typeof release.body === "string" ? release.body : "",
url: typeof release.html_url === "string" ? release.html_url : undefined,
// Each asset's `digest` is the `sha256:<hex>` GitHub records at upload.
// vale-detect.cjs pins Vale's grammar archives by it, since upstream's
// checksums file does not cover them.
assets: Array.isArray(release.assets)
? release.assets.map((asset) => ({
name: asset?.name,
digest: asset?.digest ?? undefined,
}))
: [],
};
}

Expand Down
12 changes: 11 additions & 1 deletion .github/scripts/vale-detect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ async function main({
console.log(`fetching ${checksumsUrl}`);
const checksumsText = await text(checksumsUrl);

const plan = planManifestUpdate({ manifest, upstreamTag, checksumsText });
const plan = planManifestUpdate({
manifest,
upstreamTag,
checksumsText,
releaseAssets: release.assets,
});
console.log(
`Upstream ${plan.upstreamVersion} is ahead of ${plan.pinnedVersion}.`
);
Expand All @@ -178,6 +183,11 @@ async function main({
` ${applyTemplate(platform.asset, { version: plan.upstreamVersion })} ${platform.sha256}`
);
}
for (const module_ of plan.manifest.grammars.modules) {
console.log(
` ${applyTemplate(plan.manifest.grammars.asset, { name: module_.name })} ${module_.sha256}`
);
}

if (write) {
writeFileSync(MANIFEST_PATH, `${JSON.stringify(plan.manifest, null, 2)}\n`);
Expand Down
38 changes: 38 additions & 0 deletions .github/scripts/vale-detect.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ function checksumsFor(version) {
.join("\n")}\n`;
}

/**
* The release's asset list as the GitHub API returns it: every grammar the
* committed manifest pins, each with a recorded digest.
*/
function assetsFor() {
return MANIFEST.grammars.modules.map((module_, index) => ({
name: `grammar-${module_.name}.zip`,
digest: `sha256:${digestFor(index)}`,
}));
}

/**
* Run main() with both fetches stubbed and $GITHUB_OUTPUT pointed at a temp
* file, then return the parsed step outputs plus which URLs were fetched.
Expand All @@ -55,6 +66,7 @@ async function runDetect({
checksums,
argv = [],
wantNotes = false,
assets = assetsFor(),
}) {
const directory = mkdtempSync(join(tmpdir(), "vale-detect-test-"));
const outputPath = join(directory, "github-output");
Expand All @@ -70,6 +82,7 @@ async function runDetect({
tag: upstreamTag,
notes,
url: `https://github.com/${MANIFEST.upstream.repository}/releases/tag/${upstreamTag}`,
assets,
}),
text: async (url) => {
fetched.push(url);
Expand Down Expand Up @@ -264,3 +277,28 @@ test("detect: a repository with no releases aborts rather than reporting current
/has no published releases/
);
});

test("detect: the grammar list and digests come from the release's assets", async () => {
// main() hands the release's asset list to planManifestUpdate. Withholding
// the grammar assets proves it reaches there: the plan refuses a release
// with none, rather than carrying the old list forward unreviewed.
await assert.rejects(
runDetect({
upstreamTag: "v3.99.0",
checksums: checksumsFor("3.99.0"),
assets: [],
}),
/upstream 3\.99\.0 publishes no grammar-\*\.zip assets/
);
});

test("detect: a grammar asset with no recorded digest aborts", async () => {
await assert.rejects(
runDetect({
upstreamTag: "v3.99.0",
checksums: checksumsFor("3.99.0"),
assets: [{ name: "grammar-go.zip" }],
}),
/grammar-go\.zip has no recorded sha256 digest/
);
});
44 changes: 23 additions & 21 deletions .github/scripts/vale-gate.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* vale-manifest.json (plus explicit dispatch). That `paths:` filter cannot see
* WHY the file changed: correcting a typo in its comment block, reformatting
* it, or fixing a digest all look identical to a version bump, and each one
* would publish six fresh packages. Publishing is not idempotent here — every
* would publish seven fresh packages. Publishing is not idempotent here — every
* run stamps <valeVersion>-<yyyymmddhhmmss>, a version npm has never seen — so
* nothing downstream can absorb the mistake.
*
Expand All @@ -19,9 +19,10 @@
*
* WHAT IT DELIBERATELY DOES NOT DO. It never suppresses an explicit dispatch:
* a human asking for a publish gets one, stamp collision or not. And it skips
* only when ALL six packages already carry the pinned base version. Checking a
* single package would silently skip a half-published set, so requiring all six
* makes the gate double as partial-release repair — it re-runs precisely the
* only when ALL seven packages (the six platform packages and the grammar
* package) already carry the pinned base version. Checking a single package
* would silently skip a half-published set, so requiring all seven makes the
* gate double as partial-release repair — it re-runs precisely the
* case the publish loop's failure aggregation is there to report.
*
* Usage:
Expand All @@ -35,7 +36,7 @@
const { appendFileSync, readFileSync } = require("node:fs");
const { join } = require("node:path");

const { assertManifest } = require("./vale-release.cjs");
const { assertManifest, manifestPackages } = require("./vale-release.cjs");

const MANIFEST_PATH = join(__dirname, "vale-manifest.json");
const REGISTRY = "https://registry.npmjs.org";
Expand Down Expand Up @@ -85,15 +86,17 @@ async function fetchPublishedVersions(packageName) {
* forced, nothing published, everything published, and a partial set.
*/
function planPublish({ manifest, publishedByPackage, forced }) {
const missing = manifest.platforms
// Every package the manifest releases, the grammar package included: binaries
// published without their grammars are not a published release.
const missing = manifestPackages(manifest)
.filter(
(platform) =>
(entry) =>
!coversVersion(
publishedByPackage[platform.package] ?? [],
publishedByPackage[entry.package] ?? [],
manifest.valeVersion
)
)
.map((platform) => platform.package);
.map((entry) => entry.package);

if (forced) {
return { shouldPublish: true, missing, reason: "forced" };
Expand All @@ -114,35 +117,34 @@ async function main({
JSON.parse(readFileSync(MANIFEST_PATH, "utf8"))
);

// Concurrent, not sequential: the six lookups are independent, and this job
// Concurrent, not sequential: the seven lookups are independent, and this job
// exists to decide cheaply BEFORE prepare downloads ~60 MB. Sequential awaits
// would make the gate six round trips deep for no reason.
// would make the gate seven round trips deep for no reason.
const packages = manifestPackages(manifest);
const publishedByPackage = Object.fromEntries(
await Promise.all(
manifest.platforms.map(async (platform) => [
platform.package,
await published(platform.package),
packages.map(async (entry) => [
entry.package,
await published(entry.package),
])
)
);

const plan = planPublish({ manifest, publishedByPackage, forced });

console.log(`Vale ${manifest.valeVersion}`);
for (const platform of manifest.platforms) {
const covered = !plan.missing.includes(platform.package);
console.log(
` ${covered ? "published" : "MISSING "} ${platform.package}`
);
for (const entry of packages) {
const covered = !plan.missing.includes(entry.package);
console.log(` ${covered ? "published" : "MISSING "} ${entry.package}`);
}

if (plan.reason === "forced") {
console.log(
`\nExplicitly dispatched — publishing regardless (${plan.missing.length} of ${manifest.platforms.length} not yet on the registry).`
`\nExplicitly dispatched — publishing regardless (${plan.missing.length} of ${packages.length} not yet on the registry).`
);
} else if (plan.shouldPublish) {
console.log(
`\n${plan.missing.length} of ${manifest.platforms.length} package(s) lack Vale ${manifest.valeVersion}. Publishing.`
`\n${plan.missing.length} of ${packages.length} package(s) lack Vale ${manifest.valeVersion}. Publishing.`
);
} else {
console.log(
Expand Down
33 changes: 31 additions & 2 deletions .github/scripts/vale-gate.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* Tests for vale-gate.cjs — the decision that keeps an unrelated edit to
* vale-manifest.json from publishing six packages.
* vale-manifest.json from publishing seven packages.
*
* The interesting cases are all "what does the registry already have", so the
* registry is stubbed throughout and nothing here touches the network. The
Expand All @@ -22,7 +22,10 @@ const MANIFEST = JSON.parse(
readFileSync(join(__dirname, "vale-manifest.json"), "utf8")
);
const PINNED = MANIFEST.valeVersion;
const PACKAGES = MANIFEST.platforms.map((platform) => platform.package);
const PACKAGES = [
...MANIFEST.platforms.map((platform) => platform.package),
MANIFEST.grammars.package,
];

/** A registry stub answering from a {package: [versions]} table. */
const registry = (table) => async (packageName) => table[packageName] ?? [];
Expand Down Expand Up @@ -131,3 +134,29 @@ test("a 404 package reads as unpublished rather than failing the gate", async ()
assert.equal(plan.shouldPublish, true);
assert.deepEqual(plan.missing, PACKAGES);
});

test("publishes when the binaries are out and the grammars are not", () => {
// Binaries without their grammars are not a published release: a CLI
// pinned to that set would read code comments by delimiters.
const table = allPublished();
delete table[MANIFEST.grammars.package];
const plan = planPublish({
manifest: MANIFEST,
publishedByPackage: table,
forced: false,
});
assert.equal(plan.shouldPublish, true);
assert.deepEqual(plan.missing, [MANIFEST.grammars.package]);
});

test("publishes when the grammars are out and a binary is not", () => {
const table = allPublished();
delete table[MANIFEST.platforms[0].package];
const plan = planPublish({
manifest: MANIFEST,
publishedByPackage: table,
forced: false,
});
assert.equal(plan.shouldPublish, true);
assert.deepEqual(plan.missing, [MANIFEST.platforms[0].package]);
});
107 changes: 105 additions & 2 deletions .github/scripts/vale-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
"",
"`asset` is a template; {version} is replaced with valeVersion. The detect",
"phase of .github/workflows/release-vale.yml rewrites valeVersion and every",
"sha256 from upstream's checksums file, and leaves the templates alone."
"sha256 from upstream's checksums file, and leaves the templates alone.",
"",
"`grammars` is the platform-independent @taskless/vale-grammars package: one",
"tree-sitter module per upstream grammar-<name>.zip, unpacked from",
"`archiveMember`. Upstream checksums.txt does NOT cover these archives, so each",
"sha256 is the digest GitHub records for the release asset at upload time, read",
"from the releases API by the detect phase; it is reviewed in the same pull",
"request as the binary digests and verified the same way before unpacking."
],
"valeVersion": "3.27.0",
"upstream": {
Expand Down Expand Up @@ -77,5 +84,101 @@
"archiveMember": "vale.exe",
"sha256": "26e61cc58ac4180866d068dc2325d2625560c8cc518de7e7b5523211a5ab0cbc"
}
]
],
"grammars": {
"package": "@taskless/vale-grammars",
"directory": "packages/vale-grammars",
"asset": "grammar-{name}.zip",
"archiveMember": "grammar-{name}/styles/config/grammars/{name}.wasm",
"modules": [
{
"name": "bash",
"sha256": "383f41dac7ba7ff6b62310ae90fbecad5872b421e16362428e85f6d3383282a4"
},
{
"name": "c",
"sha256": "0e4d8e14893f8f20dccf7ee85c79c6beeeac4c77f032551a237067a93b450b0d"
},
{
"name": "cpp",
"sha256": "0f550858aa68c02663362631dc64d40e7b1a28aa48379fa5d55c0dfc3bf905f7"
},
{
"name": "csharp",
"sha256": "1c5ef2dc517dcd7fad2c7e6d1e2b5c8a60690b10d34a22cb3b108d98b3b73898"
},
{
"name": "css",
"sha256": "efc982ba928828df69d3a0a8d17ff4095b5890d9f918c41ce34adff940d31529"
},
{
"name": "elixir",
"sha256": "3beddaad99e1f3069948d5233709feb1ce8aaeab5b5a8333de3dc5e32659ecb0"
},
{
"name": "elm",
"sha256": "baedd9bdc51c76883a7d5f81e340e210f117e4355bc2fd479ae4b11ce8041ff1"
},
{
"name": "go",
"sha256": "c188c53747864bff9849cc39eaac51393c3264be8ae3c67c12edb2ccc94eb130"
},
{
"name": "java",
"sha256": "fc65e8426fe7116ef941b227520beb542cd2f6c8cf0789d28b63b370e8d36827"
},
{
"name": "javascript",
"sha256": "448d9a94d558b4e2e62c929b815378337ea5a151fc12e1f8277c853314c9e1d4"
},
{
"name": "julia",
"sha256": "edc4dbc9cfb3dc06f72c1820a7bd16d481a4c492efa35f9dd7a23a7c876d29f8"
},
{
"name": "kotlin",
"sha256": "58b5e2d01f1920cb2fb908863a477b6cd14cc0e3cf8a36fc4413191b709f4926"
},
{
"name": "lua",
"sha256": "10c94b27ea4d6cf4779be2bcf57accf256b1c752b57fcf27ff56be297ad9178f"
},
{
"name": "php",
"sha256": "326f84f19873498972a9b606b4af4c5e4cfa77a75a45bb1ac6c29801bf9c16f2"
},
{
"name": "proto",
"sha256": "4262870472d181b4bbc6afb3df39d81de13f84910d6f87a4032d66d346c17bef"
},
{
"name": "python",
"sha256": "cd369ca78cb327534bfab0eefb710b38115e0644cda04709da174f675c28a1b2"
},
{
"name": "ruby",
"sha256": "a31c8e1f88bab718794f281cbf6b7b4c5cfaf3526e379da1ba53ca7d3cfe6548"
},
{
"name": "rust",
"sha256": "040788500c7414b3e789f08f0281e4d12fdcf197720beb238e27139bde511631"
},
{
"name": "toml",
"sha256": "8a66d9450aba2f7d1423d16ed6bdc84a2d14dbb6eb26cd75a476128d5bdd2912"
},
{
"name": "tsx",
"sha256": "b051dedfe0ad634a6689c7d328f5df61b2a44fe120cf93146c2d4185fb43f5bc"
},
{
"name": "typescript",
"sha256": "d127e82362d35ec0d8945049b9f51735e0db10091b7d884f47ce2f6aebe7a162"
},
{
"name": "yaml",
"sha256": "8184a6cf2329f6cbc6748fbf8807ae5b58de7ab20f9a19f1301efd1c36a4b971"
}
]
}
}
Loading
Loading