Skip to content

Commit

Permalink
update release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Mar 6, 2024
1 parent f564dee commit 2f210d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 109 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/trigger_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
116 changes: 11 additions & 105 deletions scripts/start-release.js
Original file line number Diff line number Diff line change
@@ -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']

Expand Down Expand Up @@ -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')
}
Expand Down

0 comments on commit 2f210d4

Please sign in to comment.