diff --git a/.changeset/chubby-geese-sink.md b/.changeset/chubby-geese-sink.md new file mode 100644 index 00000000..c1dad759 --- /dev/null +++ b/.changeset/chubby-geese-sink.md @@ -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. diff --git a/action.yml b/action.yml index c38f8386..c0f2923b 100644 --- a/action.yml +++ b/action.yml @@ -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, diff --git a/publish/action.yml b/publish/action.yml index b90c0c54..809c5509 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -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" diff --git a/src/index.ts b/src/index.ts index 1ce7cafa..aa2b5e1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, }); diff --git a/src/publish/index.ts b/src/publish/index.ts index fd6ce2d2..15bf8ab3 100644 --- a/src/publish/index.ts +++ b/src/publish/index.ts @@ -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(); @@ -39,6 +48,7 @@ async function main() { script, github, createGithubReleases, + pushGitTags, cwd, fromPackDir, }); diff --git a/src/run.ts b/src/run.ts index 20931091..7c8b8233 100644 --- a/src/run.ts +++ b/src/run.ts @@ -65,6 +65,7 @@ type PublishOptions = { script?: string; fromPackDir?: string; createGithubReleases: boolean; + pushGitTags: boolean; github: GitHub; cwd: string; }; @@ -87,6 +88,7 @@ export async function runPublish({ fromPackDir, github, createGithubReleases, + pushGitTags, cwd, }: PublishOptions): Promise { const { octokit } = github; @@ -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 }); + } }), ); } @@ -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;