Skip to content

Commit ca57073

Browse files
authored
Split git tag and github release options (#680)
* Split git tag and github release options * Rename to push-git-tags * Validate inputs
1 parent 0eae789 commit ca57073

6 files changed

Lines changed: 55 additions & 6 deletions

File tree

‎.changeset/chubby-geese-sink.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@changesets/action": major
3+
---
4+
5+
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.
6+
7+
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.

‎action.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ inputs:
2929
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
3030
required: false
3131
default: true
32+
push-git-tags:
33+
description: >
34+
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
35+
this option will also always be `true`.
36+
required: false
37+
default: true
3238
commit-mode:
3339
description: >
3440
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,

‎publish/action.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ inputs:
1818
description: "Whether to create Github releases after publish"
1919
required: false
2020
default: true
21+
push-git-tags:
22+
description: >
23+
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
24+
this option will also always be `true`.
25+
required: false
26+
default: true
2127
outputs:
2228
published:
2329
description: "A boolean value to indicate whether a publishing has happened or not"

‎src/index.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,22 @@ import {
122122
);
123123
}
124124

125+
const createGithubReleases = core.getBooleanInput(
126+
"create-github-releases",
127+
);
128+
const pushGitTags = core.getBooleanInput("push-git-tags");
129+
if (createGithubReleases && !pushGitTags) {
130+
throw new Error(
131+
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
132+
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
133+
"or set 'create-github-releases' to false.",
134+
);
135+
}
125136
const result = await runPublish({
126137
script: publishScript,
127138
github,
128-
createGithubReleases: core.getBooleanInput("create-github-releases"),
139+
createGithubReleases,
140+
pushGitTags,
129141
cwd,
130142
});
131143

‎src/publish/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ async function main() {
2020
const script = getOptionalInput("script");
2121
const packDirArtifactId = getOptionalInput("pack-dir-artifact-id");
2222
const createGithubReleases = core.getBooleanInput("create-github-releases");
23+
const pushGitTags = core.getBooleanInput("push-git-tags");
24+
25+
if (createGithubReleases && !pushGitTags) {
26+
throw new Error(
27+
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
28+
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
29+
"or set 'create-github-releases' to false.",
30+
);
31+
}
2332

2433
// If the user needs to change the cwd, set `working-directory` in the step instead
2534
const cwd = process.cwd();
@@ -39,6 +48,7 @@ async function main() {
3948
script,
4049
github,
4150
createGithubReleases,
51+
pushGitTags,
4252
cwd,
4353
fromPackDir,
4454
});

‎src/run.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type PublishOptions = {
6565
script?: string;
6666
fromPackDir?: string;
6767
createGithubReleases: boolean;
68+
pushGitTags: boolean;
6869
github: GitHub;
6970
cwd: string;
7071
};
@@ -87,6 +88,7 @@ export async function runPublish({
8788
fromPackDir,
8889
github,
8990
createGithubReleases,
91+
pushGitTags,
9092
cwd,
9193
}: PublishOptions): Promise<PublishResult> {
9294
const { octokit } = github;
@@ -137,12 +139,16 @@ export async function runPublish({
137139
releasedPackages.push(pkg);
138140
}
139141

140-
if (createGithubReleases) {
142+
if (createGithubReleases || pushGitTags) {
141143
await Promise.all(
142144
releasedPackages.map(async (pkg) => {
143145
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
144-
await github.pushTag(tagName);
145-
await createRelease(octokit, { pkg, tagName });
146+
if (pushGitTags) {
147+
await github.pushTag(tagName);
148+
}
149+
if (createGithubReleases) {
150+
await createRelease(octokit, { pkg, tagName });
151+
}
146152
}),
147153
);
148154
}
@@ -161,9 +167,11 @@ export async function runPublish({
161167

162168
if (match) {
163169
releasedPackages.push(pkg);
164-
if (createGithubReleases) {
165-
const tagName = `v${pkg.packageJson.version}`;
170+
const tagName = `v${pkg.packageJson.version}`;
171+
if (pushGitTags) {
166172
await github.pushTag(tagName);
173+
}
174+
if (createGithubReleases) {
167175
await createRelease(octokit, { pkg, tagName });
168176
}
169177
break;

0 commit comments

Comments
 (0)