Skip to content

Commit

Permalink
chore: fix several release issues (#4059)
Browse files Browse the repository at this point in the history
A good bundle of 3 issues.

## The NXpocalypse

Originally, my removal of the plugin caused that, but I still think the
plugin was a bit of a code-smell hiding some other issue, such as the
following one.
For some obscure reason, I did not succeed in deciphering
`release:phase2`(before my changes), which systematically refuses to run
its dependents, even when they are defined.
So, I scrapped it and replaced it with a single task, `release:phase1`
(after my changes). It does the same thing, but it's a bit simpler.

## Whoopsie daisy in
coveo/semantic-monorepo-tools@9164711

So, fun fact: The command works as intended on Windows and returns the
correct stuff.
On Linux/macOS, the double quotes are not interpreted nicely or the same
way, and every commit ends with `format:`.
That ain't a good semantic commit message, so since we updated
eb3542e,
every release has been a patch...

Will be fixed in coveo/semantic-monorepo-tools#240, but we can remove
the patch when we update, it'll be about the same.

## Reify choke on packages installing themselves as a dependency.

It's probably a way to make it work, but I decided to replace the
version by ' file:.`. It's a dev dep, so it has no impact on the
consumers and saves me some headaches.

## Was it tested?

Yes: I used some admin magic to be able to run the Prerelease enviro on
this branch until it worked. This is now revoked/back to normal.
  • Loading branch information
louis-bompart authored Jun 6, 2024
1 parent 2ede6d1 commit 8156ae8
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/masterbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ jobs:
- name: Release
run: |
npm run nx:graph
npm run release:phase1-3
npm run release:phase1
npm run release:phase2
env:
DEBUG: '*'
IS_PRERELEASE: 'true'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
# registry-url: 'https://npm.pkg.github.com'
# node-version-file: '.nvmrc'
# - name: Publish to GitHub Packages
# run: npm run release:phase5
# run: npm run release:phase4
# env:
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DEBUG: ${{ inputs.debug && '*' || '' }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ sarifs
**.cy.ts.mp4
.cspellcache
scripts/translation-gpt/temporary.json
.nx/cache

# CI Release
topology.json
.git-message
.nx/cache
packages/atomic/custom-elements.json
.nx
32 changes: 17 additions & 15 deletions internal-docs/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ This task accomplishes its purpose by:
1. Committing a `.git-lock` file to the main branch.
2. Updating the repository's settings to enable "Require branches to be up to date before merging" for the main branch.

## `release:phase1` (bump package versions)
## `release:phase1`

### Sub-phase 1: Bump package versions

This task is run individually on every package, in topological order (dependencies first, then dependants).

The purpose of this task is to update the `package.json` file of every package to contain their new version and their new dependencies. This serves multiple purposes:
The purpose of this sub-phase is to update the `package.json` file of every package to contain their new version and their new dependencies. This serves multiple purposes:

1. NPM publishing.
- When publishing packages to NPM, NPM determines the version of the package by looking at its `package.json` file.
Expand All @@ -61,31 +63,25 @@ Additionally, this task will update the `CHANGELOG.md` file of the package to co

This task does not make any changes to the `package-lock.json` file at the root of the repository, since doing so would cause [an error with NPM Workspaces](https://github.com/npm/cli/issues/5506).

## `release:build` (build bumped packages)

This task is run individually on every package, immediately after `release:phase1`.

The purpose of this task is to re-build a project right after it was bumped and before it gets published. This is needed because many packages contain information about their own version in their compiled code.
### Sub-phase 2: build

This task (and its dependencies) are automatically generated by `@coveo/nx-plugin`, which clones all `build` tasks and their respective dependencies. This is needed to ensure `release:build` depends on the current package's `release:phase1`. **Warning**: changes to `@coveo/nx-plugin` won't take effect until `npm install` is executed, which triggers Nx to rebuild its graph.
The purpose of this sub-phase is to re-build a project right after it was bumped and before it gets published. This is needed because many packages contain information about their own version in their compiled code.

## `release:phase2` (publish to NPM)

This task is run individually on every package, immediately after `release:build`.
### Sub-phase 3: publish

This workflow works on the assumption that we can't bump a package's version if any of its dependencies isn't published to NPM. The purpose of this task is to publish packages to NPM before dependant packages bump their versions.

If a package is already published to NPM, this task will exit without error. After a package is published, this task will repeatedly query NPM until it confirms that the package exists in the registry.

## `release:phase3` (reify `package-lock.json`)
## `release:phase2` (reify `package-lock.json`)

This task is run once at the root of the repository after every package's version was bumped.

The purpose of this task is to re-generate the root `package-lock.json` file using [Arborist](https://www.npmjs.com/package/@npmcli/arborist), which should confirm that the version bumps were successful.

Scheduled releases will commit the new `package-lock.json` to the main branch, which ensures that contributors can run `npm install` without unnecessary changes being made to their `package-lock.json`.

## `release:phase4` (commit version bumps)
## `release:phase3` (commit version bumps)

This task is only run for the scheduled release.

Expand All @@ -98,12 +94,18 @@ This task will create a new "version bump" commit, which will contain:

This task will also revert the changes from `release:phase0` to allow merging new features and fixes.

## `release:phase5` (publish to GitHub Packages)
## `release:phase4` (publish to GitHub Packages)

> [!WARNING]
> Currently disabled.
This task will do the same thing as `release:phase2`, but is intended to publish the NPM package to GitHub Packages instead.
This task will do the same thing as `release:phase1`, sub-phase 3, but is intended to publish the NPM package to GitHub Packages instead.

# Deploying

> [!NOTE]
> Probably out-of-date
After the release is completed on Git, GitHub and NPM, the release workflow will start a job on a Coveo-Hosted-runners to trigger the deployment pipeline.
From there on, the process then follows this diagram (starting with 'Continue GitHub workflow on Coveo Hosted Runner):

Expand Down
25 changes: 16 additions & 9 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,23 @@
"dependsOn": ["build"]
},
"release:phase1": {
"dependsOn": ["^release:phase1", "^release:phase2"]
},
"release:build": {
"dependsOn": ["^release:build", "release:phase1"]
},
"release:phase2": {
"dependsOn": ["release:build", "release:phase1"]
"dependsOn": ["^release:phase1"],
"executor": "nx:run-commands",
"options": {
"commands": [
"npm run publish:bump",
"npm run build",
"npm run publish:npm"
],
"parallel": false,
"cwd": "{projectRoot}"
}
},
"release:phase5": {
"dependsOn": ["^release:phase5"]
"release:phase4": {
"dependsOn": ["^release:phase4"],
"//": "Currently disabled TODO KIT-3074",
"executor": "nx:noop",
"options": {"script": "publish:bump"}
},
"cached:build:stencil": {
"cache": true
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"pre-commit": "lint-staged",
"promote:npm:latest": "nx run-many --target=promote:npm:latest",
"notify:docs": "node ./scripts/notify-docs/published-ui-kit.mjs",
"release": "npm run nx:graph && npm run release:phase0 && npm run release:phase1-3 && npm run release:phase4",
"release": "npm run nx:graph && npm run release:phase0 && npm run release:phase1 && npm run release:phase2 && npm run release:phase3",
"nx:graph": "nx graph --file=topology.json",
"release:phase0": "npm run-script -w=@coveo/release git-lock",
"release:phase1-3": "npm run release:phase2 && npm run-script -w=@coveo/release reify",
"release:phase2": "nx run-many --targets=release:phase2 --all --parallel=false --output-style=stream",
"release:phase4": "npm run-script -w=@coveo/release git-publish-all",
"release:phase5": "nx run-many --targets=release:phase5 --all"
"release:phase1": "nx run-many --targets=release:phase1 --all --parallel=false --output-style=stream",
"release:phase2": "npm run-script -w=@coveo/release reify",
"release:phase3": "npm run-script -w=@coveo/release git-publish-all",
"release:phase4": "nx run-many --targets=release:phase4 --all"
},
"devDependencies": {
"@actions/core": "1.10.1",
Expand Down
6 changes: 2 additions & 4 deletions packages/atomic-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"build": "nx build",
"build:bundles": "ng build",
"build:assets": "ncp ../atomic/dist/atomic/assets projects/atomic-angular/dist/assets && ncp ../atomic/dist/atomic/lang projects/atomic-angular/dist/lang",
"release:phase1": "node ./scripts/bump.mjs",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "node ./scripts/publish-npm.mjs"
"publish:npm": "node ./scripts/publish-npm.mjs",
"publish:bump": "node ./scripts/bump.mjs"
},
"private": true,
"dependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/atomic-hosted-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
"e2e:watch": "cypress open --browser chrome --e2e",
"e2e": "cypress run --browser chrome",
"validate:definitions": "tsc --noEmit --esModuleInterop --skipLibCheck ./dist/types/components.d.ts",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/atomic-hosted-page/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]
},
"targets": {
"release:phase1": {},
"cached:build:stencil": {
"dependsOn": ["^build"],
"inputs": ["^production", "production"],
Expand Down
4 changes: 1 addition & 3 deletions packages/atomic-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
"build:bundles:cjs": "tsc -p tsconfig.cjs.json",
"build:bundles:iife": "rollup --config rollup.config.mjs",
"build:bundles": "concurrently \"npm run build:bundles:esm\" \"npm run build:bundles:cjs\" \"npm run build:bundles:iife\"",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest",
"build:assets": "ncp ../atomic/dist/atomic/assets dist/assets && ncp ../atomic/dist/atomic/lang dist/lang "
},
Expand Down
1 change: 1 addition & 0 deletions packages/atomic-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "atomic-react",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"targets": {
"release:phase1": {},
"cached:build": {
"dependsOn": ["^build", "clean"],
"executor": "nx:run-commands",
Expand Down
6 changes: 2 additions & 4 deletions packages/atomic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
"e2e:snapshots:watch": "cypress open --config-file cypress-screenshots.config.ts --browser chrome",
"e2e:insight": "cypress run --config-file cypress-insight-panel.config.ts --browser chrome",
"e2e:insight:watch": "cypress open --config-file cypress-insight-panel.config.ts --browser chrome",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest",
"validate:definitions": "tsc --noEmit --esModuleInterop --skipLibCheck ./dist/types/components.d.ts"
},
Expand All @@ -67,7 +65,7 @@
"devDependencies": {
"@axe-core/playwright": "4.9.1",
"@babel/core": "7.24.5",
"@coveo/atomic": "2.65.5",
"@coveo/atomic": "file:.",
"@coveo/headless": "2.63.5",
"@coveo/release": "1.0.0",
"@custom-elements-manifest/analyzer": "0.10.2",
Expand Down
1 change: 1 addition & 0 deletions packages/atomic/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"script": "validate:definitions"
}
},
"release:phase1": {},
"build": {
"dependsOn": [
"cached:build:stencil",
Expand Down
4 changes: 1 addition & 3 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
"build:bundles": "node esbuild.mjs",
"build:definitions": "tsc -p src/tsconfig.build.json -d --emitDeclarationOnly --declarationDir dist/definitions",
"clean": "rimraf -rf dist/*",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest",
"e2e": "npm run e2e:saml",
"e2e:saml": "vite manual-e2e/saml/"
Expand Down
1 change: 1 addition & 0 deletions packages/auth/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "auth",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"targets": {
"release:phase1": {},
"cached:build": {
"executor": "nx:run-commands",
"options": {
Expand Down
4 changes: 1 addition & 3 deletions packages/bueno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
"clean": "rimraf -rf dist/*",
"test": "jest",
"test:watch": "jest --watch --colors --no-cache",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/bueno/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "bueno",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"targets": {
"release:phase1": {},
"cached:build": {
"executor": "nx:run-commands",
"options": {
Expand Down
4 changes: 1 addition & 3 deletions packages/headless-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
"test": "jest",
"test:watch": "jest --watch --colors --no-cache",
"lint": "eslint .; publint",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/headless-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "headless-react",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"targets": {
"release:phase1": {},
"cached:build": {
"executor": "nx:run-commands",
"options": {
Expand Down
4 changes: 1 addition & 3 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
"test:watch": "jest --watch --colors --no-cache --silent=false",
"test:unit": "jest --testPathIgnorePatterns=src/integration-tests",
"test:integration": "jest --testPathPattern=src/integration-tests",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest",
"build:doc": "npm run build:doc:extract && npm run build:doc:parse",
"build:doc:extract": "node ./scripts/extract-documentation.mjs",
Expand Down
1 change: 1 addition & 0 deletions packages/headless/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"targets": {
"release:phase1": {},
"cached:build": {
"outputs": [
"{projectRoot}/dist",
Expand Down
4 changes: 1 addition & 3 deletions packages/quantic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
"publish:sfdx": "../../node_modules/.bin/ts-node scripts/build/create-package.ts --remove-translations",
"promote:sfdx": "npm run publish:sfdx -- --promote",
"promote:sfdx:ci": "npm run publish:sfdx -- --promote --ci",
"release:phase1": "npm run-script -w=@coveo/release bump",
"release:phase2": "npm run publish:npm",
"release:phase5": "npm run publish:npm",
"publish:npm": "npm run-script -w=@coveo/release npm-publish",
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest",
"preinstall": "node scripts/npm/check-sfdx-project.js",
"postinstall": "node scripts/npm/setup-quantic.js"
Expand Down
1 change: 1 addition & 0 deletions packages/quantic/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"negativeNonBuildOutputs": ["!{projectRoot}/reports"]
},
"targets": {
"release:phase1": {},
"cached:build": {
"outputs": [
"{projectRoot}/docs/out",
Expand Down
13 changes: 13 additions & 0 deletions patches/@coveo+semantic-monorepo-tools+2.4.31.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/@coveo/semantic-monorepo-tools/dist/git/getCommits.js b/node_modules/@coveo/semantic-monorepo-tools/dist/git/getCommits.js
index 302c25a..1bbd782 100644
--- a/node_modules/@coveo/semantic-monorepo-tools/dist/git/getCommits.js
+++ b/node_modules/@coveo/semantic-monorepo-tools/dist/git/getCommits.js
@@ -13,7 +13,7 @@ export default async function (projectPath, from, to = "HEAD") {
const delimiter = `<--- ${randomBytes(64).toString("hex")} --->`;
const gitParams = [
"log",
- `--pretty="format:%B%n-hash-%n%H ${delimiter}"`,
+ `--format=%B%n-hash-%n%H%n${delimiter}`,
"--dense",
`${from}..${to}`,
].concat(getOptionalPositionalArgument(projectPath));
5 changes: 4 additions & 1 deletion utils/release/bump-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ const modifyPackageJson = (packageDir, modifyPackageJsonCallback) => {
readFileSync(packageJsonPath, {encoding: 'utf-8'})
);
const newPackageJson = modifyPackageJsonCallback(packageJson);
writeFileSync(packageJsonPath, JSON.stringify(newPackageJson || packageJson));
writeFileSync(
packageJsonPath,
JSON.stringify(newPackageJson || packageJson, null, 2)
);
};

const isPrerelease = process.env.IS_PRERELEASE === 'true';
Expand Down
3 changes: 3 additions & 0 deletions utils/release/reify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function buildDependencyGraph(rootNode) {
if (!node.package.name || !dependency.package.name) {
throw 'Workspaces must all have a name.';
}
if (node.package.name === dependency.package.name) {
continue;
}
graph.addDependency(node.package.name, dependency.package.name);
addWorkspaceDependencies(dependency);
}
Expand Down

0 comments on commit 8156ae8

Please sign in to comment.