|
| 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