diff --git a/.changeset/mighty-chefs-serve.md b/.changeset/mighty-chefs-serve.md new file mode 100644 index 00000000..5c7d2227 --- /dev/null +++ b/.changeset/mighty-chefs-serve.md @@ -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')` diff --git a/.github/workflows/pkg-pr-new.yml b/.github/workflows/pkg-pr-new.yml index 328ee3d1..65675645 100644 --- a/.github/workflows/pkg-pr-new.yml +++ b/.github/workflows/pkg-pr-new.yml @@ -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 diff --git a/package.json b/package.json index 42f19bc0..518fbe74 100644 --- a/package.json +++ b/package.json @@ -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) ", "funding": "https://opencollective.com/changesets-gitlab", "license": "MIT", diff --git a/src/git-utils.ts b/src/git-utils.ts index 82b7bfbf..b7f404d5 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -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, diff --git a/src/main.ts b/src/main.ts index bd666c25..e830b720 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ import { runPublish, runVersion } from './run.js' import type { MainCommandOptions } from './types.js' import { execSync, + FALSY_VALUES, getOptionalInput, getUsername, TRUTHY_VALUES, @@ -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) { diff --git a/src/read-changeset-state.ts b/src/read-changeset-state.ts index c2405d91..f50f50ea 100644 --- a/src/read-changeset-state.ts +++ b/src/read-changeset-state.ts @@ -1,5 +1,5 @@ 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 { @@ -7,10 +7,6 @@ export interface ChangesetState { 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 { diff --git a/src/run.ts b/src/run.ts index ad0a360c..de476120 100644 --- a/src/run.ts +++ b/src/run.ts @@ -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 }, ) => { @@ -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({ @@ -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', @@ -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 } @@ -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 => @@ -181,7 +194,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => { } } -interface VersionOptions { +export interface VersionOptions { script?: string gitlabToken: string cwd?: string diff --git a/src/utils.ts b/src/utils.ts index c209fcc3..083930dc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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