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

Create release script #617

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
91 changes: 91 additions & 0 deletions create-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env node

const { Octokit } = require('@octokit/rest');
const inquirer = require('inquirer');

const octokit = new Octokit({
auth: '<GENERATE FROM HERE: https://github.com/settings/tokens>',
Copy link
Member

Choose a reason for hiding this comment

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

OK, so token goes here! Is there a security risk to putting a token here? Sorry, just to be sure!

Copy link
Member

Choose a reason for hiding this comment

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

Ah @Sagarpreet - check it out - here it says to put the token in the "secrets" --- where it can be referenced from:

https://riggaroo.dev/using-github-actions-to-automate-our-release-process/

also here: https://github.com/actions/create-release#example-workflow---create-a-release

Let me see about that...

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@jywarren jywarren Nov 5, 2020

Choose a reason for hiding this comment

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

Would this work then?

Suggested change
auth: '<GENERATE FROM HERE: https://github.com/settings/tokens>',
auth: ${{ secrets.GITHUBTOKEN }},

Copy link
Member

Choose a reason for hiding this comment

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

OK, adding these privileges:
image

Copy link
Member

Choose a reason for hiding this comment

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

OK, strangely I couldn't make a secret called GITHUB_TOKEN as it said it was an invalid name. I instead made GITHUBTOKEN. I wonder... is there an organization secret  with a colliding name? Not sure, but let's try GITHUBTOKEN

Copy link
Member

Choose a reason for hiding this comment

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

Just noting that we have no org secrets so it wasn't a name collision...

oh! Aha - it's a reserved name -- it already exists with some permissions. Maybe best try it out? https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#about-the-github_token-secret

i wasn't sure it had release creation permissions. but if it does, might as well use it instead of the one I created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think anyone can create a release in open source projects, right?
Similar to issues maybe, not sure.
So only read permissions for projects should be enough

});

async function fetchAppParameters() {
const questions = [
{
type: 'input',
name: 'name',
message: "What is your name?",
default: 'Jeff',
},
{
type: 'list',
name: 'verson',
message: "How will you describe the release upgrade? Note changes or any breaking changes if it's a major release, following Semantic Versioning conventions: https://docs.npmjs.com/about-semantic-versioning",
default: 'Major',
choices: ['Minor', 'Major'],
},
{
type: 'input',
name: 'isDraft',
message: "Do you want to make Draft release? (y/n)",
default: 'N',
}
];
return inquirer.prompt(questions).then(answers => {
console.log(
`Thanks for entering the information, kindly wait till I generate a perfect release for you.`
);
return answers;
});

}

(async () => {
const answers = await fetchAppParameters();
const output = await octokit.repos.getLatestRelease({
owner: 'publiclab',
repo: 'plots2'
});
const latestTag = output.data.tag_name;
const currTag = latestTag.split('v')[1].split('.');
const newTag = answers.verson === "Minor" ? ("v" + currTag[0] + "." + (parseInt(currTag[1]) + 1).toString()) : ("v" + (parseInt(currTag[0]) + 1).toString() + ".0");

console.log("latestTag", latestTag);
console.log("newTag", newTag);

let commitHistory = ``;
try {
const result = await octokit.repos.compareCommits({
owner: 'publiclab',
repo: 'plots2',
base: latestTag,
Copy link
Member

Choose a reason for hiding this comment

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

oh is this a problem as we're currently in the Editor repo?

head: "main"
});
commitHistory = result.data.commits.reduce((acc, commitobj) => {
const authorName = `@${commitobj.commit.author.name}`;
const commit_sha = commitobj.sha;
const commit_msg = commitobj.commit.message;
const arr = commit_msg.split(' ')
const PR_number = arr[0];
arr.shift();
const final_msg = arr.join(' ');
return acc + "\n ### :baby: " + authorName + " " + PR_number + " (squashed commit: " + commit_sha + ")" + "\n" + final_msg + "\n";
} , '');
} catch(e) {
console.error('Something went wrong!', e);
}

try {
const result = await octokit.repos.createRelease({
owner: 'publiclab',
repo: 'plots2',
tag_name: newTag,
draft: answers.isDraft.toUpperCase() === 'Y',
name: `${answers.verson} Release ${newTag}`,
body: "#### :sunflower: Release made by: " + answers.name + "\n\n ### Changes: \n" +
commitHistory
});
console.log("Your release is ready here: ");
console.log(result.data.html_url);
} catch(e) {
console.error('Something went wrong!', e);
}
})();
Loading