2022-06-08 13:47:13 +00:00
|
|
|
/// <reference path="../globals.d.ts" />
|
|
|
|
|
|
|
|
import appPackage from '../../app/package.json'
|
|
|
|
import { createPR } from '../pr-api'
|
2022-06-14 16:37:34 +00:00
|
|
|
import { sh } from '../sh'
|
|
|
|
|
|
|
|
async function getPullRequestContent(
|
|
|
|
contentType: 'title' | 'body',
|
|
|
|
fullVersion: string
|
|
|
|
): Promise<string> {
|
|
|
|
const result = await sh(
|
|
|
|
'./script/draft-release/release-pr-content.sh',
|
|
|
|
contentType,
|
|
|
|
fullVersion
|
|
|
|
)
|
|
|
|
return result.trim()
|
2022-06-08 13:47:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 16:37:34 +00:00
|
|
|
const getPullRequestBody = (fullVersion: string) =>
|
|
|
|
getPullRequestContent('body', fullVersion)
|
|
|
|
const getPullRequestTitle = (fullVersion: string) =>
|
|
|
|
getPullRequestContent('title', fullVersion)
|
2022-06-08 13:47:13 +00:00
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
console.error(error.message)
|
|
|
|
})
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
const version = appPackage.version
|
2022-06-14 16:37:34 +00:00
|
|
|
if (version.includes('test')) {
|
|
|
|
console.error('Cannot create a PR for a test version')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2022-06-08 13:47:13 +00:00
|
|
|
console.log(`Creating release Pull Request for ${version}...`)
|
2022-06-14 16:37:34 +00:00
|
|
|
const title = await getPullRequestTitle(version)
|
|
|
|
const body = await getPullRequestBody(version)
|
2022-06-08 13:47:13 +00:00
|
|
|
const response = await createPR(title, body, `releases/${version}`)
|
|
|
|
if (response === null) {
|
|
|
|
console.error('Failed to create release Pull Request')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
console.log(`Done: ${response.permalink}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|