Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch the tags and push each one individually #195

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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/mighty-chefs-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'changesets-gitlab': minor
---

fetch the tags and push each one individually
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its
- `INPUT_TARGET_BRANCH` -> The merge request target branch. Defaults to current branch
- `INPUT_CREATE_GITLAB_RELEASES` - A boolean value to indicate whether to create Gitlab releases after publish or not. Default true.
- `INPUT_LABELS` - A comma separated string of labels to be added to the version package Gitlab Merge request
- `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.

### Outputs

Expand Down
5 changes: 5 additions & 0 deletions src/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export const pushTags = async () => {
await exec('git', ['push', 'origin', '--tags'])
}

export const pushTag = async (tag: string) => {
console.log('Pushing tag: ' + tag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('Pushing tag: ' + tag)

await exec('git', ['push', 'origin', tag])
}

export const switchToMaybeExistingBranch = async (branch: string) => {
const { stderr } = await execWithOutput('git', ['checkout', branch], {
ignoreReturnCode: true,
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const main = async ({
script: publishScript,
gitlabToken: GITLAB_TOKEN,
createGitlabReleases: getInput('create_gitlab_releases') !== 'false',
pushAllTags: getInput('push_all_tags') !== 'false',
})

if (result.published) {
Expand Down
18 changes: 17 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface PublishOptions {
script: string
gitlabToken: string
createGitlabReleases?: boolean
pushAllTags?: boolean
cwd?: string
}

Expand All @@ -82,6 +83,7 @@ export async function runPublish({
script,
gitlabToken,
createGitlabReleases = true,
pushAllTags = true,
cwd = process.cwd(),
}: PublishOptions): Promise<PublishResult> {
const api = createApi(gitlabToken)
Expand All @@ -93,7 +95,9 @@ export async function runPublish({
{ cwd },
)

await gitUtils.pushTags()
if (pushAllTags) {
await gitUtils.pushTags()
}

const { packages, tool } = await getPackages(cwd)
const releasedPackages: Package[] = []
Expand All @@ -113,6 +117,11 @@ export async function runPublish({

if (match) {
releasedPackages.push(pkg)
if (!pushAllTags) {
await gitUtils.pushTag(
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
Copy link
Member

@JounQin JounQin Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tag should be only vx.y.z for one package. See also

https://github.com/changesets/changesets/blob/01c037c0462540196b5d3d0c0241d8752b465b4b/packages/cli/src/commands/publish/index.ts#L119-L135

And we can actually leave to use pushAllTags because there is only one.

)
}
if (createGitlabReleases) {
await createRelease(api, {
pkg,
Expand Down Expand Up @@ -142,6 +151,13 @@ export async function runPublish({
}
releasedPackages.push(pkg)
}
if (!pushAllTags) {
for (const pkg of releasedPackages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Promise.all be better?

await gitUtils.pushTag(
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
)
}
}
if (createGitlabReleases) {
await Promise.all(
releasedPackages.map(pkg =>
Expand Down