From 285eda647e98e352dec0af735df55e9a8fa3ccf2 Mon Sep 17 00:00:00 2001 From: gagik Date: Mon, 6 Jan 2025 12:09:38 +0100 Subject: [PATCH] align with future release move changes --- ...ckages.yml => bump-auxiliary-packages.yml} | 12 ++-- ...ges.yml => release-auxiliary-packages.yml} | 8 +-- package-lock.json | 4 +- package.json | 12 ++-- packages/build/package.json | 4 ++ packages/build/src/config/config.ts | 1 + packages/build/src/index.ts | 1 + packages/build/src/npm-packages/bump.ts | 14 +++-- packages/build/src/npm-packages/constants.ts | 4 +- .../build/src/npm-packages/publish.spec.ts | 2 + packages/build/src/npm-packages/publish.ts | 61 ++++++++++++++----- packages/build/src/release.ts | 4 +- packages/build/src/run-publish.ts | 2 +- 13 files changed, 85 insertions(+), 44 deletions(-) rename .github/workflows/{bump-packages.yml => bump-auxiliary-packages.yml} (79%) rename .github/workflows/{release-packages.yml => release-auxiliary-packages.yml} (87%) diff --git a/.github/workflows/bump-packages.yml b/.github/workflows/bump-auxiliary-packages.yml similarity index 79% rename from .github/workflows/bump-packages.yml rename to .github/workflows/bump-auxiliary-packages.yml index 0f7348bd8..caa0024b5 100644 --- a/.github/workflows/bump-packages.yml +++ b/.github/workflows/bump-auxiliary-packages.yml @@ -1,4 +1,4 @@ -name: Bump packages +name: Bump auxiliary package versions on: workflow_dispatch: push: @@ -38,9 +38,9 @@ jobs: - name: Bump packages env: - LAST_BUMP_COMMIT_MESSAGE: "chore(release): bump package versions" + LAST_BUMP_COMMIT_MESSAGE: "chore(release): bump auxiliary package versions" run: | - npm run bump-packages + npm run bump-auxiliary git add . git commit --no-allow-empty -m "$LAST_BUMP_COMMIT_MESSAGE" || true @@ -48,9 +48,9 @@ jobs: uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5 with: token: ${{ steps.app-token.outputs.token }} - commit-message: "chore(release): bump package versions" - branch: ci/bump-packages - title: "chore(release): bump package versions" + commit-message: "chore(release): bump auxiliary package versions" + branch: ci/bump-auxiliary-packages + title: "chore(release): bump auxiliary package versions" labels: no-title-validation body: | - Bump package versions diff --git a/.github/workflows/release-packages.yml b/.github/workflows/release-auxiliary-packages.yml similarity index 87% rename from .github/workflows/release-packages.yml rename to .github/workflows/release-auxiliary-packages.yml index 215958957..8e825b60e 100644 --- a/.github/workflows/release-packages.yml +++ b/.github/workflows/release-auxiliary-packages.yml @@ -1,4 +1,4 @@ -name: Publish +name: Publish Auxiliary Packages on: # NOTE: avoid using the manual execution unless is the only way to fix some issue, # rather retry failed jobs in case of flakes. The manual execution can potentially @@ -53,9 +53,3 @@ jobs: git update-index --assume-unchanged .npmrc npm run publish-packages - - name: "Publish tags" - run: | - npx lerna list -a --json | \ - jq -r '.[] | .name + "@" + .version' | \ - xargs -i sh -c "git tag -a {} -m {} || true" - git push --follow-tags diff --git a/package-lock.json b/package-lock.json index 6123da22c..e177e74ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -66,7 +66,7 @@ "nyc": "^15.1.0", "pkg-up": "^3.1.0", "rimraf": "^3.0.2", - "semver": "^7.5.4", + "semver": "^7.6.3", "sinon": "^7.5.0", "sinon-chai": "^3.5.0", "terser-webpack-plugin": "^4.2.3", @@ -5847,7 +5847,7 @@ "toposort": "^2.0.2" }, "bin": { - "bump-monorepo-packages": "bin/bump-packages.js", + "bump-monorepo-packages": "bin/bump-auxiliary.js", "depalign": "bin/depalign.js", "monorepo-where": "bin/where.js", "precommit": "bin/precommit.js" diff --git a/package.json b/package.json index 5f7bc42db..af12edefb 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,8 @@ "prepare": "husky", "precommit": "precommit", "preinstall": "node scripts/sort-workspaces.js", - "bump-packages": "npm run bump-packages --workspace @mongosh/build", - "publish-packages": "lerna publish from-package --no-verify-access --no-push --no-git-tag-version --yes" + "bump-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build", + "publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build" }, "config": { "unsafe-perm": true @@ -100,6 +100,7 @@ "@babel/compat-data": "^7.9.0", "@mongodb-js/monorepo-tools": "^1.1.10", "@mongodb-js/sbom-tools": "^0.7.0", + "@pkgjs/nv": "^0.2.2", "@types/chai": "^4.2.5", "@types/mocha": "^5.2.7", "@types/node": "^14.14.6", @@ -109,6 +110,7 @@ "@types/which": "^1.3.2", "chai": "^4.2.0", "cross-env": "^6.0.3", + "depcheck": "^1.4.7", "duplexpair": "^1.0.2", "find-up": "^5.0.0", "glob": "^10.3.12", @@ -120,7 +122,7 @@ "nyc": "^15.1.0", "pkg-up": "^3.1.0", "rimraf": "^3.0.2", - "semver": "^7.5.4", + "semver": "^7.6.3", "sinon": "^7.5.0", "sinon-chai": "^3.5.0", "terser-webpack-plugin": "^4.2.3", @@ -132,9 +134,7 @@ "webpack-bundle-analyzer": "^4.7.0", "webpack-cli": "^4.3.1", "which": "^2.0.2", - "yaml": "^1.10.0", - "depcheck": "^1.4.7", - "@pkgjs/nv": "^0.2.2" + "yaml": "^1.10.0" }, "optionalDependencies": { "lerna": "^8.1.8" diff --git a/packages/build/package.json b/packages/build/package.json index 8f2830de7..774f9cb8c 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -26,6 +26,10 @@ "evergreen-release": "ts-node -r ../../scripts/import-expansions.js src/index.ts", "release": "ts-node src/index.ts trigger-release", "prettier": "prettier", + "bump": "ts-node src/index.ts bump", + "publish": "ts-node src/index.ts publish", + "bump-auxiliary": "ts-node src/index.ts bump --auxiliary", + "publish-auxiliary": "ts-node src/index.ts publish --auxiliary", "reformat": "npm run prettier -- --write . && npm run eslint --fix" }, "license": "Apache-2.0", diff --git a/packages/build/src/config/config.ts b/packages/build/src/config/config.ts index 4502f48ab..0e1b6daf2 100644 --- a/packages/build/src/config/config.ts +++ b/packages/build/src/config/config.ts @@ -46,4 +46,5 @@ export interface Config { artifactUrlExtraTag?: string; manpage?: ManPageConfig; isDryRun?: boolean; + isAuxiliaryOnly?: boolean; } diff --git a/packages/build/src/index.ts b/packages/build/src/index.ts index 064557fa6..496226a9f 100644 --- a/packages/build/src/index.ts +++ b/packages/build/src/index.ts @@ -59,6 +59,7 @@ if (require.main === module) { } config.isDryRun ||= process.argv.includes('--dry-run'); + config.isAuxiliaryOnly ||= process.argv.includes('--auxiliary'); await release(command, config); } diff --git a/packages/build/src/npm-packages/bump.ts b/packages/build/src/npm-packages/bump.ts index 544b605bd..dde1ba719 100644 --- a/packages/build/src/npm-packages/bump.ts +++ b/packages/build/src/npm-packages/bump.ts @@ -1,6 +1,6 @@ import { spawnSync } from '../helpers'; import { - IGNORE_BUMP_PACKAGES, + MONGOSH_RELEASE_ONLY_PACKAGES, MONGOSH_RELEASE_PACKAGES, PROJECT_ROOT, } from './constants'; @@ -10,9 +10,13 @@ import path from 'path'; import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools'; /** Bumps only the main mongosh release packages to the set version. */ -export async function bumpMongoshReleasePackages( - version: string -): Promise { +export async function bumpMongoshReleasePackages(): Promise { + const version = process.env.MONGOSH_RELEASE_VERSION; + if (!version) { + throw new Error( + 'MONGOSH_RELEASE_VERSION version not specified during mongosh bump' + ); + } console.info(`mongosh: Bumping package versions to ${version}`); const monorepoRootPath = path.resolve(__dirname, '..', '..', '..', '..'); const packages = await getPackagesInTopologicalOrder(monorepoRootPath); @@ -62,7 +66,7 @@ export function bumpIndependentPackages() { env: { ...process.env, SKIP_BUMP_PACKAGES: [ - ...IGNORE_BUMP_PACKAGES, + ...MONGOSH_RELEASE_ONLY_PACKAGES, ...MONGOSH_RELEASE_PACKAGES, ].join(','), }, diff --git a/packages/build/src/npm-packages/constants.ts b/packages/build/src/npm-packages/constants.ts index 1d742f920..54d331230 100644 --- a/packages/build/src/npm-packages/constants.ts +++ b/packages/build/src/npm-packages/constants.ts @@ -11,8 +11,8 @@ export const LERNA_BIN = path.resolve( /** Packages which get bumped only as part of the mongosh release. */ export const MONGOSH_RELEASE_PACKAGES = ['mongosh', '@mongosh/cli-repl']; -/** Packages which always get ignored when doing a release or bump */ -export const IGNORE_BUMP_PACKAGES = [ +/** Packages which always get excluded when doing a release or bump */ +export const EXCLUDE_RELEASE_PACKAGES = [ '@mongodb-js/eslint-config-mongosh', '@mongodb-js/tsconfig-mongosh', ]; diff --git a/packages/build/src/npm-packages/publish.spec.ts b/packages/build/src/npm-packages/publish.spec.ts index 08815dc49..ab28a8ce8 100644 --- a/packages/build/src/npm-packages/publish.spec.ts +++ b/packages/build/src/npm-packages/publish.spec.ts @@ -30,6 +30,7 @@ describe('npm-packages publishNpmPackages', function () { listNpmPackages.returns(packages); publishNpmPackages( + false, false, listNpmPackages, markBumpedFilesAsAssumeUnchanged, @@ -69,6 +70,7 @@ describe('npm-packages publishNpmPackages', function () { try { publishNpmPackages( + false, false, listNpmPackages, markBumpedFilesAsAssumeUnchanged, diff --git a/packages/build/src/npm-packages/publish.ts b/packages/build/src/npm-packages/publish.ts index 624c45760..6165b0d19 100644 --- a/packages/build/src/npm-packages/publish.ts +++ b/packages/build/src/npm-packages/publish.ts @@ -1,17 +1,40 @@ import path from 'path'; -import { LERNA_BIN, PROJECT_ROOT } from './constants'; +import { + EXCLUDE_RELEASE_PACKAGES, + LERNA_BIN, + MONGOSH_RELEASE_PACKAGES, + PROJECT_ROOT, +} from './constants'; import type { LernaPackageDescription } from './list'; import { listNpmPackages as listNpmPackagesFn } from './list'; import { spawnSync } from '../helpers/spawn-sync'; +import type { SpawnSyncOptionsWithStringEncoding } from 'child_process'; export function publishNpmPackages( - isDryRun: boolean, + isDryRun = false, + isAuxiliaryOnly = false, listNpmPackages: typeof listNpmPackagesFn = listNpmPackagesFn, markBumpedFilesAsAssumeUnchangedFn: typeof markBumpedFilesAsAssumeUnchanged = markBumpedFilesAsAssumeUnchanged, spawnSyncFn: typeof spawnSync = spawnSync ): void { - const packages = listNpmPackages(); + const commandOptions: SpawnSyncOptionsWithStringEncoding = { + stdio: 'inherit', + cwd: PROJECT_ROOT, + encoding: 'utf8', + env: { + ...process.env, + ...(isDryRun ? { npm_config_dry_run: 'true' } : {}), + }, + }; + let packages = listNpmPackages().filter( + (packageConfig) => !EXCLUDE_RELEASE_PACKAGES.includes(packageConfig.name) + ); + if (isAuxiliaryOnly) { + packages = packages.filter( + (packageConfig) => !MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name) + ); + } // Lerna requires a clean repository for a publish from-package (--force-publish does not have any effect here) // we use git update-index --assume-unchanged on files we know have been bumped markBumpedFilesAsAssumeUnchangedFn(packages, true); @@ -23,26 +46,36 @@ export function publishNpmPackages( 'from-package', '--no-private', '--no-changelog', - '--no-push', '--exact', - '--no-git-tag-version', + // During mongosh releases we handle the tags manually + ...(!isAuxiliaryOnly ? ['--no-git-tag-version', '--no-push'] : []), '--force-publish', '--yes', '--no-verify-access', ], - { - stdio: 'inherit', - cwd: PROJECT_ROOT, - encoding: 'utf8', - env: { - ...process.env, - ...(isDryRun ? { npm_config_dry_run: 'true' } : {}), - }, - } + commandOptions ); } finally { markBumpedFilesAsAssumeUnchangedFn(packages, false); } + + if (!isAuxiliaryOnly) { + const mongoshVersion = packages.find( + (packageConfig) => packageConfig.name === 'mongosh' + )?.version; + + if (!mongoshVersion) { + throw new Error('Mongosh package not found'); + } + + spawnSync( + 'git', + ['tag', '-a', mongoshVersion, '-m', mongoshVersion], + commandOptions + ); + + spawnSync('git', ['push', '--follow-tags'], commandOptions); + } } export function markBumpedFilesAsAssumeUnchanged( diff --git a/packages/build/src/release.ts b/packages/build/src/release.ts index ded54215d..ccd7547a2 100644 --- a/packages/build/src/release.ts +++ b/packages/build/src/release.ts @@ -57,7 +57,9 @@ export async function release( if (command === 'bump') { bumpIndependentPackages(); - await bumpMongoshReleasePackages(config.version); + if (!config.isAuxiliaryOnly) { + await bumpMongoshReleasePackages(); + } return; } diff --git a/packages/build/src/run-publish.ts b/packages/build/src/run-publish.ts index 4c8eaeb6c..c057fc4cc 100644 --- a/packages/build/src/run-publish.ts +++ b/packages/build/src/run-publish.ts @@ -81,7 +81,7 @@ export async function runPublish( // ensures the segment api key to be present in the published packages await writeBuildInfo(config, 'packaged'); - publishNpmPackages(!!config.isDryRun); + publishNpmPackages(config.isDryRun, config.isAuxiliaryOnly); await publishToHomebrew( homebrewCoreGithubRepo,