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
7 changes: 7 additions & 0 deletions .changeset/chubby-geese-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@changesets/action": major
---

Add a new `push-git-tags` option that complements `create-github-releases` to control specifically if git tags should be created but not GitHub releases.

If `create-github-releases` was previously set to `false`, which also indirectly disabled git tag creation, git tags will now be created instead by default. If this is not desired, set `push-git-tags` to `false` explicitly.
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ inputs:
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
required: false
default: true
push-git-tags:
description: >
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
this option will also always be `true`.
required: false
default: true
commit-mode:
description: >
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
Expand Down
6 changes: 6 additions & 0 deletions publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ inputs:
description: "Whether to create Github releases after publish"
required: false
default: true
push-git-tags:
description: >
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
this option will also always be `true`.
required: false
default: true
outputs:
published:
description: "A boolean value to indicate whether a publishing has happened or not"
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,22 @@ import {
);
}

const createGithubReleases = core.getBooleanInput(
"create-github-releases",
);
const pushGitTags = core.getBooleanInput("push-git-tags");
if (createGithubReleases && !pushGitTags) {
throw new Error(
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
"or set 'create-github-releases' to false.",
);
}
const result = await runPublish({
script: publishScript,
github,
createGithubReleases: core.getBooleanInput("create-github-releases"),
createGithubReleases,
pushGitTags,
cwd,
});

Expand Down
10 changes: 10 additions & 0 deletions src/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ async function main() {
const script = getOptionalInput("script");
const packDirArtifactId = getOptionalInput("pack-dir-artifact-id");
const createGithubReleases = core.getBooleanInput("create-github-releases");
const pushGitTags = core.getBooleanInput("push-git-tags");

if (createGithubReleases && !pushGitTags) {
throw new Error(
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
"or set 'create-github-releases' to false.",
);
}

// If the user needs to change the cwd, set `working-directory` in the step instead
const cwd = process.cwd();
Expand All @@ -39,6 +48,7 @@ async function main() {
script,
github,
createGithubReleases,
pushGitTags,
cwd,
fromPackDir,
});
Expand Down
18 changes: 13 additions & 5 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type PublishOptions = {
script?: string;
fromPackDir?: string;
createGithubReleases: boolean;
pushGitTags: boolean;
github: GitHub;
cwd: string;
};
Expand All @@ -87,6 +88,7 @@ export async function runPublish({
fromPackDir,
github,
createGithubReleases,
pushGitTags,
cwd,
}: PublishOptions): Promise<PublishResult> {
const { octokit } = github;
Expand Down Expand Up @@ -137,12 +139,16 @@ export async function runPublish({
releasedPackages.push(pkg);
}

if (createGithubReleases) {
if (createGithubReleases || pushGitTags) {
await Promise.all(
releasedPackages.map(async (pkg) => {
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
await github.pushTag(tagName);
await createRelease(octokit, { pkg, tagName });
if (pushGitTags) {
await github.pushTag(tagName);
}
if (createGithubReleases) {
await createRelease(octokit, { pkg, tagName });
}
}),
);
}
Expand All @@ -161,9 +167,11 @@ export async function runPublish({

if (match) {
releasedPackages.push(pkg);
if (createGithubReleases) {
const tagName = `v${pkg.packageJson.version}`;
const tagName = `v${pkg.packageJson.version}`;
if (pushGitTags) {
await github.pushTag(tagName);
}
if (createGithubReleases) {
await createRelease(octokit, { pkg, tagName });
}
break;
Expand Down