Skip to content

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

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

Merged
merged 12 commits into from
Apr 1, 2025
Merged
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
---

feat: fetch the tags and push each one individually based on size of `packages` to be published and `api.FeatureFlags(projectId, 'git_push_create_all_pipelines')`
2 changes: 1 addition & 1 deletion .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Build
run: yarn build

- run: yarn dlx pkg-pr-new publish
- run: yarn dlx pkg-pr-new publish --compact
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "changesets-gitlab",
"version": "0.12.2",
"type": "module",
"repository": "https://github.com/rx-ts/changesets-gitlab.git",
"repository": "https://github.com/un-ts/changesets-gitlab.git",
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>",
"funding": "https://opencollective.com/changesets-gitlab",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const pushTags = async () => {
await exec('git', ['push', 'origin', '--tags'])
}

export const pushTag = async (tag: string) => {
await exec('git', ['push', 'origin', tag])
}

export const switchToMaybeExistingBranch = async (branch: string) => {
const { stderr } = await execWithOutput('git', ['checkout', branch], {
ignoreReturnCode: true,
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { runPublish, runVersion } from './run.js'
import type { MainCommandOptions } from './types.js'
import {
execSync,
FALSY_VALUES,
getOptionalInput,
getUsername,
TRUTHY_VALUES,
Expand Down Expand Up @@ -84,7 +85,9 @@ export const main = async ({
const result = await runPublish({
script: publishScript,
gitlabToken: GITLAB_TOKEN,
createGitlabReleases: getInput('create_gitlab_releases') !== 'false',
createGitlabReleases: !FALSY_VALUES.has(
getInput('create_gitlab_releases'),
),
})

if (result.published) {
Expand Down
6 changes: 1 addition & 5 deletions src/read-changeset-state.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { readPreState } from '@changesets/pre'
import _readChangesets from '@changesets/read'
import readChangesets from '@changesets/read'
import type { PreState, NewChangeset } from '@changesets/types'

export interface ChangesetState {
preState: PreState | undefined
changesets: NewChangeset[]
}

// @ts-expect-error - workaround for https://github.com/atlassian/changesets/issues/622
const readChangesets = (_readChangesets.default ||
_readChangesets) as typeof _readChangesets

export default async function readChangesetState(
cwd: string = process.cwd(),
): Promise<ChangesetState> {
Expand Down
51 changes: 32 additions & 19 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
getChangelogEntry,
getOptionalInput,
getVersionsByDirectory,
GITLAB_MAX_TAGS,
sortTheThings,
} from './utils.js'

const createRelease = async (
export const createRelease = async (
api: Gitlab,
{ pkg, tagName }: { pkg: Package; tagName: string },
) => {
Expand Down Expand Up @@ -55,26 +56,21 @@ const createRelease = async (
}
}

interface PublishOptions {
export interface PublishOptions {
script: string
gitlabToken: string
createGitlabReleases?: boolean
cwd?: string
}

interface PublishedPackage {
export interface PublishedPackage {
name: string
version: string
}

type PublishResult =
| {
published: false
}
| {
published: true
publishedPackages: PublishedPackage[]
}
export type PublishResult =
| { published: false }
| { published: true; publishedPackages: PublishedPackage[] }

// eslint-disable-next-line sonarjs/cognitive-complexity
export async function runPublish({
Expand All @@ -92,13 +88,23 @@ export async function runPublish({
{ cwd },
)

await gitUtils.pushTags()

const { packages, tool } = await getPackages(cwd)

const pushAllTags =
packages.length <= GITLAB_MAX_TAGS ||
(await api.FeatureFlags.show(
context.projectId,
'git_push_create_all_pipelines',
).catch(() => false))

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

const releasedPackages: Package[] = []

if (tool === 'root') {
if (packages.length === 0) {
if (packages.length !== 1) {
throw new Error(
`No package found.` +
'This is probably a bug in the action, please open an issue',
Expand All @@ -112,11 +118,9 @@ export async function runPublish({

if (match) {
releasedPackages.push(pkg)
const tagName = `v${pkg.packageJson.version}`
if (createGitlabReleases) {
await createRelease(api, {
pkg,
tagName: `v${pkg.packageJson.version}`,
})
await createRelease(api, { pkg, tagName })
}
break
}
Expand All @@ -141,6 +145,15 @@ export async function runPublish({
}
releasedPackages.push(pkg)
}
if (!pushAllTags) {
await Promise.all(
releasedPackages.map(pkg =>
gitUtils.pushTag(
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
),
),
)
}
if (createGitlabReleases) {
await Promise.all(
releasedPackages.map(pkg =>
Expand Down Expand Up @@ -181,7 +194,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
}
}

interface VersionOptions {
export interface VersionOptions {
script?: string
gitlabToken: string
cwd?: string
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ export const getUsername = (api: Gitlab) => {
export const cjsRequire =
typeof require === 'undefined' ? createRequire(import.meta.url) : require

export const FALSY_VALUES = new Set(['false', '0'])

export const TRUTHY_VALUES = new Set(['true', '1'])

export const GITLAB_MAX_TAGS = 4
Loading