Skip to content

Commit a2389e8

Browse files
authored
fix: scope SDK documentation publishing by released package (#804)
## Summary Replace whole-tree SDK documentation deletion/copy with imports scoped to the stable packages and majors that were actually published. **Prerequisite landed:** reflagcom/docs#32 merged the importer/checks without changing public pages. The broader v2 documentation cutover remains draft in reflagcom/docs#31. - Reconcile this PR with current main, preserving the existing Changesets `next` channel and package publication safeguards. - Select only documented packages present in Changesets' `publishedPackages` output. Exclude prereleases; require clean, matching source metadata and exact package tags. - Delegate public routing and generated-file ownership to the docs repository. No wholesale tree deletion or copying of unrelated workspace-HEAD docs. - **Hold automatic documentation sync until the public v1 archive and SDK migration landing pages are present.** The newly landed importer reports `ready=false` on docs main, so infrastructure can ship now without publishing v2 content. Direct release-import invocations also fail closed before that cutover. - Validate generated documentation before committing/pushing; do not swallow commit/push failures. - Add publication-boundary tests to Package CI and retain channel safeguards on every docs step. No SDK runtime source, package manifest/version, Changeset, npm tag, GitBook setting or application deployment changes are included. Existing package publication behavior is unchanged. ## Verification - [x] Immutable Yarn install - [x] Full workspace build (`yarn build --concurrency 2`), with a task-local checksum-verified JRE and existing OpenFeature providers built first - [x] Canonical documentation build - [x] Full workspace tests: **1,028 runtime tests + 48 Browser E2E cases** - [x] **17** release/manifest safeguards + **5** publisher boundary tests - [x] Importer infrastructure: **21** tests, all **77** existing navigation entries, and readiness `false` - [x] Existing draft cutover remains compatible: its original **19** tests and all **89** navigation entries / **33** generated pages pass with the extracted importer/checker; readiness `true` - [x] Scoped formatting and zero-warning lint; full lint has only the inherited generated Next.js declaration warning - [x] Normal commit hooks preserved the exact verified tree - [x] Read-only Changesets preflight reports no pending package releases - [x] Five real planner/importer dry runs cover the pre-cutover hold, scoped v2 writes, v1/current isolation, independent Management updates and prerelease exclusion - [x] All 11 public workspace versions already exist in npm; no package version or Changeset changed - [x] Final-head remote CI: both [push](https://github.com/reflagcom/javascript/actions/runs/45351743922) and [PR](https://github.com/reflagcom/javascript/actions/runs/45351759083) Build & Test runs pass; CodeQL, Oneleet and Reflag Review pass (no actionable findings) ## Rollout boundary Merge this after docs#32. This PR does not authorize a package release or the default-v2 docs cutover. Docs sync remains intentionally paused until docs#31 (or an equivalent reviewed content cutover) is published; stable package releases during that pause will not update public documentation automatically. Regenerate the final docs from the intended released sources as part of that later cutover. Co-authored-by: Ron Cohen <744+roncohen@users.noreply.github.com>
1 parent 5131bf6 commit a2389e8

6 files changed

Lines changed: 280 additions & 16 deletions

File tree

‎.github/workflows/package-ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
run: yarn build
4040
- name: Build docs
4141
run: yarn docs
42+
- name: Test documentation publication boundaries
43+
run: yarn test:docs-publishing
4244
- id: test
4345
name: Test the project
4446
run: yarn test:ci

‎.github/workflows/publish.yml‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,41 @@ jobs:
4343
commit: Version Packages
4444
env:
4545
GITHUB_TOKEN: ${{ secrets.CHANGESETS_BOT_TOKEN }}
46-
- name: Build docs
46+
- name: Select released SDK documentation
4747
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'
48-
run: yarn docs
48+
id: docs
49+
env:
50+
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
51+
run: node scripts/docs-release-plan.mjs "$RUNNER_TEMP/sdk-docs-plan.json"
4952
- name: Checkout docs with SSH
50-
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'
53+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs.outputs.has_docs == 'true'
5154
uses: actions/checkout@v4
5255
with:
5356
repository: reflagcom/docs
5457
ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }}
5558
path: reflag-docs
56-
- name: Copy generated docs to docs repo
57-
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'
58-
run: |
59-
rm -rf reflag-docs/sdk
60-
cp -R dist/docs reflag-docs/sdk
59+
- name: Hold docs sync until the public v1/v2 content cutover
60+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs.outputs.has_docs == 'true'
61+
id: docs-site
62+
run: node reflag-docs/.github/scripts/sdk-docs.mjs ready --destination reflag-docs | tee -a "$GITHUB_OUTPUT"
63+
- name: Build docs
64+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs-site.outputs.ready == 'true'
65+
run: yarn docs
66+
- name: Sync only released packages and majors
67+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs-site.outputs.ready == 'true'
68+
run: node reflag-docs/.github/scripts/sdk-docs.mjs release --source . --destination reflag-docs --plan "$RUNNER_TEMP/sdk-docs-plan.json"
69+
- name: Check generated documentation
70+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs-site.outputs.ready == 'true'
71+
working-directory: reflag-docs
72+
run: node .github/scripts/check-sdk-docs.mjs
6173
- name: Commit and push changes
62-
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'
74+
if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false' && steps.docs-site.outputs.ready == 'true'
75+
working-directory: reflag-docs
6376
run: |
64-
cd reflag-docs
6577
git config user.name "github-actions[bot]"
6678
git config user.email "github-actions[bot]@reflag.com"
67-
git add sdk
68-
git commit -m "Update documentation" && git push || echo "No docs changes to commit"
79+
git add supported-languages legacy api sdk .generated/sdk-docs
80+
if ! git diff --cached --quiet; then
81+
git commit -m "Update released SDK documentation"
82+
git push
83+
fi

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"release-packages": "yarn build && yarn release",
2727
"release": "yarn check:publish-manifests && changeset publish",
2828
"docs": "./docs.sh",
29+
"test:docs-publishing": "node --test scripts/docs-release-plan.test.mjs",
2930
"lint:fix": "yarn oxlint --fix .",
3031
"fmt": "yarn oxfmt --check .",
3132
"fmt:fix": "yarn oxfmt --write .",

