1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-24 09:12:20 +03:00
leon/scripts/release/pre-release-binaries.js
2022-10-09 23:58:59 +08:00

78 lines
2.1 KiB
JavaScript

import path from 'node:path'
import { prompt } from 'inquirer'
import { command } from 'execa'
import { PYTHON_BRIDGE_SRC_PATH, TCP_SERVER_SRC_PATH } from '@/constants'
import { LogHelper } from '@/helpers/log-helper'
import { LoaderHelper } from '@/helpers/loader-helper'
/**
* Pre-release binaries via GitHub Actions
* 1. Ask for confirmation whether the binary version has been bumped
* 2. Trigger GitHub workflow to pre-release binaries
*/
const BUILD_TARGETS = new Map()
BUILD_TARGETS.set('python-bridge', {
workflowFileName: 'pre-release-python-bridge.yml',
setupFilePath: path.join(PYTHON_BRIDGE_SRC_PATH, 'setup.py')
})
BUILD_TARGETS.set('tcp-server', {
workflowFileName: 'pre-release-tcp-server.yml',
setupFilePath: path.join(TCP_SERVER_SRC_PATH, 'setup.py')
})
;(async () => {
LoaderHelper.start()
const { argv } = process
const givenReleaseTarget = argv[2].toLowerCase()
const givenBranch = argv[3]?.toLowerCase()
const { workflowFileName, setupFilePath } =
BUILD_TARGETS.get(givenReleaseTarget)
LoaderHelper.stop()
const answer = await prompt({
type: 'confirm',
name: 'binary.bumped',
message: `Have you bumped the version number of the binary from the "${setupFilePath}" file?`,
default: false
})
LoaderHelper.start()
if (!answer.binary.bumped) {
LogHelper.info(
'Please bump the version number of the binary from the setup file before continuing'
)
process.exit(0)
}
try {
LogHelper.info('Triggering the GitHub workflow...')
const runWorkflowCommand = !givenBranch
? `gh workflow run ${workflowFileName}`
: `gh workflow run ${workflowFileName} --ref ${givenBranch}`
await command(runWorkflowCommand, {
shell: true,
stdout: 'inherit'
})
LogHelper.success(
'GitHub workflow triggered. The pre-release is on its way!'
)
LogHelper.success(
'Once the pre-release is done, go to the GitHub releases to double-check information and hit release'
)
process.exit(0)
} catch (e) {
LogHelper.error(
`An error occurred while triggering the GitHub workflow: ${e}`
)
process.exit(1)
}
})()