feat(cli): allow specifying an existing release (#1256)
This commit is contained in:
parent
94e8e54b38
commit
b54e698237
1 changed files with 55 additions and 33 deletions
|
@ -39,6 +39,8 @@ export class PrePublishCommand extends Command {
|
||||||
|
|
||||||
ghReleaseName?: string = Option.String('--gh-release-name')
|
ghReleaseName?: string = Option.String('--gh-release-name')
|
||||||
|
|
||||||
|
existingReleaseId?: string = Option.String('--gh-release-id')
|
||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
const {
|
const {
|
||||||
packageJsonPath,
|
packageJsonPath,
|
||||||
|
@ -62,10 +64,9 @@ export class PrePublishCommand extends Command {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const { owner, repo, pkgInfo, octokit } = await this.createGhRelease(
|
const { owner, repo, pkgInfo, octokit } = this.existingReleaseId
|
||||||
packageName,
|
? await this.getRepoInfo(packageName, version)
|
||||||
version,
|
: await this.createGhRelease(packageName, version)
|
||||||
)
|
|
||||||
|
|
||||||
for (const platformDetail of platforms) {
|
for (const platformDetail of platforms) {
|
||||||
const pkgDir = join(
|
const pkgDir = join(
|
||||||
|
@ -92,17 +93,21 @@ export class PrePublishCommand extends Command {
|
||||||
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
|
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const releaseInfo = await octokit!.repos.getReleaseByTag({
|
const releaseId = this.existingReleaseId
|
||||||
repo: repo,
|
? Number(this.existingReleaseId)
|
||||||
owner: owner,
|
: (
|
||||||
tag: pkgInfo.tag,
|
await octokit!.repos.getReleaseByTag({
|
||||||
})
|
repo: repo,
|
||||||
|
owner: owner,
|
||||||
|
tag: pkgInfo.tag,
|
||||||
|
})
|
||||||
|
).data.id
|
||||||
const dstFileStats = statSync(dstPath)
|
const dstFileStats = statSync(dstPath)
|
||||||
const assetInfo = await octokit!.repos.uploadReleaseAsset({
|
const assetInfo = await octokit!.repos.uploadReleaseAsset({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
name: filename,
|
name: filename,
|
||||||
release_id: releaseInfo.data.id,
|
release_id: releaseId,
|
||||||
mediaType: { format: 'raw' },
|
mediaType: { format: 'raw' },
|
||||||
headers: {
|
headers: {
|
||||||
'content-length': dstFileStats.size,
|
'content-length': dstFileStats.size,
|
||||||
|
@ -140,6 +145,46 @@ export class PrePublishCommand extends Command {
|
||||||
pkgInfo: { name: null, version: null, tag: null },
|
pkgInfo: { name: null, version: null, tag: null },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const { repo, owner, pkgInfo, octokit } = await this.getRepoInfo(
|
||||||
|
packageName,
|
||||||
|
version,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!repo || !owner) {
|
||||||
|
return {
|
||||||
|
owner: null,
|
||||||
|
repo: null,
|
||||||
|
pkgInfo: { name: null, version: null, tag: null },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isDryRun) {
|
||||||
|
try {
|
||||||
|
await octokit.repos.createRelease({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
tag_name: pkgInfo.tag,
|
||||||
|
name: this.ghReleaseName,
|
||||||
|
prerelease:
|
||||||
|
version.includes('alpha') ||
|
||||||
|
version.includes('beta') ||
|
||||||
|
version.includes('rc'),
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
debug(
|
||||||
|
`Params: ${JSON.stringify(
|
||||||
|
{ owner, repo, tag_name: pkgInfo.tag },
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
)}`,
|
||||||
|
)
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { owner, repo, pkgInfo, octokit }
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getRepoInfo(packageName: string, version: string) {
|
||||||
const headCommit = (await spawn('git log -1 --pretty=%B'))
|
const headCommit = (await spawn('git log -1 --pretty=%B'))
|
||||||
.toString('utf8')
|
.toString('utf8')
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -179,29 +224,6 @@ export class PrePublishCommand extends Command {
|
||||||
name: packageName,
|
name: packageName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.isDryRun) {
|
|
||||||
try {
|
|
||||||
await octokit.repos.createRelease({
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
tag_name: pkgInfo.tag,
|
|
||||||
name: this.ghReleaseName,
|
|
||||||
prerelease:
|
|
||||||
version.includes('alpha') ||
|
|
||||||
version.includes('beta') ||
|
|
||||||
version.includes('rc'),
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
debug(
|
|
||||||
`Params: ${JSON.stringify(
|
|
||||||
{ owner, repo, tag_name: pkgInfo.tag },
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
)}`,
|
|
||||||
)
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { owner, repo, pkgInfo, octokit }
|
return { owner, repo, pkgInfo, octokit }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue