Skip to content

Commit

Permalink
Release script: Set draft status, and only remove after uploading ass…
Browse files Browse the repository at this point in the history
…et (#27713)

In the release script, rather than creating a GH release, and then attaching the plugin zip release asset, this PR creates a release _draft_ first, attaches the plugin zip, and only then removes the draft state.

This is a prerequisite for GH action-based automation.
  • Loading branch information
ockham authored Dec 14, 2020
1 parent 3b0bca0 commit fcc4b8c
Showing 1 changed file with 58 additions and 37 deletions.
95 changes: 58 additions & 37 deletions bin/plugin/commands/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 )
Expand Down

0 comments on commit fcc4b8c

Please sign in to comment.