diff --git a/.changeset/mighty-chefs-serve.md b/.changeset/mighty-chefs-serve.md new file mode 100644 index 00000000..9c305b0a --- /dev/null +++ b/.changeset/mighty-chefs-serve.md @@ -0,0 +1,5 @@ +--- +'changesets-gitlab': minor +--- + +fetch the tags and push each one individually diff --git a/README.md b/README.md index 50683cf2..a90c2ec2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/gitUtils.ts b/src/gitUtils.ts index 82b7bfbf..c62b15a7 100644 --- a/src/gitUtils.ts +++ b/src/gitUtils.ts @@ -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) + await exec('git', ['push', 'origin', tag]) +} + export const switchToMaybeExistingBranch = async (branch: string) => { const { stderr } = await execWithOutput('git', ['checkout', branch], { ignoreReturnCode: true, diff --git a/src/main.ts b/src/main.ts index 0f2625b4..957da0ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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) { diff --git a/src/run.ts b/src/run.ts index e6cc186e..af56e0c5 100644 --- a/src/run.ts +++ b/src/run.ts @@ -60,6 +60,7 @@ interface PublishOptions { script: string gitlabToken: string createGitlabReleases?: boolean + pushAllTags?: boolean cwd?: string } @@ -82,6 +83,7 @@ export async function runPublish({ script, gitlabToken, createGitlabReleases = true, + pushAllTags = true, cwd = process.cwd(), }: PublishOptions): Promise { const api = createApi(gitlabToken) @@ -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[] = [] @@ -113,6 +117,11 @@ export async function runPublish({ if (match) { releasedPackages.push(pkg) + if (!pushAllTags) { + await gitUtils.pushTag( + `${pkg.packageJson.name}@${pkg.packageJson.version}`, + ) + } if (createGitlabReleases) { await createRelease(api, { pkg, @@ -142,6 +151,13 @@ export async function runPublish({ } releasedPackages.push(pkg) } + if (!pushAllTags) { + for (const pkg of releasedPackages) { + await gitUtils.pushTag( + `${pkg.packageJson.name}@${pkg.packageJson.version}`, + ) + } + } if (createGitlabReleases) { await Promise.all( releasedPackages.map(pkg =>