diff --git a/bin/plugin/commands/release.js b/bin/plugin/commands/release.js index 974d5fc105f95e..56a232d13882c4 100644 --- a/bin/plugin/commands/release.js +++ b/bin/plugin/commands/release.js @@ -392,52 +392,60 @@ async function runGithubReleaseStep( abortMessage ) { let octokit; + let releaseDraft; let release; - await runStep( 'Creating the GitHub release', abortMessage, async () => { - await askForConfirmation( - 'Proceed with the creation of the GitHub release?', - true, - abortMessage - ); - - const { token } = await inquirer.prompt( [ - { - type: 'input', - name: 'token', - message: - 'Please enter a GitHub personal authentication token.\n' + - 'You can create one by navigating to ' + - formats.success( - 'https://github.com/settings/tokens/new?scopes=repo,admin:org,write:packages' - ) + - '.\nToken:', - }, - ] ); - - octokit = new Octokit( { - auth: token, - } ); - const releaseData = await octokit.repos.createRelease( { - owner: config.githubRepositoryOwner, - repo: config.githubRepositoryName, - tag_name: 'v' + version, - name: versionLabel, - body: changelog, - prerelease: isPrerelease, - } ); - release = releaseData.data; + await runStep( + 'Creating the GitHub release draft', + abortMessage, + async () => { + await askForConfirmation( + 'Proceed with the creation of the GitHub release draft?', + true, + abortMessage + ); - log( '>> The GitHub release has been created.' ); - } ); + const { token } = await inquirer.prompt( [ + { + type: 'input', + name: 'token', + message: + 'Please enter a GitHub personal authentication token.\n' + + 'You can create one by navigating to ' + + formats.success( + 'https://github.com/settings/tokens/new?scopes=repo,admin:org,write:packages' + ) + + '.\nToken:', + }, + ] ); + + octokit = new Octokit( { + auth: token, + } ); + + const releaseDraftData = await octokit.repos.createRelease( { + owner: config.githubRepositoryOwner, + repo: config.githubRepositoryName, + tag_name: 'v' + version, + name: versionLabel, + body: changelog, + prerelease: isPrerelease, + draft: true, + } ); + releaseDraft = releaseDraftData.data; + + log( '>> The GitHub release draft has been created.' ); + } + ); abortMessage = - abortMessage + ' Make sure to remove the the GitHub release as well.'; + abortMessage + + ' Make sure to remove the the GitHub release draft as well.'; // Uploading the Zip to the Github release await runStep( 'Uploading the plugin ZIP', abortMessage, async () => { const filestats = fs.statSync( zipPath ); await octokit.repos.uploadReleaseAsset( { - url: release.upload_url, + url: releaseDraft.upload_url, headers: { 'content-length': filestats.size, 'content-type': 'application/zip', @@ -448,6 +456,19 @@ async function runGithubReleaseStep( log( '>> The plugin ZIP has been successfully uploaded.' ); } ); + // Remove draft status from the Github release + await runStep( 'Publishing the Github release', abortMessage, async () => { + const releaseData = await octokit.repos.updateRelease( { + owner: config.githubRepositoryOwner, + repo: config.githubRepositoryName, + release_id: releaseDraft.id, + draft: false, + } ); + release = releaseData.data; + + log( '>> The GitHub release has been published.' ); + } ); + log( '>> The GitHub release is available here: ' + formats.success( release.html_url )