From caddabaa318999c849d1c8e8ce62cfbec90feab5 Mon Sep 17 00:00:00 2001 From: Louis Bompart Date: Fri, 27 Oct 2023 03:26:56 -0400 Subject: [PATCH] chore: stabilize --- .github/workflows/release.yml | 98 ++++++-- package-lock.json | 8 +- package.json | 1 + packages/cli/commons/package.json | 1 + packages/cli/core/package.json | 1 + packages/cli/source/package.json | 1 + packages/ui/angular/package.json | 1 + .../package.json | 3 +- .../create-atomic-component/package.json | 3 +- .../package.json | 3 +- packages/ui/atomic/health-check/package.json | 3 +- packages/ui/search-token-server/package.json | 1 + utils/release/create-github-release.mjs | 6 +- utils/release/git-publish-all.mjs | 235 ++++++++++-------- utils/release/is-cli-release.mjs | 16 +- 15 files changed, 230 insertions(+), 151 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5f87ee5259..b127472668 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,7 @@ on: default: false required: false env: + E2E_USE_NPM_REGISTRY: true # Platform environment to log into for the e2e tests. PLATFORM_ENV: 'stg' # Username used to log into the organization whose ID is stored in the ORG_ID variable @@ -74,6 +75,7 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} VERSION: ${{ inputs.version }} + DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} DEBUG: ${{ inputs.debug && '*' || '' }} - name: Prepare artifacts run: | @@ -126,7 +128,7 @@ jobs: cache: 'npm' node-version-file: '.nvmrc' - name: Download artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: npm-release - name: Apply & delete the patch @@ -147,15 +149,17 @@ jobs: - name: Find modified Snapshots id: snapshots-path run: | - EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - echo "snapshotsPath<<$EOF" >> "$GITHUB_ENV" - git diff --name-only *.yml >> "$GITHUB_ENV" - echo "$EOF" >> "$GITHUB_ENV" + { + echo 'snapshotsPath<> "$GITHUB_OUTPUT" - name: Upload Jest Snapshots + if: ${{ steps.snapshots-path.outputs.snapshotsPath != ''}} uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 with: name: release-e2e-snaps - path: ${{ env.snapshotsPath }} + path: ${{ steps.snapshots-path.outputs.snapshotsPath }} e2e-teardown: name: End-to-end teardown if: ${{ always() }} @@ -177,8 +181,49 @@ jobs: - uses: ./.github/actions/e2e-clean with: cliConfigJson: ${{ env.CLI_CONFIG_JSON }} - release-git: + unit-tests: + name: Unit Tests + runs-on: 'ubuntu-20.04' needs: [release-npm] + steps: + - name: Setup runner + # Ensure we can use as many file watcher as we want. see https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/troubleshooting.md#npm-start-fail-due-to-watch-error + run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3 + - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3 + with: + cache: 'npm' + node-version-file: '.nvmrc' + - name: Download artifacts + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 + with: + name: npm-release + - name: Apply & delete the patch + run: | + git apply release.patch + rm release.patch + - name: Setup repo + run: npm ci + - name: Build + run: npm run build + - name: Tests + run: npm run test:ci:snap + - name: Find modified Snapshots + id: snapshots-path + run: | + { + echo 'snapshotsPath<> "$GITHUB_OUTPUT" + - name: Upload Jest Snapshots + if: ${{ steps.snapshots-path.outputs.snapshotsPath != ''}} + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + with: + name: release-e2e-snaps + path: ${{ steps.snapshots-path.outputs.snapshotsPath }} + release-git: + needs: [e2e, release-npm, unit-tests] environment: 'Release' runs-on: ubuntu-20.04 env: @@ -194,7 +239,7 @@ jobs: cache: 'npm' node-version-file: '.nvmrc' - name: Download NPM artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: npm-release - name: Apply & delete the patch @@ -202,7 +247,7 @@ jobs: git apply release.patch rm release.patch - name: Download E2E artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: release-e2e-snaps - name: Install dependencies @@ -263,7 +308,7 @@ jobs: cache: 'npm' node-version-file: '.nvmrc' - name: Download artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: npm-release - name: Apply & delete the patch @@ -274,8 +319,10 @@ jobs: run: npm ci - name: Get CLI version run: | - echo "cliVersion=" >> "$GITHUB_ENV" - cat packages/cli/core/package.json | jq '.version' >> "$GITHUB_ENV" + { + printf "CLI_VERSION=" + cat packages/cli/core/package.json | jq -r '.version' + } >> "$GITHUB_ENV" - name: Build run: npm run build - name: Setup Temporary Keychain @@ -311,19 +358,19 @@ jobs: New-Item -Force -ItemType directory -Path tmp echo "${{ secrets.COVEO_PFX }}" > ./tmp/cert.txt certutil -decode ./tmp/cert.txt ./tmp/cert.pfx - Start-Process -FilePath "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe" -ArgumentList "sign /f ./tmp/cert.pfx /p ${{ secrets.COVEO_PFX_PWD }} /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 ./dist/win32/coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64.exe" -PassThru | Wait-Process - Start-Process -FilePath "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe" -ArgumentList "sign /f ./tmp/cert.pfx /p ${{ secrets.COVEO_PFX_PWD }} /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 ./dist/win32/coveo-${{env.cliversion}}-${{env.commitSHA1}}-x86.exe" -PassThru | Wait-Process + Start-Process -FilePath "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe" -ArgumentList "sign /f ./tmp/cert.pfx /p ${{ secrets.COVEO_PFX_PWD }} /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 ./dist/win32/coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64.exe" -PassThru | Wait-Process + Start-Process -FilePath "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe" -ArgumentList "sign /f ./tmp/cert.pfx /p ${{ secrets.COVEO_PFX_PWD }} /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 ./dist/win32/coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x86.exe" -PassThru | Wait-Process - name: Sign Executable (macOS) working-directory: ./packages/cli/core/dist/macos if: ${{matrix.os == 'macos-latest'}} run: | echo "Signing for ARM64 architecture" security unlock-keychain -p "$MACOS_KEYCHAIN_PWD" build.keychain - productsign --sign $MACOS_WWDR_TEAM_ID coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64.pkg coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64-signed.pkg --keychain build.keychain + productsign --sign $MACOS_WWDR_TEAM_ID coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64.pkg coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64-signed.pkg --keychain build.keychain echo "Signing for X64 architecture" security unlock-keychain -p "$MACOS_KEYCHAIN_PWD" build.keychain - productsign --sign $MACOS_WWDR_TEAM_ID coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64.pkg coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64-signed.pkg --keychain build.keychain + productsign --sign $MACOS_WWDR_TEAM_ID coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64.pkg coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64-signed.pkg --keychain build.keychain - name: Notarize Executable (macOS) working-directory: ./packages/cli/core/dist/macos if: ${{matrix.os == 'macos-latest'}} @@ -335,20 +382,20 @@ jobs: xcrun notarytool store-credentials "notarytool-profile" --apple-id "${{ secrets.MACOS_APP_USERNAME }}" --team-id "${{ secrets.MACOS_WWDR_TEAM_ID }}" --password "${{ secrets.MACOS_APP_SPECIFIC_PWD }}" echo "Creating temp notarization archive" - ditto -c -k --keepParent "coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64-signed.pkg" "notarization-arm64.zip" - ditto -c -k --keepParent "coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64-signed.pkg" "notarization-x64.zip" + ditto -c -k --keepParent "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64-signed.pkg" "notarization-arm64.zip" + ditto -c -k --keepParent "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64-signed.pkg" "notarization-x64.zip" echo "Notarizing app" xcrun notarytool submit "notarization-arm64.zip" --keychain-profile "notarytool-profile" --wait xcrun notarytool submit "notarization-x64.zip" --keychain-profile "notarytool-profile" --wait echo "Attaching staple" - xcrun stapler staple "coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64-signed.pkg" - xcrun stapler staple "coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64-signed.pkg" + xcrun stapler staple "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64-signed.pkg" + xcrun stapler staple "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64-signed.pkg" echo "Deleting unsigned packages" - mv "coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64-signed.pkg" "coveo-${{env.cliversion}}-${{env.commitSHA1}}-x64.pkg" - mv "coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64-signed.pkg" "coveo-${{env.cliversion}}-${{env.commitSHA1}}-arm64.pkg" + mv "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64-signed.pkg" "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-x64.pkg" + mv "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64-signed.pkg" "coveo-v${{env.CLI_VERSION}}-${{env.commitSHA1}}-arm64.pkg" rm notarization-arm64.zip notarization-x64.zip - name: Upload binaries uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 @@ -373,13 +420,14 @@ jobs: cache: 'npm' node-version-file: '.nvmrc' - name: Download NPM artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: npm-release - name: Download binaries artifacts - uses: actions/download-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 with: name: release-binaries + path: release-binaries - name: Apply & delete the patch run: | git apply release.patch @@ -401,6 +449,6 @@ jobs: uses: svenstaro/upload-release-action@7319e4733ec7a184d739a6f412c40ffc339b69c7 # 2.5.0 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ./packages/cli/core/dist/**/* + file: ./release-binaries/**/* file_glob: true tag: ${{ env.tag }} diff --git a/package-lock.json b/package-lock.json index b6345d1999..83a30a4e08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30752,7 +30752,7 @@ "typescript": "4.9.5" }, "engines": { - "node": "^16.13.0 || ^18.12.0" + "node": "^18.18.1 || ^20.9.0" }, "peerDependencies": { "create-react-app": "*" @@ -30803,7 +30803,7 @@ "undici": "5.22.0" }, "engines": { - "node": "^16.13.0 || ^18.12.0" + "node": "^18.18.1 || ^20.9.0" } }, "packages/ui/angular": { @@ -31268,7 +31268,7 @@ "typescript": "4.9.5" }, "engines": { - "node": "^16.13.0 || ^18.12.0" + "node": "^18.18.1 || ^20.9.0" } }, "packages/ui/search-token-server": { @@ -31409,6 +31409,8 @@ "bin": { "git-lock": "git-lock.mjs", "git-publish-all": "git-publish-all.mjs", + "github-publish": "create-github-release.mjs", + "is-cli-release": "is-cli-release.mjs", "npm-publish": "npm-publish-package.mjs" }, "devDependencies": { diff --git a/package.json b/package.json index cb57fb5f1f..5fb3f97ed4 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "clean": "rimraf package-lock.json node_modules", "build": "nx run-many --target=build --all", "test": "nx run-many --target=test --all", + "test:ci:snap": "nx run-many --target=test:ci:snap --all", "lint": "nx run-many --target=lint --all && prettier --ignore-path .ci.prettierignore --check . && eslint .", "commit": "git-cz", "pr:report": "node ./scripts/pr-bot.js", diff --git a/packages/cli/commons/package.json b/packages/cli/commons/package.json index 52f8b1de3c..709787404b 100644 --- a/packages/cli/commons/package.json +++ b/packages/cli/commons/package.json @@ -40,6 +40,7 @@ }, "scripts": { "test": "jest", + "test:ci:snap": "jest -u", "build": "tsc -b tsconfig.build.json", "prepublishOnly": "npm run build", "release:phase1": "npx -p=@coveord/release npm-publish" diff --git a/packages/cli/core/package.json b/packages/cli/core/package.json index b206eafa71..30524f7d2c 100644 --- a/packages/cli/core/package.json +++ b/packages/cli/core/package.json @@ -174,6 +174,7 @@ "scripts": { "build": "rimraf lib && tsc -b tsconfig.build.json", "test": "jest --colors", + "test:ci:snap": "jest --colors -u", "lint": "prettier --check . && eslint .", "release:phase1": "npx -p=@coveord/release npm-publish", "postpack": "rimraf oclif.manifest.json", diff --git a/packages/cli/source/package.json b/packages/cli/source/package.json index 0c421cd602..97e9a9ff7f 100644 --- a/packages/cli/source/package.json +++ b/packages/cli/source/package.json @@ -68,6 +68,7 @@ "scripts": { "build": "tsc -b tsconfig.build.json", "test": "jest --colors", + "test:ci:snap": "jest --colors -u", "lint": "prettier --config .prettierrc.js --check . && eslint .", "release:phase1": "npx -p=@coveord/release npm-publish", "postpack": "rimraf oclif.manifest.json", diff --git a/packages/ui/angular/package.json b/packages/ui/angular/package.json index c2ec896f86..f0753640e6 100644 --- a/packages/ui/angular/package.json +++ b/packages/ui/angular/package.json @@ -4,6 +4,7 @@ "description": "Coveo schematic for angular", "scripts": { "test": "jest", + "test:ci:snap": "jest -u", "lint": "prettier --check . && eslint .", "build": "tsc -p tsconfig.json", "prebuild": "node ./scripts/clean.js", diff --git a/packages/ui/atomic/create-atomic-component-project/package.json b/packages/ui/atomic/create-atomic-component-project/package.json index 647afb7233..8539bf6c8b 100644 --- a/packages/ui/atomic/create-atomic-component-project/package.json +++ b/packages/ui/atomic/create-atomic-component-project/package.json @@ -13,7 +13,8 @@ ], "scripts": { "release:phase1": "npx -p=@coveord/release npm-publish", - "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js" + "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js", + "test:ci:snap": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js -u" }, "keywords": [ "coveo", diff --git a/packages/ui/atomic/create-atomic-component/package.json b/packages/ui/atomic/create-atomic-component/package.json index 83d22e217b..c2dbbcc7e0 100644 --- a/packages/ui/atomic/create-atomic-component/package.json +++ b/packages/ui/atomic/create-atomic-component/package.json @@ -13,7 +13,8 @@ ], "scripts": { "release:phase1": "npx -p=@coveord/release npm-publish", - "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js" + "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js", + "test:ci:snap": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js -u" }, "keywords": [ "coveo", diff --git a/packages/ui/atomic/create-atomic-result-component/package.json b/packages/ui/atomic/create-atomic-result-component/package.json index 758b45b9c4..af7c830d9b 100644 --- a/packages/ui/atomic/create-atomic-result-component/package.json +++ b/packages/ui/atomic/create-atomic-result-component/package.json @@ -13,7 +13,8 @@ ], "scripts": { "release:phase1": "npx -p=@coveord/release npm-publish", - "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js" + "test": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js", + "test:ci:snap": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js -u" }, "keywords": [ "coveo", diff --git a/packages/ui/atomic/health-check/package.json b/packages/ui/atomic/health-check/package.json index e233629ec7..723920acf8 100644 --- a/packages/ui/atomic/health-check/package.json +++ b/packages/ui/atomic/health-check/package.json @@ -20,7 +20,8 @@ "pretest": "rimraf dist && tsc -b tsconfig.json", "test:unit": "jest --testPathIgnorePatterns=e2e", "test:e2e": "node --experimental-vm-modules --no-warnings ../../../../node_modules/jest/bin/jest.js --testPathPattern=e2e", - "test": "npm run test:unit && npm run test:e2e" + "test": "npm run test:unit && npm run test:e2e", + "test:ci:snap": "npm run test:unit -- -u && npm run test:e2e -- -u" }, "repository": { "type": "git", diff --git a/packages/ui/search-token-server/package.json b/packages/ui/search-token-server/package.json index c366d80d39..c12bdc1ed4 100644 --- a/packages/ui/search-token-server/package.json +++ b/packages/ui/search-token-server/package.json @@ -25,6 +25,7 @@ "scripts": { "start": "ts-node server.ts", "test": "jest", + "test:ci:snap": "jest -u", "release:phase1": "npx -p=@coveord/release npm-publish" }, "devDependencies": { diff --git a/utils/release/create-github-release.mjs b/utils/release/create-github-release.mjs index 31679496c5..d032042eb0 100644 --- a/utils/release/create-github-release.mjs +++ b/utils/release/create-github-release.mjs @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import {readFileSync} from 'node:fs'; import {Octokit} from 'octokit'; import {createAppAuth} from '@octokit/auth-app'; @@ -15,7 +17,7 @@ const getCliChangelog = () => { const lastVersionChanges = changelog.split(versionH1Matcher)[1]; return lastVersionChanges.trim(); }; -async () => { +(async () => { //#region GitHub authentication const authSecrets = { appId: process.env.RELEASER_APP_ID, @@ -51,4 +53,4 @@ async () => { body: releaseBody, }); exportVariable('tag', cliLatestTag); -}; +})(); diff --git a/utils/release/git-publish-all.mjs b/utils/release/git-publish-all.mjs index 6ac6d58fec..0487622894 100755 --- a/utils/release/git-publish-all.mjs +++ b/utils/release/git-publish-all.mjs @@ -22,6 +22,8 @@ import { gitPublishBranch, gitSetRefOnCommit, gitPush, + gitSetupSshRemote, + gitSetupUser, } from '@coveo/semantic-monorepo-tools'; import {Octokit} from 'octokit'; import {createAppAuth} from '@octokit/auth-app'; @@ -31,97 +33,49 @@ import {dedent} from 'ts-dedent'; import {readFileSync, writeFileSync} from 'fs'; import {removeWriteAccessRestrictions} from './lock-master.mjs'; import {spawnSync} from 'child_process'; -const REPO_OWNER = 'coveo'; -const REPO_NAME = 'cli'; -const GIT_SSH_REMOTE = 'deploy'; -// Commit, tag and push -(async () => { - const PATH = '.'; - - //#region GitHub authentication - const authSecrets = { - appId: process.env.RELEASER_APP_ID, - privateKey: process.env.RELEASER_PRIVATE_KEY, - clientId: process.env.RELEASER_CLIENT_ID, - clientSecret: process.env.RELEASER_CLIENT_SECRET, - installationId: process.env.RELEASER_INSTALLATION_ID, - }; - - const octokit = new Octokit({ - authStrategy: createAppAuth, - auth: authSecrets, - }); - //#endregion - - // Define release # andversion - const currentVersionTag = getCurrentVersion(PATH); - currentVersionTag.inc('prerelease'); - const npmNewVersion = currentVersionTag.format(); - // Write release version in the root package.json - await npmBumpVersion(npmNewVersion, PATH); - - const releaseNumber = currentVersionTag.prerelease[0]; - const gitNewTag = `release-${releaseNumber}`; - - // Find all changes since last release and generate the changelog. - const versionPrefix = 'release-'; - const lastTag = await getLastTag(versionPrefix); - const commits = await getCommits(PATH, lastTag); - const convention = await angularChangelogConvention; - - let changelog = ''; - if (commits.length > 0) { - const parsedCommits = parseCommits(commits, convention.parserOpts); - changelog = await generateChangelog( - parsedCommits, - gitNewTag, - { - host: 'https://github.com', - owner: REPO_OWNER, - repository: REPO_NAME, - }, - convention.writerOpts - ); - await writeChangelog(PATH, changelog); +const setupGit = async () => { + const GIT_USERNAME = 'developer-experience-bot[bot]'; + const GIT_EMAIL = + '91079284+developer-experience-bot[bot]@users.noreply.github.com'; + const DEPLOY_KEY = process.env.DEPLOY_KEY; + if (DEPLOY_KEY === undefined) { + throw new Error('Deploy key is undefined'); } - updateRootReadme(); - - // Find all packages that have been released in this release. - const packagesReleased = readFileSync('.git-message', { - encoding: 'utf-8', - }).trim(); - // Compile git commit message - const commitMessage = dedent` - [version bump] chore(release): release ${gitNewTag} [skip ci] - - ${packagesReleased} + await gitSetupUser(GIT_USERNAME, GIT_EMAIL); + await gitSetupSshRemote(REPO_OWNER, REPO_NAME, DEPLOY_KEY, GIT_SSH_REMOTE); +}; - **/README.md - **/CHANGELOG.md - **/package.json - README.md - CHANGELOG.md - package.json - package-lock.json - packages/ui/cra-template/template.json - `; - - // Craft the commit (complex process, see function) - const commit = await commitChanges(releaseNumber, commitMessage, octokit); - - // Add the tags locally... - for (const tag of packagesReleased.split('\n').concat(gitNewTag)) { - await gitTag(tag, commit); +/** + * Update usage section at the root readme. + */ +function updateRootReadme() { + const usageRegExp = /^(.|\n)*$/m; + const cliReadme = readFileSync('packages/cli/core/README.md', 'utf-8'); + let rootReadme = readFileSync('README.md', 'utf-8'); + const cliUsage = usageRegExp.exec(cliReadme)?.[0]; + if (!cliUsage) { + return; } - // And push them - await gitPushTags(); + writeFileSync('README.md', rootReadme.replace(usageRegExp, cliUsage)); +} - // Unlock the main branch - await removeWriteAccessRestrictions(); -})(); +/** + * Append `.cmd` to the input if the runtime OS is Windows. + * @param {string|TemplateStringsArray} cmd + * @returns + */ +const appendCmdIfWindows = (cmd) => + `${cmd}${process.platform === 'win32' ? '.cmd' : ''}`; + +/** + * Run `npm run pre-commit` + */ +function runPrecommit() { + spawnSync(appendCmdIfWindows`npm`, ['run', 'pre-commit']); +} /** * "Craft" the signed release commit. @@ -182,32 +136,95 @@ async function commitChanges(releaseNumber, commitMessage, octokit) { return commit.data.sha; } -/** - * Update usage section at the root readme. - */ -function updateRootReadme() { - const usageRegExp = /^(.|\n)*$/m; - const cliReadme = readFileSync('packages/cli/core/README.md', 'utf-8'); - let rootReadme = readFileSync('README.md', 'utf-8'); - const cliUsage = usageRegExp.exec(cliReadme)?.[0]; - if (!cliUsage) { - return; - } - rootReadme.replace(usageRegExp, cliUsage); - writeFileSync('README.md', rootReadme); +const REPO_OWNER = 'coveo'; +const REPO_NAME = 'cli'; +const GIT_SSH_REMOTE = 'deploy'; + +// Commit, tag and push +const PATH = '.'; + +//#region GitHub authentication +const authSecrets = { + appId: process.env.RELEASER_APP_ID, + privateKey: process.env.RELEASER_PRIVATE_KEY, + clientId: process.env.RELEASER_CLIENT_ID, + clientSecret: process.env.RELEASER_CLIENT_SECRET, + installationId: process.env.RELEASER_INSTALLATION_ID, +}; + +const octokit = new Octokit({ + authStrategy: createAppAuth, + auth: authSecrets, +}); +//#endregion + +await setupGit(); + +// Define release # andversion +const currentVersionTag = getCurrentVersion(PATH); +currentVersionTag.inc('prerelease'); +const npmNewVersion = currentVersionTag.format(); +// Write release version in the root package.json +await npmBumpVersion(npmNewVersion, PATH); + +const releaseNumber = currentVersionTag.prerelease[0]; +const gitNewTag = `release-${releaseNumber}`; + +// Find all changes since last release and generate the changelog. +const versionPrefix = 'release-'; +const lastTag = await getLastTag(versionPrefix); +const commits = await getCommits(PATH, lastTag); +const convention = await angularChangelogConvention; + +let changelog = ''; +if (commits.length > 0) { + const parsedCommits = parseCommits(commits, convention.parserOpts); + changelog = await generateChangelog( + parsedCommits, + gitNewTag, + { + host: 'https://github.com', + owner: REPO_OWNER, + repository: REPO_NAME, + }, + convention.writerOpts + ); + await writeChangelog(PATH, changelog); } +updateRootReadme(); -/** - * Run `npm run pre-commit` - */ -function runPrecommit() { - spawnSync(appendCmdIfWindows`npm`, ['run', 'pre-commit']); +// Find all packages that have been released in this release. +const packagesReleased = readFileSync('.git-message', { + encoding: 'utf-8', +}).trim(); + +// Compile git commit message +const commitMessage = dedent` + [version bump] chore(release): release ${gitNewTag} [skip ci] + + ${packagesReleased} + + **/README.md + **/CHANGELOG.md + **/package.json + **/*.snap + README.md + CHANGELOG.md + package.json + package-lock.json + packages/ui/cra-template/template.json + `; + +// Craft the commit (complex process, see function) +const commit = await commitChanges(releaseNumber, commitMessage, octokit); + +// Add the tags locally... +for (const tag of packagesReleased.split('\n').concat(gitNewTag)) { + await gitTag(tag, commit); } -/** - * Append `.cmd` to the input if the runtime OS is Windows. - * @param {string|TemplateStringsArray} cmd - * @returns - */ -const appendCmdIfWindows = (cmd) => - `${cmd}${process.platform === 'win32' ? '.cmd' : ''}`; +// And push them +await gitPushTags(); + +// Unlock the main branch +await removeWriteAccessRestrictions(); diff --git a/utils/release/is-cli-release.mjs b/utils/release/is-cli-release.mjs index b4acb59c51..294be9cd9a 100644 --- a/utils/release/is-cli-release.mjs +++ b/utils/release/is-cli-release.mjs @@ -1,13 +1,13 @@ +#!/usr/bin/env node + import {readFileSync} from 'node:fs'; import {setOutput} from '@actions/core'; const CLI_PKG_MATCHER = /^@coveo\/cli@(?\d+\.\d+\.\d+)$/gm; -async () => { - const packagesReleased = readFileSync('.git-message', { - encoding: 'utf-8', - }).trim(); +const packagesReleased = readFileSync('.git-message', { + encoding: 'utf-8', +}).trim(); - // If `@coveo/cli` has not been released we should not build it etc. - const shouldReleaseCli = CLI_PKG_MATCHER.test(packagesReleased); - setOutput('shouldReleaseCli', shouldReleaseCli); -}; +// If `@coveo/cli` has not been released we should not build it etc. +const shouldReleaseCli = CLI_PKG_MATCHER.test(packagesReleased); +setOutput('shouldReleaseCli', shouldReleaseCli);