Skip to content

Commit

Permalink
[Config] Automatically create a github release
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 12, 2019
1 parent c33a598 commit f61253b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
51 changes: 51 additions & 0 deletions scripts/create_release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const fetch = require('node-fetch');

const TITLE_DELIMITER = '\n\n';

const changelog = process.argv[2] || '';

function releaseUrl(repo) {
return `https://api.github.com/repos/${repo}/releases`;
};

function postRelease({
repo,
token,
tag,
body
}) {
console.log('posting release');
fetch(releaseUrl(repo), {
method: 'POST',
headers: { Authorization: `token ${token}` },
body: JSON.stringify({
tag_name: tag,
name: tag,
body
})
});
}

function release({ repo, token, tag }) {
console.log('In release');

if (!(changelog && token && repo)) {
return;
}

const body = changelog.substr(changelog.indexOf(TITLE_DELIMITER) + TITLE_DELIMITER.length);

postRelease({
repo,
token,
tag,
body
});
};

release({
repo: process.env.GITHUB_REPO,
token: process.env.GITHUB_TOKEN,
tag: process.env.NEXT_VERSION,
changelog
});
2 changes: 1 addition & 1 deletion scripts/get_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function listMessages(commits = []) {
}

function getCommitDiff(repo, branches, token) {
return fetch(compareUrl(repo, branches), { ...token && { headers: { token } } })
return fetch(compareUrl(repo, branches), { ...token && { headers: { Authorization: `token ${token}` } } })
.then((res) => res.json())
.catch(() => process.exit(1));
}
Expand Down
5 changes: 4 additions & 1 deletion scripts/push_tag_to_master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ echo "Rebuilding with current tag"
yarn build

echo "Updating changelog"
node ./scripts/update_changelog.js
CHANGELOG=$(node ./scripts/update_changelog.js)

EMOJIS=(🚀 🤘 ✨ 🔔 🌈 🤯)
EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]}]}
Expand All @@ -32,3 +32,6 @@ git push https://${GITHUB_TOKEN}@github.com/$GITHUB_REPO.git master

git tag $NEXT_VERSION
git push origin $NEXT_VERSION

echo "Publishing Release"
node ./scripts/create_release.js "$CHANGELOG"
4 changes: 3 additions & 1 deletion scripts/update_changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const updateChangelog = () => {
changelog.splice(6, 0, versionLog);

fs.writeFileSync('./CHANGELOG.md', changelog.join('\n'));

console.log(versionLog);
};

module.exports = updateChangelog;
updateChangelog();

0 comments on commit f61253b

Please sign in to comment.