Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/nervous-eggs-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---

Reduce the number of API calls when releasing with `commitMode: github-api`
12 changes: 2 additions & 10 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,8 @@ export class Git {

async pushTag(tag: string) {
if (this.octokit) {
return this.octokit.rest.git
.createRef({
...github.context.repo,
ref: `refs/tags/${tag}`,
sha: github.context.sha,
})
.catch((err) => {
// Assuming tag was manually pushed in custom publish script
core.warning(`Failed to create tag ${tag}: ${err.message}`);
});
// a tag will be created automatically when creating a release
return;
}
await exec("git", ["push", "origin", tag], { cwd: this.cwd });
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
}
const git = new Git({
octokit: commitMode === "github-api" ? octokit : undefined,
cwd
cwd,
});

let setupGitUser = core.getBooleanInput("setupGitUser");
Expand Down Expand Up @@ -104,6 +104,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
git,
octokit,
createGithubReleases: core.getBooleanInput("createGithubReleases"),
commitMode,
cwd,
});

Expand Down
24 changes: 19 additions & 5 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const MAX_CHARACTERS_PER_MESSAGE = 60000;

const createRelease = async (
octokit: Octokit,
{ pkg, tagName }: { pkg: Package; tagName: string }
{
pkg,
tagName,
commitMode,
}: { pkg: Package; tagName: string; commitMode: "github-api" | "git-cli" }
) => {
let changelog;
try {
Expand All @@ -47,19 +51,28 @@ const createRelease = async (
);
}

await octokit.rest.repos.createRelease({
let createReleaseParams: Parameters<
typeof octokit.rest.repos.createRelease
>[0] = {
name: tagName,
tag_name: tagName,
body: changelogEntry.content,
prerelease: pkg.packageJson.version.includes("-"),
...github.context.repo,
});
};

if (commitMode === "github-api") {
createReleaseParams.target_commitish = github.context.sha;
}

await octokit.rest.repos.createRelease(createReleaseParams);
};

type PublishOptions = {
script: string;
octokit: Octokit;
createGithubReleases: boolean;
commitMode: "github-api" | "git-cli";
git: Git;
cwd: string;
};
Expand All @@ -80,6 +93,7 @@ export async function runPublish({
git,
octokit,
createGithubReleases,
commitMode,
cwd,
}: PublishOptions): Promise<PublishResult> {
let [publishCommand, ...publishArgs] = script.split(/\s+/);
Expand Down Expand Up @@ -118,7 +132,7 @@ export async function runPublish({
releasedPackages.map(async (pkg) => {
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
await git.pushTag(tagName);
await createRelease(octokit, { pkg, tagName });
await createRelease(octokit, { pkg, tagName, commitMode });
})
);
}
Expand All @@ -140,7 +154,7 @@ export async function runPublish({
if (createGithubReleases) {
const tagName = `v${pkg.packageJson.version}`;
await git.pushTag(tagName);
await createRelease(octokit, { pkg, tagName });
await createRelease(octokit, { pkg, tagName, commitMode });
}
break;
}
Expand Down