‎scripts/docs-release-plan.mjs‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync } from "node:child_process";
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
import { pathToFileURL } from "node:url";
6+
7+
const documented = new Set([
8+
"browser-sdk",
9+
"react-sdk",
10+
"vue-sdk",
11+
"node-sdk",
12+
"react-native-sdk",
13+
"management-sdk",
14+
"cli",
15+
]);
16+
const versionPattern =
17+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[\da-zA-Z.-]+)?(?:\+[\da-zA-Z.-]+)?$/;
18+
const git = (source, ...args) =>
19+
execFileSync("git", ["-C", source, ...args], { encoding: "utf8" }).trim();
20+
21+
export function selectReleases(source, published) {
22+
assert(Array.isArray(published), "publishedPackages must be an array");
23+
const seen = new Set();
24+
const releases = [];
25+
for (const release of published) {
26+
assert(
27+
release && /^@reflag\/[a-z][a-z0-9-]*$/.test(release.name),
28+
"Invalid published package",
29+
);
30+
assert(
31+
typeof release.version === "string" &&
32+
versionPattern.test(release.version),
33+
"Invalid published version",
34+
);
35+
assert(!seen.has(release.name), "Duplicate published package");
36+
seen.add(release.name);
37+
const name = release.name.slice("@reflag/".length);
38+
if (!documented.has(name)) continue;
39+
const pkg = JSON.parse(
40+
fs.readFileSync(
41+
path.join(source, "packages", name, "package.json"),
42+
"utf8",
43+
),
44+
);
45+
assert.equal(pkg.name, release.name);
46+
assert.equal(
47+
pkg.version,
48+
release.version,
49+
"Published/source version mismatch",
50+
);
51+
assert(!pkg.private, "Private published package");
52+
// A prerelease must not change stable documentation or default navigation.
53+
if (!versionPattern.exec(release.version)[4])
54+
releases.push({ name: release.name, version: release.version });
55+
}
56+
return releases;
57+
}
58+
59+
export function releasePlan(source, published) {
60+
assert.equal(
61+
git(source, "status", "--porcelain", "--untracked-files=no"),
62+
"",
63+
"SDK source must be clean",
64+
);
65+
const sourceCommit = git(source, "rev-parse", "HEAD");
66+
const releases = selectReleases(source, published);
67+
for (const release of releases)
68+
assert.equal(
69+
git(
70+
source,
71+
"rev-parse",
72+
`refs/tags/${release.name}@${release.version}^{commit}`,
73+
),
74+
sourceCommit,
75+
"Release tag/source mismatch",
76+
);
77+
return { sourceCommit, releases };
78+
}
79+
80+
if (
81+
process.argv[1] &&
82+
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
83+
) {
84+
const destination = process.argv[2];
85+
assert(destination, "Pass the release-plan output filename");
86+
const plan = releasePlan(
87+
process.cwd(),
88+
JSON.parse(process.env.PUBLISHED_PACKAGES),
89+
);
90+
fs.writeFileSync(destination, `${JSON.stringify(plan, null, 2)}\n`);
91+
if (process.env.GITHUB_OUTPUT)
92+
fs.appendFileSync(
93+
process.env.GITHUB_OUTPUT,
94+
`has_docs=${plan.releases.length > 0}\n`,
95+
);
96+
console.log(
97+
`Selected ${plan.releases.length} stable package releases for documentation.`,
98+
);
99+
}

