Skip to content

Commit 38af686

Browse files
WeslleyNasRochaJounQin
authored andcommitted
feat: add INPUT_PUSH_ALL_TAGS option and refactor tag pushing logic
1 parent 3225157 commit 38af686

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its
3131
- `INPUT_TARGET_BRANCH` -> The merge request target branch. Defaults to current branch
3232
- `INPUT_CREATE_GITLAB_RELEASES` - A boolean value to indicate whether to create Gitlab releases after publish or not. Default true.
3333
- `INPUT_LABELS` - A comma separated string of labels to be added to the version package Gitlab Merge request
34+
- `INPUT_PUSH_ALL_TAGS` - A boolean value to indicate whether to push all tags at once using `git push origin --tags` [see](https://github.com/un-ts/changesets-gitlab/issues/194). Default true.
3435

3536
### Outputs
3637

src/git-utils.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,13 @@ export const push = async (
2727
}
2828

2929
export const pushTags = async () => {
30-
// Get the commit hash
31-
const { stdout: commitHash } = await execWithOutput("git", [
32-
"rev-parse",
33-
"HEAD",
34-
]);
35-
// Get the tags that contain the commit
36-
const { stdout: tags } = await execWithOutput("git", [
37-
"--no-pager",
38-
"tag",
39-
"--contains",
40-
commitHash,
41-
]);
42-
// Separate the tags into a list
43-
const tagList = tags.split("\n");
44-
// Push the tags individually to the remote
45-
for (const tag of tagList) {
46-
await exec("git", ["push", "origin", tag]);
47-
}
48-
};
30+
await exec('git', ['push', 'origin', '--tags'])
31+
}
4932

33+
export const pushTag = async (tag: string) => {
34+
console.log('Pushing tag: ' + tag)
35+
await exec('git', ['push', 'origin', tag])
36+
}
5037

5138
export const switchToMaybeExistingBranch = async (branch: string) => {
5239
const { stderr } = await execWithOutput('git', ['checkout', branch], {

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const main = async ({
8585
script: publishScript,
8686
gitlabToken: GITLAB_TOKEN,
8787
createGitlabReleases: getInput('create_gitlab_releases') !== 'false',
88+
pushAllTags: getInput('push_all_tags') !== 'false',
8889
})
8990

9091
if (result.published) {

src/run.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface PublishOptions {
5959
script: string
6060
gitlabToken: string
6161
createGitlabReleases?: boolean
62+
pushAllTags?: boolean
6263
cwd?: string
6364
}
6465

@@ -81,6 +82,7 @@ export async function runPublish({
8182
script,
8283
gitlabToken,
8384
createGitlabReleases = true,
85+
pushAllTags = true,
8486
cwd = process.cwd(),
8587
}: PublishOptions): Promise<PublishResult> {
8688
const api = createApi(gitlabToken)
@@ -92,7 +94,9 @@ export async function runPublish({
9294
{ cwd },
9395
)
9496

95-
await gitUtils.pushTags()
97+
if (pushAllTags) {
98+
await gitUtils.pushTags()
99+
}
96100

97101
const { packages, tool } = await getPackages(cwd)
98102
const releasedPackages: Package[] = []
@@ -112,6 +116,11 @@ export async function runPublish({
112116

113117
if (match) {
114118
releasedPackages.push(pkg)
119+
if (!pushAllTags) {
120+
await gitUtils.pushTag(
121+
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
122+
)
123+
}
115124
if (createGitlabReleases) {
116125
await createRelease(api, {
117126
pkg,
@@ -141,6 +150,13 @@ export async function runPublish({
141150
}
142151
releasedPackages.push(pkg)
143152
}
153+
if (!pushAllTags) {
154+
for (const pkg of releasedPackages) {
155+
await gitUtils.pushTag(
156+
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
157+
)
158+
}
159+
}
144160
if (createGitlabReleases) {
145161
await Promise.all(
146162
releasedPackages.map(pkg =>

0 commit comments

Comments
 (0)