Skip to content

Commit cc2aa34

Browse files
committed
fix: only skip publish when both NPM version and changelog entry exist
Previously a package was skipped entirely if the version already existed on NPM, causing git tags and GitHub releases to be missed on partial failures. Now the skip only triggers when both conditions are true; if either is absent the remaining steps (publish, tag, release) still run as needed.
1 parent 3cea59f commit cc2aa34

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

src/workflows/publish.ts

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,36 +170,51 @@ export async function publishWorkflow(options: NormalizedReleaseScriptsOptions):
170170
);
171171
}
172172

173-
if (existsResult.value) {
174-
logger.info(`Version ${farver.cyan(version)} already exists on NPM, skipping`);
173+
const npmExists = existsResult.value;
174+
175+
// Check if a changelog entry exists for this version
176+
let changelogEntryExists = false;
177+
const changelogPath = join(pkg.path, "CHANGELOG.md");
178+
try {
179+
const changelogContent = await readFile(changelogPath, "utf-8");
180+
const parsed = parseChangelog(changelogContent);
181+
changelogEntryExists = parsed.versions.some((v) => v.version === version);
182+
} catch {
183+
// If changelog can't be read, treat entry as missing
184+
}
185+
186+
if (npmExists && changelogEntryExists) {
187+
logger.info(`Version ${farver.cyan(version)} already exists on NPM and in changelog, skipping`);
175188
status.skipped.push(packageName);
176189
continue;
177190
}
178191

179-
// Publish to NPM
180-
logger.step(`Publishing ${farver.cyan(`${packageName}@${version}`)} to NPM...`);
181-
const publishResult = await publishPackage(packageName, version, options.workspaceRoot, options);
182-
183-
if (!publishResult.ok) {
184-
logger.error(`Failed to publish: ${publishResult.error.message}`);
185-
status.failed.push(packageName);
186-
187-
// Provide helpful error messages for common issues
188-
let hint: string | undefined;
189-
if (publishResult.error.code === "E403") {
190-
hint = "Authentication failed. Ensure your NPM token or OIDC configuration is correct";
191-
} else if (publishResult.error.code === "EPUBLISHCONFLICT") {
192-
hint = "Version conflict. The version may have been published recently";
193-
} else if (publishResult.error.code === "EOTP") {
194-
hint = "2FA/OTP required. Provide the otp option or use OIDC authentication";
192+
if (!npmExists) {
193+
// Publish to NPM
194+
logger.step(`Publishing ${farver.cyan(`${packageName}@${version}`)} to NPM...`);
195+
const publishResult = await publishPackage(packageName, version, options.workspaceRoot, options);
196+
197+
if (!publishResult.ok) {
198+
logger.error(`Failed to publish: ${publishResult.error.message}`);
199+
status.failed.push(packageName);
200+
201+
// Provide helpful error messages for common issues
202+
let hint: string | undefined;
203+
if (publishResult.error.code === "E403") {
204+
hint = "Authentication failed. Ensure your NPM token or OIDC configuration is correct";
205+
} else if (publishResult.error.code === "EPUBLISHCONFLICT") {
206+
hint = "Version conflict. The version may have been published recently";
207+
} else if (publishResult.error.code === "EOTP") {
208+
hint = "2FA/OTP required. Provide the otp option or use OIDC authentication";
209+
}
210+
211+
exitWithError(`Publishing failed for ${packageName}`, hint, publishResult.error);
195212
}
196213

197-
exitWithError(`Publishing failed for ${packageName}`, hint, publishResult.error);
214+
logger.success(`Published ${farver.cyan(`${packageName}@${version}`)}`);
215+
status.published.push(packageName);
198216
}
199217

200-
logger.success(`Published ${farver.cyan(`${packageName}@${version}`)}`);
201-
status.published.push(packageName);
202-
203218
// Create and push git tag
204219
logger.step(`Creating git tag ${farver.cyan(`${packageName}@${version}`)}...`);
205220
const tagResult = await createAndPushPackageTag(packageName, version, options.workspaceRoot);

0 commit comments

Comments
 (0)