release: Use draft releases to test the create-github-release script
This commit is contained in:
@@ -20,7 +20,7 @@ jobs:
|
||||
node-version: '12.x'
|
||||
|
||||
- name: Install node dependencies
|
||||
run: yarn install @octokit/rest
|
||||
run: npm install @octokit/rest
|
||||
|
||||
# GITHUB_REF is of the format refs/tags/vA.B.C
|
||||
# This step extracts vA.B.C from GITHUB_REF
|
||||
@@ -28,5 +28,7 @@ jobs:
|
||||
id: get_version
|
||||
run: echo "::set-output name=TAG_NAME::${GITHUB_REF#refs/tags/}"
|
||||
|
||||
# TODO/Note: This will only create a Draft release, which the maintainer can see and publish.
|
||||
# If the Draft release looks good, modify the step to go ahead publish the release. (By adding the third CLI argument.)
|
||||
- name: Create release on GitHub
|
||||
run: node scripts/create-github-release.js ${{ steps.get_version.outputs.TAG_NAME }} ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }} 1
|
||||
run: node scripts/create-github-release.js ${{ steps.get_version.outputs.TAG_NAME }} ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* (Dry Run mode, will not create release)
|
||||
* (Dry Run mode, will create a DRAFT release, but will not publish it.)
|
||||
* (Draft releases are visible to maintainers and do not notify users.)
|
||||
* $ node scripts/get-release-description v0.4.1 <GITHUB_TOKEN>
|
||||
*
|
||||
* This will open the git tree at this tag https://github.com/backstage/backstage/tree/v0.4.1
|
||||
@@ -34,7 +35,7 @@
|
||||
* (Production or GitHub Actions Mode)
|
||||
* $ node scripts/get-release-description v0.4.1 <GITHUB_TOKEN> 1
|
||||
*
|
||||
* This will do the same steps as above, and will create the Release with the description.
|
||||
* This will do the same steps as above, and will publish the Release with the description.
|
||||
*/
|
||||
|
||||
const { Octokit } = require('@octokit/rest');
|
||||
@@ -44,7 +45,7 @@ const [TAG_NAME, GITHUB_TOKEN, BOOL_CREATE_RELEASE] = process.argv.slice(2);
|
||||
|
||||
if (!BOOL_CREATE_RELEASE) {
|
||||
console.log(
|
||||
'\nRunning script in Dry Run mode. It will output details, but will not create any Release.',
|
||||
'\nRunning script in Dry Run mode. It will output details, wil create a draft release but will NOT publish it.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -146,19 +147,26 @@ async function prepareReleaseDescription(prDescription) {
|
||||
|
||||
// Create Release on GitHub.
|
||||
async function createRelease(releaseDescription) {
|
||||
// Create the release
|
||||
// Create draft release if BOOL_CREATE_RELEASE is undefined
|
||||
// Publish release if BOOL_CREATE_RELEASE is not undefined
|
||||
const boolCreateDraft = !BOOL_CREATE_RELEASE;
|
||||
|
||||
const releaseResponse = await octokit.repos.createRelease({
|
||||
owner: GH_REPO,
|
||||
repo: GH_REPO,
|
||||
tag_name: TAG_NAME,
|
||||
name: TAG_NAME,
|
||||
body: releaseDescription,
|
||||
draft: false,
|
||||
draft: boolCreateDraft,
|
||||
prerelease: false,
|
||||
});
|
||||
|
||||
if (releaseResponse.status === 201) {
|
||||
console.log('Created release!');
|
||||
if (boolCreateDraft) {
|
||||
console.log('Created draft release! Click Publish to notify users.');
|
||||
} else {
|
||||
console.log('Published release!');
|
||||
}
|
||||
console.log(releaseResponse.data.html_url);
|
||||
} else {
|
||||
console.error(releaseResponse);
|
||||
@@ -171,11 +179,7 @@ async function main() {
|
||||
const prDescription = await getPrDescriptionFromCommitMessage(commitMessage);
|
||||
const releaseDescription = await prepareReleaseDescription(prDescription);
|
||||
|
||||
if (BOOL_CREATE_RELEASE) {
|
||||
await createRelease(releaseDescription);
|
||||
} else {
|
||||
console.log('Skipping release since script running in Dry Run mode.');
|
||||
}
|
||||
await createRelease(releaseDescription);
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user