1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 04:04:58 +03:00

feat: trigger GitHub workflows script done

This commit is contained in:
louistiti 2022-10-09 21:16:42 +08:00
parent 3fe89bfda3
commit 4fcf8dceda
2 changed files with 69 additions and 0 deletions

View File

@ -55,6 +55,8 @@
"start": "cross-env LEON_NODE_ENV=production node ./server/dist/index.js",
"train": "ts-node scripts/train/run-train.js",
"prepare-release": "ts-node scripts/release/prepare-release.js",
"release:python-bridge": "ts-node scripts/release/release-binaries.js python-bridge",
"release:tcp-server": "ts-node scripts/release/release-binaries.js tcp-server",
"check": "ts-node scripts/run-check.js",
"docker:build": "docker build -t leon-ai/leon .",
"docker:run": "docker compose up",

View File

@ -0,0 +1,67 @@
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'
/**
* Release binaries via GitHub Actions
* 1. Ask for confirmation whether the binary version has been bumped
* 2. Trigger GitHub workflow to release binaries
*/
const BUILD_TARGETS = new Map()
const WORKFLOWS_PATH = path.join('.github', 'workflows')
BUILD_TARGETS.set('python-bridge', {
workflowFileName: 'build-python-bridge.yml',
setupFilePath: path.join(PYTHON_BRIDGE_SRC_PATH, 'setup.py')
})
BUILD_TARGETS.set('tcp-server', {
workflowFileName: 'build-tcp-server.yml',
setupFilePath: path.join(TCP_SERVER_SRC_PATH, 'setup.py')
})
;(async () => {
LoaderHelper.start()
const { argv } = process
const givenReleaseTarget = argv[2].toLowerCase()
const { workflowFileName, setupFilePath } =
BUILD_TARGETS.get(givenReleaseTarget)
const workflowFilePath = path.join(WORKFLOWS_PATH, workflowFileName)
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...')
await command(`gh workflow run ${workflowFilePath}`, {
shell: true,
stdout: 'inherit'
})
LogHelper.success('GitHub workflow triggered. The release is on its way!')
} catch (e) {
LogHelper.error(
`An error occurred while triggering the GitHub workflow: ${e}`
)
process.exit(1)
}
})()