Skip to content

Commit

Permalink
Create GitHub release in single pass
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Blagoev <[email protected]>
  • Loading branch information
nblagoev committed May 2, 2019
1 parent e418dea commit 4da7982
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ const { ReleaseNotes } = require("pull-release-notes")
const REPO_OWNER = "vmware"
const REPO_NAME = "vrealize-developer-tools"

function createRelease(releaseVersion) {
function createRelease(releaseVersion, releaseSha, notes) {
log.info(`Creating GitHub release v${releaseVersion}`)
const stream = gulp.src("./*.vsix").pipe(
publishRelease({
token: process.env.GITHUB_SECRET,
owner: REPO_OWNER,
repo: REPO_NAME,
name: releaseVersion,
notes: "Pending changelog",
notes: `## Notable changes\n${notes}`,
tag: `v${releaseVersion}`,
target_commitish: releaseSha,
draft: true,
reuseDraftOnly: true,
skipIfPublished: true
Expand All @@ -43,23 +44,6 @@ function getReleaseNotes(fromTag, toSha) {
return releaseNotes.pull(process.env.GITHUB_SECRET)
}

function updateRelease(releaseVersion, notes) {
log.info(`Updating GitHub release v${releaseVersion} with release notes`)
const stream = publishRelease({
token: process.env.GITHUB_SECRET,
owner: REPO_OWNER,
repo: REPO_NAME,
name: releaseVersion,
notes: notes,
tag: `v${releaseVersion}`,
draft: false,
reuseDraftOnly: true,
skipIfPublished: true
})

return toPromise(stream)
}

function toPromise(stream) {
return new Promise(function(resolve, reject) {
stream.on("finish", resolve).on("error", reject)
Expand All @@ -84,9 +68,8 @@ module.exports = function() {
const releaseSha = process.env.RELEASE_COMMIT_SHA

return Promise.resolve()
.then(() => createRelease(releaseVersion))
.then(() => getReleaseNotes(currentVersion, releaseSha))
.then(notes => updateRelease(releaseVersion, notes))
.then(notes => createRelease(releaseVersion, releaseSha, notes))
.catch(error => {
log.error(error)
throw new Error("Could not release in GitHub")
Expand Down

0 comments on commit 4da7982

Please sign in to comment.