‎scripts/docs-release-plan.test.mjs‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync } from "node:child_process";
3+
import fs from "node:fs";
4+
import os from "node:os";
5+
import path from "node:path";
6+
import test from "node:test";
7+
8+
import { releasePlan, selectReleases } from "./docs-release-plan.mjs";
9+
10+
function fixture(t) {
11+
const root = fs.mkdtempSync(
12+
path.join(os.tmpdir(), "reflag-docs-release-test-"),
13+
);
14+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
15+
for (const [name, version] of [
16+
["node-sdk", "2.0.0"],
17+
["react-sdk", "2.0.0-next.0"],
18+
["management-sdk", "1.9.0"],
19+
["cli", "1.0.4"],
20+
]) {
21+
const dir = path.join(root, "packages", name);
22+
fs.mkdirSync(dir, { recursive: true });
23+
fs.writeFileSync(
24+
path.join(dir, "package.json"),
25+
JSON.stringify({ name: `@reflag/${name}`, version }),
26+
);
27+
}
28+
return root;
29+
}
30+
31+
test("only stable, actually published SDK/tooling packages enter the plan", (t) => {
32+
const root = fixture(t);
33+
assert.deepEqual(
34+
selectReleases(root, [
35+
{ name: "@reflag/node-sdk", version: "2.0.0" },
36+
{ name: "@reflag/react-sdk", version: "2.0.0-next.0" },
37+
{ name: "@reflag/flag-evaluation", version: "2.0.0" },
38+
]),
39+
[{ name: "@reflag/node-sdk", version: "2.0.0" }],
40+
);
41+
});
42+
43+
test("an independent or CLI-v1 release cannot select unreleased web SDKs", (t) => {
44+
const root = fixture(t);
45+
for (const release of [
46+
{ name: "@reflag/management-sdk", version: "1.9.0" },
47+
{ name: "@reflag/cli", version: "1.0.4" },
48+
])
49+
assert.deepEqual(selectReleases(root, [release]), [release]);
50+
assert.deepEqual(selectReleases(root, []), []);
51+
});
52+
53+
test("source mismatches, malformed inputs and duplicates fail closed", (t) => {
54+
const root = fixture(t);
55+
assert.throws(() => selectReleases(root, {}), /array/);
56+
assert.throws(
57+
() => selectReleases(root, [{ name: "../../escape", version: "2.0.0" }]),
58+
/Invalid published package/,
59+
);
60+
assert.throws(
61+
() => selectReleases(root, [{ name: "@reflag/node-sdk", version: "main" }]),
62+
/Invalid published version/,
63+
);
64+
assert.throws(
65+
() =>
66+
selectReleases(root, [{ name: "@reflag/node-sdk", version: "2.0.1" }]),
67+
/version mismatch/,
68+
);
69+
const item = { name: "@reflag/node-sdk", version: "2.0.0" };
70+
assert.throws(() => selectReleases(root, [item, item]), /Duplicate/);
71+
});
72+
73+
test("release planning requires clean source and an exact package tag", (t) => {
74+
const root = fixture(t);
75+
const git = (...args) =>
76+
execFileSync("git", ["-C", root, ...args], {
77+
encoding: "utf8",
78+
stdio: ["ignore", "pipe", "pipe"],
79+
}).trim();
80+
const commit = (message) => {
81+
git("add", ".");
82+
git(
83+
"-c",
84+
"user.name=Test",
85+
"-c",
86+
"user.email=test@example.invalid",
87+
"commit",
88+
"--quiet",
89+
"-m",
90+
message,
91+
);
92+
};
93+
git("init", "--quiet");
94+
commit("Source");
95+
const published = [{ name: "@reflag/node-sdk", version: "2.0.0" }];
96+
assert.throws(() => releasePlan(root, published), /Command failed/);
97+
git("tag", "@reflag/node-sdk@2.0.0");
98+
assert.deepEqual(releasePlan(root, published), {
99+
sourceCommit: git("rev-parse", "HEAD"),
100+
releases: published,
101+
});
102+
fs.appendFileSync(path.join(root, "packages/node-sdk/package.json"), "\n");
103+
assert.throws(() => releasePlan(root, published), /must be clean/);
104+
commit("Later source");
105+
assert.throws(
106+
() => releasePlan(root, published),
107+
/Release tag\/source mismatch/,
108+
);
109+
});
110+
111+
test("workflow scopes documentation by release and delegates version routing to the docs importer", () => {
112+
const release = fs.readFileSync(
113+
new URL("../.github/workflows/publish.yml", import.meta.url),
114+
"utf8",
115+
);
116+
assert.doesNotMatch(release, /rm -rf|cp -R dist\/docs|echo "No docs changes/);
117+
assert.match(release, /steps\.changesets\.outputs\.publishedPackages/);
118+
assert.match(release, /steps\.docs\.outputs\.has_docs == 'true'/);
119+
assert.match(release, /sdk-docs\.mjs ready --destination reflag-docs/);
120+
assert.match(release, /steps\.docs-site\.outputs\.ready == 'true'/);
121+
const steps = release.split(/\n - name: /);
122+
for (const name of [
123+
"Build docs",
124+
"Sync only released packages and majors",
125+
"Check generated documentation",
126+
"Commit and push changes",
127+
]) {
128+
const step = steps.find((item) => item.startsWith(`${name}\n`));
129+
assert(step, `Missing documentation step: ${name}`);
130+
assert.match(step, /steps\.docs-site\.outputs\.ready == 'true'/);
131+
}
132+
assert(
133+
release.indexOf("sdk-docs.mjs ready") < release.indexOf("run: yarn docs"),
134+
);
135+
assert.match(
136+
release,
137+
/sdk-docs\.mjs release --source \. --destination reflag-docs --plan/,
138+
);
139+
assert.match(release, /node \.github\/scripts\/check-sdk-docs\.mjs/);
140+
const ci = fs.readFileSync(
141+
new URL("../.github/workflows/package-ci.yml", import.meta.url),
142+
"utf8",
143+
);
144+
assert.match(ci, /yarn test:docs-publishing/);
145+
});

‎scripts/release-channel.test.mjs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ test("all stable-doc publication steps require a stable release channel", () =>
6363
.split("\n")
6464
.map((line) => line.trim())
6565
.filter((line) => line.startsWith("if: "));
66-
assert.equal(conditions.length, 4);
66+
assert.equal(conditions.length, 7);
6767
for (const condition of conditions) {
68-
assert.equal(
69-
condition,
70-
"if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'",
68+
assert.ok(
69+
condition.startsWith(
70+
"if: steps.changesets.outputs.published == 'true' && steps.release-channel.outputs.prerelease == 'false'",
71+
),
72+
`Missing stable release guard: ${condition}`,
7173
);
7274
}
7375
assert.match(workflow, /version: yarn version-packages/);

0 commit comments

Comments
 (0)