-
Notifications
You must be signed in to change notification settings - Fork 128
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
sagarpreet-chadha
wants to merge
6
commits into
main
Choose a base branch
from
create-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
682ccb0
Create create-release.js
sagarpreet-chadha ab46d30
Update package.json
sagarpreet-chadha 0505ed1
Update package-lock.json
sagarpreet-chadha b0a48dc
Update package.json
sagarpreet-chadha 6c682a0
Update package-lock.json
sagarpreet-chadha 0224a59
Update create-release.js
sagarpreet-chadha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>', | ||
}); | ||
|
||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
})(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha yes https://github.com/publiclab/PublicLab.Editor/settings/secrets - doing this now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, adding these privileges:
There was a problem hiding this comment.
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 madeGITHUBTOKEN
. I wonder... is there an organization secret with a colliding name? Not sure, but let's tryGITHUBTOKEN
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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