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
2 changes: 1 addition & 1 deletion .github/workflows/publish-js-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ jobs:
id: detect
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node scripts/release/should-publish-stable.mjs --output .release-manifest.json
run: node scripts/release/should-publish-stable.mjs --allow-non-release-head --output .release-manifest.json
- name: Configure git user
run: |
git config user.name "github-actions[bot]"
Expand Down
17 changes: 16 additions & 1 deletion scripts/release/push-release-tags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { appendSummary, parseArgs } from "./_shared.mjs";
const args = parseArgs();
const manifestPath = args.manifest ?? ".release-manifest.json";
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
const targetCommit = manifest.commit;

if ((manifest.packages ?? []).length === 0) {
console.log("No release tags to push.");
process.exit(0);
}

if (!targetCommit) {
throw new Error("Release manifest is missing commit.");
}

const tags = manifest.packages.map(
(pkg) => pkg.tag ?? `${pkg.name}@${pkg.version}`,
);
Expand All @@ -28,13 +33,17 @@ for (const tag of tags) {

if (!localTagExists(tag)) {
toCreate.push(tag);
} else if (getLocalTagTarget(tag) !== targetCommit) {
throw new Error(
`Local tag ${tag} already exists on ${getLocalTagTarget(tag)}, expected ${targetCommit}.`,
);
}

toPush.push(tag);
}

for (const tag of toCreate) {
execFileSync("git", ["tag", tag], { stdio: "inherit" });
execFileSync("git", ["tag", tag, targetCommit], { stdio: "inherit" });
}

if (toPush.length > 0) {
Expand Down Expand Up @@ -65,6 +74,12 @@ function localTagExists(tag) {
);
}

function getLocalTagTarget(tag) {
return execFileSync("git", ["rev-list", "-n", "1", tag], {
encoding: "utf8",
}).trim();
}

function fetchRemoteTags(tagsToCheck) {
const result = spawnSync(
"git",
Expand Down
31 changes: 21 additions & 10 deletions scripts/release/should-publish-stable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

const args = parseArgs();
const outputPath = args.output ?? ".release-manifest.json";
const allowNonReleaseHead = args["allow-non-release-head"] === true;
const packages = PUBLISHABLE_PACKAGES.map((approved) => {
const manifest = readPackage(approved.dir);
const publishedToNpm = isPublishedToNpm(manifest.name, manifest.version);
Expand All @@ -31,19 +32,17 @@ const packages = PUBLISHABLE_PACKAGES.map((approved) => {
});

const actionablePackages = packages.filter((pkg) => pkg.needsPublish);
const commit = execFileSync("git", ["rev-parse", "HEAD"], {
const headCommit = execFileSync("git", ["rev-parse", "HEAD"], {
encoding: "utf8",
}).trim();
const commitMessage = execFileSync("git", ["log", "-1", "--pretty=%B"], {
encoding: "utf8",
}).trim();
const isReleaseCommit = /\[ci\] release/i.test(commitMessage);
const hasWork = actionablePackages.length > 0 && isReleaseCommit;
const headIsReleaseCommit = isReleaseCommit(headCommit);
const hasWork =
actionablePackages.length > 0 && (headIsReleaseCommit || allowNonReleaseHead);
const releasePackages = hasWork ? actionablePackages : [];

const manifest = {
mode: "stable",
commit,
commit: headCommit,
packages: releasePackages,
};

Expand All @@ -63,9 +62,10 @@ writeGithubOutput("package_count", releasePackages.length);
writeGithubOutput("manifest_path", outputPath);

if (!hasWork) {
const message = actionablePackages.length
? "Unpublished package versions exist, but HEAD is not a merged Changesets release commit, so stable publish is skipped."
: "No stable publish work is required on this main commit.";
const message =
actionablePackages.length === 0
? "No stable publish work is required on this main commit."
: "Unpublished package versions exist, but HEAD is not a merged Changesets release commit, so stable publish is skipped.";
console.log(message);
appendSummary(`## Stable publish\n\n${message}`);
process.exit(0);
Expand Down Expand Up @@ -96,3 +96,14 @@ function isPublishedToNpm(name, version) {

return result.stdout.trim() === version;
}

function isReleaseCommit(commit) {
const commitMessage = execFileSync(
"git",
["log", "-1", "--pretty=%B", commit],
{
encoding: "utf8",
},
).trim();
return /\[ci\] release/i.test(commitMessage);
}
Loading