Skip to content

Commit f698879

Browse files
committed
Declare plugin archive release coverage
1 parent 5d6cc3a commit f698879

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

homeboy.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
"nodejs": {}
77
},
88
"build_artifact": "packages/wordpress-plugin/dist/wp-codebox.zip",
9+
"release": {
10+
"package_coverage": [
11+
{
12+
"artifact": "packages/wordpress-plugin/dist/wp-codebox.zip",
13+
"artifact_match": "exact",
14+
"source_roots": [
15+
"packages/wordpress-plugin"
16+
],
17+
"archive_root": "wp-codebox"
18+
}
19+
]
20+
},
921
"version_targets": [
1022
{
1123
"file": "package.json",
@@ -45,6 +57,7 @@
4557
],
4658
"test": [
4759
"npm run smoke -- --group package",
60+
"npm run test:release-package-coverage",
4861
"npm run release:package"
4962
]
5063
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"prepare": "npm run build",
8080
"package:wordpress-plugin": "tsx scripts/build-wordpress-plugin-zip.ts",
8181
"release:package": "tsx scripts/package-release-artifact.ts",
82+
"test:release-package-coverage": "tsx tests/release-package-coverage.test.ts",
8283
"wp-codebox": "node packages/cli/dist/index.js",
8384
"wp-codebox:source": "node bin/wp-codebox-source.mjs",
8485
"generate:browser-fanout-aggregation-runtime": "tsx scripts/generate-browser-fanout-aggregation-runtime.ts",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import assert from "node:assert/strict"
2+
import { execFile } from "node:child_process"
3+
import { readFile } from "node:fs/promises"
4+
import { resolve } from "node:path"
5+
import { promisify } from "node:util"
6+
7+
const execFileAsync = promisify(execFile)
8+
const repositoryRoot = resolve(import.meta.dirname, "..")
9+
const pluginRoot = "packages/wordpress-plugin"
10+
const pluginArtifact = "packages/wordpress-plugin/dist/wp-codebox.zip"
11+
12+
const homeboy = JSON.parse(await readFile(resolve(repositoryRoot, "homeboy.json"), "utf8"))
13+
assert.deepEqual(homeboy.release?.package_coverage, [{
14+
artifact: pluginArtifact,
15+
artifact_match: "exact",
16+
source_roots: [pluginRoot],
17+
archive_root: "wp-codebox",
18+
}])
19+
20+
const { stdout } = await execFileAsync("npm", ["run", "release:package"], {
21+
cwd: repositoryRoot,
22+
maxBuffer: 1024 * 1024 * 20,
23+
})
24+
const artifacts = JSON.parse(stdout.trim().split("\n").at(-1) ?? "[]")
25+
assert.equal(artifacts.length, 2, "release package emitted unexpected artifacts")
26+
assert.deepEqual(artifacts.filter((artifact: { type: string }) => artifact.type === "wordpress-plugin-zip"), [
27+
{ path: pluginArtifact, type: "wordpress-plugin-zip" },
28+
])
29+
const cliArtifacts = artifacts.filter((artifact: { type: string }) => artifact.type === "node-cli-tarball")
30+
assert.equal(cliArtifacts.length, 1, "release package must emit exactly one CLI tarball")
31+
const cliArtifact = cliArtifacts[0] as { path: string, platform: string }
32+
assert.match(cliArtifact.path, /^dist\/wp-codebox-cli-[^/]+\.tar\.gz$/)
33+
assert.match(cliArtifact.platform, /^[a-z0-9]+-[a-z0-9]+$/)
34+
assert.equal(cliArtifact.path, `dist/wp-codebox-cli-${cliArtifact.platform}.tar.gz`)
35+
36+
const { stdout: tracked } = await execFileAsync("git", ["ls-files", "-z", "--", `${pluginRoot}/**`], { cwd: repositoryRoot })
37+
const mappedFiles = tracked
38+
.split("\0")
39+
.filter(Boolean)
40+
.filter((path) => /\.(php|inc|phtml|js|mjs|cjs|css|json)$/.test(path))
41+
.filter((path) => !path.endsWith("/package.json"))
42+
.map((path) => `wp-codebox/${path.slice(pluginRoot.length + 1)}`)
43+
assert.ok(mappedFiles.length > 0, "plugin source root has no mapped tracked runtime files")
44+
45+
const { stdout: zipEntries } = await execFileAsync("unzip", ["-Z1", pluginArtifact], {
46+
cwd: repositoryRoot,
47+
maxBuffer: 1024 * 1024 * 20,
48+
})
49+
const archiveEntries = new Set(zipEntries.trim().split("\n"))
50+
for (const path of mappedFiles) {
51+
assert.ok(archiveEntries.has(path), `${pluginArtifact} is missing mapped tracked file ${path}`)
52+
}
53+
54+
assert.equal(archiveEntries.has("wp-codebox/package.json"), false, "package metadata is intentionally excluded from the plugin archive")
55+
56+
const { stdout: tarEntries } = await execFileAsync("tar", ["-tzf", cliArtifact.path], {
57+
cwd: repositoryRoot,
58+
maxBuffer: 1024 * 1024 * 20,
59+
})
60+
assert.ok(tarEntries.split("\n").some((path) => path === "wp-codebox-cli/"), "CLI tarball root changed")
61+
62+
console.log("release package coverage passed")

0 commit comments

Comments
 (0)