Skip to content

Commit

Permalink
align with future release move changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Jan 6, 2025
1 parent c9fd356 commit 285eda6
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bump packages
name: Bump auxiliary package versions
on:
workflow_dispatch:
push:
Expand Down Expand Up @@ -38,19 +38,19 @@ 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
- name: Create Pull Request
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
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/build/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export interface Config {
artifactUrlExtraTag?: string;
manpage?: ManPageConfig;
isDryRun?: boolean;
isAuxiliaryOnly?: boolean;
}
1 change: 1 addition & 0 deletions packages/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 9 additions & 5 deletions packages/build/src/npm-packages/bump.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawnSync } from '../helpers';
import {
IGNORE_BUMP_PACKAGES,
MONGOSH_RELEASE_ONLY_PACKAGES,
MONGOSH_RELEASE_PACKAGES,
PROJECT_ROOT,
} from './constants';
Expand All @@ -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<void> {
export async function bumpMongoshReleasePackages(): Promise<void> {
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);
Expand Down Expand Up @@ -62,7 +66,7 @@ export function bumpIndependentPackages() {
env: {
...process.env,
SKIP_BUMP_PACKAGES: [
...IGNORE_BUMP_PACKAGES,
...MONGOSH_RELEASE_ONLY_PACKAGES,
...MONGOSH_RELEASE_PACKAGES,
].join(','),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/npm-packages/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
2 changes: 2 additions & 0 deletions packages/build/src/npm-packages/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('npm-packages publishNpmPackages', function () {
listNpmPackages.returns(packages);

publishNpmPackages(
false,
false,
listNpmPackages,
markBumpedFilesAsAssumeUnchanged,
Expand Down Expand Up @@ -69,6 +70,7 @@ describe('npm-packages publishNpmPackages', function () {

try {
publishNpmPackages(
false,
false,
listNpmPackages,
markBumpedFilesAsAssumeUnchanged,
Expand Down
61 changes: 47 additions & 14 deletions packages/build/src/npm-packages/publish.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion packages/build/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export async function release(

if (command === 'bump') {
bumpIndependentPackages();
await bumpMongoshReleasePackages(config.version);
if (!config.isAuxiliaryOnly) {
await bumpMongoshReleasePackages();
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/run-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 285eda6

Please sign in to comment.