Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add INPUT_PUSH_ALL_TAGS option and refactor tag pushing logic
  • Loading branch information
WeslleyNasRocha authored and JounQin committed Apr 1, 2025
commit 38af686fead9fe1a21dc947e45c5d8be29442c8f
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
25 changes: 6 additions & 19 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,13 @@ export const push = async (
}

export const pushTags = async () => {
// Get the commit hash
const { stdout: commitHash } = await execWithOutput("git", [
"rev-parse",
"HEAD",
]);
// Get the tags that contain the commit
const { stdout: tags } = await execWithOutput("git", [
"--no-pager",
"tag",
"--contains",
commitHash,
]);
// Separate the tags into a list
const tagList = tags.split("\n");
// Push the tags individually to the remote
for (const tag of tagList) {
await exec("git", ["push", "origin", tag]);
}
};
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], {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -59,6 +59,7 @@ interface PublishOptions {
script: string
gitlabToken: string
createGitlabReleases?: boolean
pushAllTags?: boolean
cwd?: string
}

Expand All @@ -81,6 +82,7 @@ export async function runPublish({
script,
gitlabToken,
createGitlabReleases = true,
pushAllTags = true,
cwd = process.cwd(),
}: PublishOptions): Promise<PublishResult> {
const api = createApi(gitlabToken)
Expand All @@ -92,7 +94,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 @@ -112,6 +116,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,
Expand Down Expand Up @@ -141,6 +150,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 =>
Expand Down