Skip to content

Commit 2bdc12e

Browse files
authored
fix: signed-commits github releases (#1455)
* fix: github releases * fix: one more debug log * fix: one more log
1 parent df37dd4 commit 2bdc12e

4 files changed

Lines changed: 83 additions & 41 deletions

File tree

.changeset/hungry-eagles-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changesets-signed-commits": minor
3+
---
4+
5+
fix: stop trying to create gh releases for already pre-existing releases

actions/signed-commits/dist/index.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60510,11 +60510,13 @@ async function pushTags(tagSeparator, createMajorVersionTags, cwd, rootPackageIn
6051060510
const rewrittenTags = replaceTagSeparator(newTags, tagSeparator);
6051160511
const finalTags = rootPackageInfo ? rewriteRootPackageTags(rewrittenTags, tagSeparator, rootPackageInfo) : rewrittenTags;
6051260512
core2.debug(
60513-
`Final tags to push: ${finalTags.map((tag) => tag.name).join(", ")}`
60513+
`Candidate tags to push: ${JSON.stringify(finalTags.map((tag) => tag.name))}`
6051460514
);
6051560515
const filteredRewrittenTags = computeTagDiff(finalTags, remoteTagNames);
6051660516
core2.debug(
60517-
`Filtered rewritten tags to push: ${filteredRewrittenTags.map((tag) => tag.name).join(", ")}`
60517+
`Filtered rewritten tags to push: ${JSON.stringify(
60518+
filteredRewrittenTags.map((tag) => tag.name)
60519+
)}`
6051860520
);
6051960521
const createdTags = await createLightweightTags(filteredRewrittenTags, cwd);
6052060522
await execWithOutput("git", ["push", "origin", "--tags"], { cwd });
@@ -61270,7 +61272,7 @@ var setupOctokit = (githubToken) => {
6127061272
var createRelease = async (octokit, { pkg, tagName }) => {
6127161273
try {
6127261274
core4.debug(
61273-
`Creating release for ${pkg.packageJson.name}@${pkg.packageJson.version}`
61275+
`Creating release for ${pkg.packageJson.name}@${pkg.packageJson.version} (tag: ${tagName})`
6127461276
);
6127561277
let changelogFileName = import_path5.default.join(pkg.dir, "CHANGELOG.md");
6127661278
let changelog = await import_fs_extra2.default.readFile(changelogFileName, "utf8");
@@ -61280,14 +61282,22 @@ var createRelease = async (octokit, { pkg, tagName }) => {
6128061282
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`
6128161283
);
6128261284
}
61283-
await octokit.rest.repos.createRelease({
61285+
core4.debug(
61286+
`Creating release with tag ${tagName} and changelog entry:
61287+
${changelogEntry.content}`
61288+
);
61289+
return await octokit.rest.repos.createRelease({
6128461290
name: tagName,
6128561291
tag_name: tagName,
6128661292
body: changelogEntry.content,
6128761293
prerelease: pkg.packageJson.version.includes("-"),
61288-
...github.context.repo
61294+
owner: github.context.repo.owner,
61295+
repo: github.context.repo.repo
6128961296
});
6129061297
} catch (err) {
61298+
core4.warning(
61299+
`Failed to create release for ${pkg.packageJson.name}@${pkg.packageJson.version} with tag ${tagName}: ${err instanceof Error ? err.message : String(err)}`
61300+
);
6129161301
if (err && typeof err === "object" && "code" in err && err.code !== "ENOENT") {
6129261302
throw err;
6129361303
}
@@ -61332,36 +61342,39 @@ async function runPublish({
6133261342
publishArgs,
6133361343
{ cwd }
6133461344
);
61335-
await pushTags(
61345+
const tags = await pushTags(
6133661346
tagSeparator,
6133761347
createMajorVersionTags,
6133861348
cwd,
6133961349
rootPackageInfo
6134061350
);
61351+
core4.debug(`Tags pushed: ${JSON.stringify(tags.map((tag) => tag.name))}`);
61352+
const nonMajorTags = tags.filter((tag) => !tag.majorVersion);
6134161353
let { packages, tool } = await (0, import_get_packages4.getPackages)(cwd);
6134261354
let releasedPackages = [];
6134361355
if (tool.type !== "root") {
61344-
let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/;
6134561356
let packagesByName = new Map(packages.map((x) => [x.packageJson.name, x]));
61346-
for (let line of changesetPublishOutput.stdout.split("\n")) {
61347-
let match = line.match(newTagRegex);
61348-
if (match === null) {
61349-
continue;
61350-
}
61351-
let pkgName = match[1];
61352-
let pkg = packagesByName.get(pkgName);
61357+
for (let tag of nonMajorTags) {
61358+
const [pkgName, _version] = tag.name.split(tagSeparator);
61359+
const pkg = packagesByName.get(pkgName);
6135361360
if (pkg === void 0) {
6135461361
throw new Error(
6135561362
`Package "${pkgName}" not found.This is probably a bug in the action, please open an issue`
6135661363
);
6135761364
}
61358-
releasedPackages.push(pkg);
61365+
core4.debug(
61366+
`Tag ${tag.name} corresponds to package ${pkg.packageJson.name} (${pkg.dir})`
61367+
);
61368+
releasedPackages.push([pkg, tag]);
6135961369
}
61370+
core4.info(
61371+
`Released packages found: ${JSON.stringify(releasedPackages.map(([p]) => p.packageJson.name))}`
61372+
);
6136061373
if (createGithubReleases) {
6136161374
await Promise.all(
61362-
releasedPackages.map((pkg) => {
61375+
releasedPackages.map(([pkg, tag]) => {
6136361376
const isRootPackage = rootPackageInfo && pkg.packageJson.name === rootPackageInfo.name;
61364-
const tagName = isRootPackage ? `v${pkg.packageJson.version}` : `${pkg.packageJson.name}${tagSeparator}${pkg.packageJson.version}`;
61377+
const tagName = isRootPackage ? `v${pkg.packageJson.version}` : tag.name;
6136561378
return createRelease(octokit, {
6136661379
pkg,
6136761380
tagName
@@ -61380,7 +61393,10 @@ async function runPublish({
6138061393
for (let line of changesetPublishOutput.stdout.split("\n")) {
6138161394
let match = line.match(newTagRegex);
6138261395
if (match) {
61383-
releasedPackages.push(pkg);
61396+
releasedPackages.push([
61397+
pkg,
61398+
{ name: `v${pkg.packageJson.version}`, ref: "" }
61399+
]);
6138461400
if (createGithubReleases) {
6138561401
await createRelease(octokit, {
6138661402
pkg,
@@ -61394,7 +61410,7 @@ async function runPublish({
6139461410
if (releasedPackages.length) {
6139561411
return {
6139661412
published: true,
61397-
publishedPackages: releasedPackages.map((pkg) => ({
61413+
publishedPackages: releasedPackages.map(([pkg, _tag]) => ({
6139861414
name: pkg.packageJson.name,
6139961415
version: pkg.packageJson.version
6140061416
}))

actions/signed-commits/src/git/github-git/repo-tags.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ export async function pushTags(
3434
? rewriteRootPackageTags(rewrittenTags, tagSeparator, rootPackageInfo)
3535
: rewrittenTags;
3636
core.debug(
37-
`Final tags to push: ${finalTags.map((tag) => tag.name).join(", ")}`,
37+
`Candidate tags to push: ${JSON.stringify(finalTags.map((tag) => tag.name))}`,
3838
);
3939

4040
// Filter out rewritten tags that are already present on the remote.
4141
const filteredRewrittenTags = computeTagDiff(finalTags, remoteTagNames);
4242
core.debug(
43-
`Filtered rewritten tags to push: ${filteredRewrittenTags
44-
.map((tag) => tag.name)
45-
.join(", ")}`,
43+
`Filtered rewritten tags to push: ${JSON.stringify(
44+
filteredRewrittenTags.map((tag) => tag.name),
45+
)}`,
4646
);
4747
const createdTags = await createLightweightTags(filteredRewrittenTags, cwd);
4848
await execWithOutput("git", ["push", "origin", "--tags"], { cwd });

actions/signed-commits/src/run.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as githubGitUtils from "./git/github-git";
1818
import readChangesetState from "./read-changeset-state";
1919
import resolveFrom from "resolve-from";
2020
import { throttling } from "@octokit/plugin-throttling";
21+
import { GitTag } from "./git/github-git/repo-tags";
2122

2223
// GitHub Issues/PRs messages have a max size limit on the
2324
// message body payload.
@@ -70,7 +71,7 @@ const createRelease = async (
7071
) => {
7172
try {
7273
core.debug(
73-
`Creating release for ${pkg.packageJson.name}@${pkg.packageJson.version}`,
74+
`Creating release for ${pkg.packageJson.name}@${pkg.packageJson.version} (tag: ${tagName})`,
7475
);
7576
let changelogFileName = path.join(pkg.dir, "CHANGELOG.md");
7677

@@ -85,14 +86,24 @@ const createRelease = async (
8586
);
8687
}
8788

88-
await octokit.rest.repos.createRelease({
89+
core.debug(
90+
`Creating release with tag ${tagName} and changelog entry:\n${changelogEntry.content}`,
91+
);
92+
93+
return await octokit.rest.repos.createRelease({
8994
name: tagName,
9095
tag_name: tagName,
9196
body: changelogEntry.content,
9297
prerelease: pkg.packageJson.version.includes("-"),
93-
...github.context.repo,
98+
owner: github.context.repo.owner,
99+
repo: github.context.repo.repo,
94100
});
95101
} catch (err) {
102+
core.warning(
103+
`Failed to create release for ${pkg.packageJson.name}@${pkg.packageJson.version} with tag ${tagName}: ${
104+
err instanceof Error ? err.message : String(err)
105+
}`,
106+
);
96107
// if we can't find a changelog, the user has probably disabled changelogs
97108
if (
98109
err &&
@@ -176,48 +187,55 @@ export async function runPublish({
176187
{ cwd },
177188
);
178189

179-
await githubGitUtils.pushTags(
190+
const tags = await githubGitUtils.pushTags(
180191
tagSeparator,
181192
createMajorVersionTags,
182193
cwd,
183194
rootPackageInfo,
184195
);
185196

197+
core.debug(`Tags pushed: ${JSON.stringify(tags.map((tag) => tag.name))}`);
198+
199+
const nonMajorTags = tags.filter((tag) => !tag.majorVersion);
200+
186201
let { packages, tool } = await getPackages(cwd);
187-
let releasedPackages: Package[] = [];
202+
let releasedPackages: [Package, GitTag][] = [];
188203

189204
// if we are in a monorepo, then publish multiple packages
190205
// a "root" tool is a single package repo
191206
// https://github.com/Thinkmill/manypkg/blob/main/packages/tools/src/RootTool.ts#L17C4-L17C64
192207
if (tool.type !== "root") {
193-
let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/;
194208
let packagesByName = new Map(packages.map((x) => [x.packageJson.name, x]));
195209

196-
for (let line of changesetPublishOutput.stdout.split("\n")) {
197-
let match = line.match(newTagRegex);
198-
if (match === null) {
199-
continue;
200-
}
201-
let pkgName = match[1];
202-
let pkg = packagesByName.get(pkgName);
210+
for (let tag of nonMajorTags) {
211+
const [pkgName, _version] = tag.name.split(tagSeparator);
212+
const pkg = packagesByName.get(pkgName);
213+
203214
if (pkg === undefined) {
204215
throw new Error(
205216
`Package "${pkgName}" not found.` +
206217
"This is probably a bug in the action, please open an issue",
207218
);
208219
}
209-
releasedPackages.push(pkg);
220+
core.debug(
221+
`Tag ${tag.name} corresponds to package ${pkg.packageJson.name} (${pkg.dir})`,
222+
);
223+
releasedPackages.push([pkg, tag]);
210224
}
211225

226+
core.info(
227+
`Released packages found: ${JSON.stringify(releasedPackages.map(([p]) => p.packageJson.name))}`,
228+
);
229+
212230
if (createGithubReleases) {
213231
await Promise.all(
214-
releasedPackages.map((pkg) => {
232+
releasedPackages.map(([pkg, tag]) => {
215233
// Use simplified v<version> tag for root packages, otherwise use standard format
216234
const isRootPackage =
217235
rootPackageInfo && pkg.packageJson.name === rootPackageInfo.name;
218236
const tagName = isRootPackage
219237
? `v${pkg.packageJson.version}`
220-
: `${pkg.packageJson.name}${tagSeparator}${pkg.packageJson.version}`;
238+
: tag.name;
221239

222240
return createRelease(octokit, {
223241
pkg,
@@ -240,7 +258,10 @@ export async function runPublish({
240258
let match = line.match(newTagRegex);
241259

242260
if (match) {
243-
releasedPackages.push(pkg);
261+
releasedPackages.push([
262+
pkg,
263+
{ name: `v${pkg.packageJson.version}`, ref: "" },
264+
]);
244265
if (createGithubReleases) {
245266
await createRelease(octokit, {
246267
pkg,
@@ -255,7 +276,7 @@ export async function runPublish({
255276
if (releasedPackages.length) {
256277
return {
257278
published: true,
258-
publishedPackages: releasedPackages.map((pkg) => ({
279+
publishedPackages: releasedPackages.map(([pkg, _tag]) => ({
259280
name: pkg.packageJson.name,
260281
version: pkg.packageJson.version,
261282
})),

0 commit comments

Comments
 (0)