Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release script: Set draft status, and only remove after uploading asset #27713

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new step necessary? I mean not just put this logic inside the previous step. (it's all related)

Copy link
Contributor Author

@ockham ockham Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering that, but since release (now draft) creation and asset upload are separate, it seemed like removing the draft status should also be separate, since it's semantically not part of the asset upload step. (I don't feel strongly about this.)

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