From 2f210d448a04a8583671f4fd097954fc193069c3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 6 Mar 2024 11:41:44 -0800 Subject: [PATCH] update release workflow --- .github/workflows/trigger_release.yml | 9 +- scripts/start-release.js | 116 +++----------------------- 2 files changed, 16 insertions(+), 109 deletions(-) diff --git a/.github/workflows/trigger_release.yml b/.github/workflows/trigger_release.yml index 559f62b04675b..106fb4e671a70 100644 --- a/.github/workflows/trigger_release.yml +++ b/.github/workflows/trigger_release.yml @@ -29,7 +29,7 @@ name: Trigger Release env: NAPI_CLI_VERSION: 2.14.7 - TURBO_VERSION: 1.11.3 + TURBO_VERSION: 1.12.2 NODE_LTS_VERSION: 20 jobs: @@ -45,14 +45,15 @@ jobs: environment: release-${{ github.event.inputs.releaseType || 'canary' }} steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 check-latest: true - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 + persist-credentials: false # to allow start-release to override the git credentials - name: Get commit of the latest tag run: echo "LATEST_TAG_COMMIT=$(git rev-list -n 1 $(git describe --tags --abbrev=0))" >> $GITHUB_ENV @@ -77,7 +78,7 @@ jobs: - id: get-store-path run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 timeout-minutes: 5 id: cache-pnpm-store with: diff --git a/scripts/start-release.js b/scripts/start-release.js index 597f161e18746..9f6d1146a1f4d 100644 --- a/scripts/start-release.js +++ b/scripts/start-release.js @@ -1,79 +1,6 @@ const path = require('path') const execa = require('execa') const resolveFrom = require('resolve-from') -const ansiEscapes = require('ansi-escapes') - -function getPromptErrorDetails(rawAssertion, mostRecentChunk) { - const assertion = rawAssertion.toString().trim() - const mostRecent = (mostRecentChunk || '').trim() - return `Waiting for:\n "${assertion}"\nmost recent chunk was:\n "${mostRecent}"` -} - -async function waitForPrompt(cp, rawAssertion, timeout = 120_000) { - let assertion - if (typeof rawAssertion === 'string') { - assertion = (chunk) => chunk.includes(rawAssertion) - } else if (rawAssertion instanceof RegExp) { - assertion = (chunk) => rawAssertion.test(chunk) - } else { - assertion = rawAssertion - } - - return new Promise((resolve, reject) => { - let mostRecentChunk = 'NO CHUNKS SO FAR' - - console.log('Waiting for prompt...') - const handleTimeout = setTimeout(() => { - cleanup() - const promptErrorDetails = getPromptErrorDetails( - rawAssertion, - mostRecentChunk - ) - reject( - new Error( - `Timed out after ${timeout}ms in waitForPrompt. ${promptErrorDetails}` - ) - ) - }, timeout) - - const onComplete = () => { - cleanup() - const promptErrorDetails = getPromptErrorDetails( - rawAssertion, - mostRecentChunk - ) - reject( - new Error( - `Process exited before prompt was found in waitForPrompt. ${promptErrorDetails}` - ) - ) - } - - const onData = (rawChunk) => { - const chunk = rawChunk.toString() - - mostRecentChunk = chunk - console.log('> ' + chunk) - if (assertion(chunk)) { - cleanup() - resolve() - } - } - - const cleanup = () => { - cp.stdout?.off('data', onData) - cp.stderr?.off('data', onData) - cp.off('close', onComplete) - cp.off('exit', onComplete) - clearTimeout(handleTimeout) - } - - cp.stdout?.on('data', onData) - cp.stderr?.on('data', onData) - cp.on('close', onComplete) - cp.on('exit', onComplete) - }) -} const SEMVER_TYPES = ['patch', 'minor', 'major'] @@ -126,41 +53,20 @@ async function main() { }) console.log(`Running pnpm release-${isCanary ? 'canary' : 'stable'}...`) - const child = execa(`pnpm release-${isCanary ? 'canary' : 'stable'}`, { - stdio: 'pipe', - shell: true, - }) + const child = execa( + isCanary + ? `pnpm lerna version ${ + semverType === 'minor' ? 'preminor' : 'prerelease' + } --preid canary --force-publish -y && pnpm release --pre --skip-questions --show-url` + : `pnpm lerna version ${semverType} --force-publish -y`, + { + stdio: 'pipe', + shell: true, + } + ) child.stdout.pipe(process.stdout) child.stderr.pipe(process.stderr) - - if (isCanary) { - console.log("Releasing canary: enter 'y'\n") - child.stdin.write('y\n') - } else { - console.log('Wait for the version prompt to show up') - await waitForPrompt(child, 'Select a new version') - console.log('Releasing stable') - if (semverType === 'minor') { - console.log('Releasing minor: cursor down > 1\n') - child.stdin.write(ansiEscapes.cursorDown(1)) - } - if (semverType === 'major') { - console.log('Releasing major: curser down > 1') - child.stdin.write(ansiEscapes.cursorDown(1)) - console.log('Releasing major: curser down > 2') - child.stdin.write(ansiEscapes.cursorDown(1)) - } - if (semverType === 'patch') { - console.log('Releasing patch: cursor stay\n') - } - console.log('Enter newline') - child.stdin.write('\n') - await waitForPrompt(child, 'Changes:') - console.log('Enter y') - child.stdin.write('y\n') - } - console.log('Await child process...') await child console.log('Release process is finished') }