Commit 2f210d44 authored by JJ Kasper's avatar JJ Kasper

update release workflow

parent f564deef
...@@ -29,7 +29,7 @@ name: Trigger Release ...@@ -29,7 +29,7 @@ name: Trigger Release
env: env:
NAPI_CLI_VERSION: 2.14.7 NAPI_CLI_VERSION: 2.14.7
TURBO_VERSION: 1.11.3 TURBO_VERSION: 1.12.2
NODE_LTS_VERSION: 20 NODE_LTS_VERSION: 20
jobs: jobs:
...@@ -45,14 +45,15 @@ jobs: ...@@ -45,14 +45,15 @@ jobs:
environment: release-${{ github.event.inputs.releaseType || 'canary' }} environment: release-${{ github.event.inputs.releaseType || 'canary' }}
steps: steps:
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 18 node-version: 18
check-latest: true check-latest: true
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
fetch-depth: 25 fetch-depth: 25
persist-credentials: false # to allow start-release to override the git credentials
- name: Get commit of the latest tag - name: Get commit of the latest tag
run: echo "LATEST_TAG_COMMIT=$(git rev-list -n 1 $(git describe --tags --abbrev=0))" >> $GITHUB_ENV run: echo "LATEST_TAG_COMMIT=$(git rev-list -n 1 $(git describe --tags --abbrev=0))" >> $GITHUB_ENV
...@@ -77,7 +78,7 @@ jobs: ...@@ -77,7 +78,7 @@ jobs:
- id: get-store-path - id: get-store-path
run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT
- uses: actions/cache@v3 - uses: actions/cache@v4
timeout-minutes: 5 timeout-minutes: 5
id: cache-pnpm-store id: cache-pnpm-store
with: with:
......
const path = require('path') const path = require('path')
const execa = require('execa') const execa = require('execa')
const resolveFrom = require('resolve-from') 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'] const SEMVER_TYPES = ['patch', 'minor', 'major']
...@@ -126,41 +53,20 @@ async function main() { ...@@ -126,41 +53,20 @@ async function main() {
}) })
console.log(`Running pnpm release-${isCanary ? 'canary' : 'stable'}...`) console.log(`Running pnpm release-${isCanary ? 'canary' : 'stable'}...`)
const child = execa(`pnpm release-${isCanary ? 'canary' : 'stable'}`, { const child = execa(
stdio: 'pipe', isCanary
shell: true, ? `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.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr) 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 await child
console.log('Release process is finished') console.log('Release process is finished')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment