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
13 changes: 2 additions & 11 deletions .github/workflows/publish-stable-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ jobs:
with:
fetch-depth: 0
ref: ${{ needs.validate-release-sha.outputs.release_sha }}
- name: Resolve release commits
id: release
- name: Validate release checkout
env:
RELEASE_SHA: ${{ needs.validate-release-sha.outputs.release_sha }}
run: |
Expand All @@ -98,14 +97,6 @@ jobs:
echo "Checked out $checked_out_sha, expected $RELEASE_SHA." >&2
exit 1
fi

first_parent="$(git rev-parse --verify HEAD^1 2>/dev/null || true)"
if [ -z "$first_parent" ]; then
echo "release_sha must identify a commit with at least one parent." >&2
exit 1
fi

echo "since_sha=$first_parent" >> "$GITHUB_OUTPUT"
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
Expand All @@ -118,7 +109,7 @@ jobs:
run: node scripts/release/validate-publishable-packages.mjs
- name: Detect stable publish work
id: detect
run: node scripts/release/release-manifest.mjs --mode stable --since "${{ steps.release.outputs.since_sha }}" --output .release-manifest.json
run: node scripts/release/release-manifest.mjs --mode stable --output .release-manifest.json
- name: Build packages
if: steps.detect.outputs.needs_publish == 'true'
run: pnpm run build
Expand Down
51 changes: 5 additions & 46 deletions scripts/release/release-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const args = parseArgs();
const mode = args.mode ?? "release";
const outputPath = args.output ?? ".release-manifest.json";
const statusPath = args["status-file"];
const sinceRef = args.since;

const headCommit = execFileSync("git", ["rev-parse", "HEAD"], {
encoding: "utf8",
Expand All @@ -37,7 +36,6 @@ if (statusPath) {
headCommit,
mode,
outputPath,
sinceRef,
title,
});
}
Expand Down Expand Up @@ -99,66 +97,37 @@ function handleStableManifest({
headCommit,
mode: currentMode,
outputPath: currentOutputPath,
sinceRef: currentSinceRef,
title: currentTitle,
}) {
const packages = (
currentSinceRef
? getVersionedPackagesSince(currentSinceRef)
: getUnpublishedPackages()
).map((pkg) => ({
...pkg,
published: isPublishedToNpm(pkg.name, pkg.version),
}));
const packages = getUnpublishedPackages();
const hasWork = packages.length > 0;
const packagesNeedingPublish = packages.filter((pkg) => !pkg.published);

writeManifestFile(currentOutputPath, {
mode: currentMode,
commit: headCommit,
since: currentSinceRef,
packages,
});

const markdownList = packagesToMarkdown(packages);
const plainList = packagesToPlain(packages);

writeGithubOutput("has_work", hasWork);
writeGithubOutput("needs_publish", packagesNeedingPublish.length > 0);
writeGithubOutput("needs_publish", hasWork);
writeGithubOutput("package_count", packages.length);
writeGithubOutput("title", currentTitle);
writeGithubOutput("markdown", markdownList);
writeGithubOutput("plain", plainList);

if (!hasWork) {
const message = "No stable publish work is required for this ref.";
console.log(message);
console.log("No unpublished package versions were found at this ref.");
process.exit(0);
}

console.log(
`Stable release work detected for ${packages.length} package(s); ${packagesNeedingPublish.length} need npm publish:\n${formatPackageList(packages)}`,
`Stable release work detected for ${packages.length} unpublished package version(s):\n${formatPackageList(packages)}`,
);
}

function getVersionedPackagesSince(sinceRef) {
return PUBLISHABLE_PACKAGES.map((approved) => {
const manifest = readPackage(approved.dir);
const previousVersion = readPackageVersionAtRef(sinceRef, approved.dir);
if (previousVersion === manifest.version) {
return null;
}

return {
dir: approved.dir,
name: manifest.name,
previousVersion,
version: manifest.version,
tag: getReleaseTag(manifest.name, manifest.version),
};
}).filter(Boolean);
}

function getUnpublishedPackages() {
return PUBLISHABLE_PACKAGES.map((approved) => {
const manifest = readPackage(approved.dir);
Expand All @@ -171,21 +140,11 @@ function getUnpublishedPackages() {
name: manifest.name,
version: manifest.version,
tag: getReleaseTag(manifest.name, manifest.version),
published: false,
};
}).filter(Boolean);
}

function readPackageVersionAtRef(ref, relativeDir) {
const content = execFileSync(
"git",
["show", `${ref}:${relativeDir}/package.json`],
{
encoding: "utf8",
},
);
return JSON.parse(content).version;
}

function writeManifestFile(currentOutputPath, manifest) {
writeFileSync(
currentOutputPath,
Expand Down
Loading