-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabo/release PR now adds PENDING.md to CHANGELOG.md (#2242)
* release PR now adds PENDING.md to CHANGELOG.md * tests * comments * tests * fixed tests * linted * ignore main coverage
- Loading branch information
Showing
6 changed files
with
112 additions
and
45 deletions.
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
### Changed | ||
|
||
- [#\2210](https://github.com/cosmos/voyager/pull/2210) Faucet give money only to non-existent addresses @sabau | ||
- release PR now adds PENDING.md to CHANGELOG.md @faboweb | ||
- [#\2202](https://github.com/cosmos/voyager/pull/2202) Fix circle configuration for publishing @sabau | ||
- [#\2236](https://github.com/cosmos/voyager/pull/2236) ES lint no tabs @sabau |
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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
const { cli, shell } = require(`@nodeguy/cli`) | ||
const fs = require(`fs`) | ||
const { join } = require(`path`) | ||
const octokit = require(`@octokit/rest`)() | ||
|
||
function bumpVersion(versionString) { | ||
|
@@ -12,24 +13,24 @@ function bumpVersion(versionString) { | |
return versionElements.join(`.`) | ||
} | ||
|
||
function updateChangeLog(changeLog, newVersion, now) { | ||
function updateChangeLog(changeLog, pending, newVersion, now) { | ||
const today = now.toISOString().slice(0, 10) | ||
|
||
return changeLog.replace( | ||
`## [Unreleased]`, | ||
`## [Unreleased]\n\n## [${newVersion}] - ${today}` | ||
`## [Unreleased]\n\n## [${newVersion}] - ${today}\n\n${pending}` | ||
) | ||
} | ||
|
||
const updatePackageJson = (packageJson, version) => | ||
Object.assign({}, packageJson, { version }) | ||
|
||
const pushCommit = ({ token, branch }) => | ||
const pushCommit = (shell, { token, branch }) => | ||
shell(` | ||
set -o verbose | ||
git config --local user.name "Voyager Bot" | ||
git config --local user.email "[email protected]" | ||
git add CHANGELOG.md package.json | ||
git add CHANGELOG.md PENDING.md package.json | ||
git commit --message="Bump version for release." | ||
git tag --force release-candidate | ||
git remote add bot https://${token}@github.com/cosmos/voyager.git | ||
|
@@ -39,7 +40,7 @@ git push --force --tags bot HEAD:${branch} | |
const recentChanges = changeLog => | ||
changeLog.match(/.+?## .+?\n## .+?\n\n(.+?)\n## /s)[1] | ||
|
||
const createPullRequest = async ({ changeLog, token, tag, head }) => { | ||
const createPullRequest = async (octokit, { changeLog, token, tag, head }) => { | ||
octokit.authenticate({ | ||
type: `token`, | ||
token | ||
|
@@ -56,41 +57,58 @@ const createPullRequest = async ({ changeLog, token, tag, head }) => { | |
}) | ||
} | ||
|
||
async function main({ octokit, shell, fs }, changeLog, pending, packageJson) { | ||
// only update if sth changed | ||
if (pending.trim() === ``) return | ||
|
||
console.log(`Making release...`) | ||
|
||
const oldVersion = packageJson.version | ||
const newVersion = bumpVersion(oldVersion) | ||
console.log(`New version:`, newVersion) | ||
const newChangeLog = updateChangeLog( | ||
changeLog, | ||
pending, | ||
newVersion, | ||
new Date() | ||
) | ||
const newPackageJson = updatePackageJson(packageJson, newVersion) | ||
|
||
fs.writeFileSync(join(__dirname, `..`, `PENDING.md`), ``, `utf8`) | ||
fs.writeFileSync(join(__dirname, `..`, `CHANGELOG.md`), newChangeLog, `utf8`) | ||
fs.writeFileSync( | ||
join(__dirname, `..`, `package.json`), | ||
JSON.stringify(newPackageJson, null, 2) + `\n`, | ||
`utf8` | ||
) | ||
|
||
console.log(`--- Committing release changes ---`) | ||
|
||
const tag = `v${newVersion}` | ||
const branch = `release-candidate/${tag}` | ||
await pushCommit(shell, { token: process.env.GIT_BOT_TOKEN, branch }) | ||
|
||
await createPullRequest(octokit, { | ||
changeLog: newChangeLog, | ||
token: process.env.GIT_BOT_TOKEN, | ||
tag, | ||
head: branch | ||
}) | ||
} | ||
|
||
if (require.main === module) { | ||
cli({}, async () => { | ||
console.log(`Making release...`) | ||
const changeLog = fs.readFileSync(__dirname + `/../CHANGELOG.md`, `utf8`) | ||
const packageJson = require(__dirname + `/../package.json`) | ||
const oldVersion = packageJson.version | ||
const newVersion = bumpVersion(oldVersion) | ||
console.log(`New version:`, newVersion) | ||
const newChangeLog = updateChangeLog(changeLog, newVersion, new Date()) | ||
const newPackageJson = updatePackageJson(packageJson, newVersion) | ||
|
||
fs.writeFileSync(__dirname + `/../CHANGELOG.md`, newChangeLog, `utf8`) | ||
|
||
fs.writeFileSync( | ||
__dirname + `/../package.json`, | ||
JSON.stringify(newPackageJson, null, 2) + `\n`, | ||
`utf8` | ||
) | ||
|
||
console.log(`--- Committing release changes ---`) | ||
|
||
const tag = `v${newVersion}` | ||
const branch = `release-candidate/${tag}` | ||
await pushCommit({ token: process.env.GIT_BOT_TOKEN, branch }) | ||
|
||
await createPullRequest({ | ||
changeLog: newChangeLog, | ||
token: process.env.GIT_BOT_TOKEN, | ||
tag, | ||
head: branch | ||
}) | ||
/* istanbul ignore next */ | ||
cli({}, () => { | ||
const changeLog = fs.readFileSync(join(__dirname, `..`, `CHANGELOG.md`), `utf8`) | ||
const pending = fs.readFileSync(join(__dirname, `..`, `PENDING.md`), `utf8`) | ||
const packageJson = require(join(__dirname, `..`, `package.json`)) | ||
|
||
main({ octokit, shell, fs }, changeLog, pending, packageJson) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
main, | ||
bumpVersion, | ||
updateChangeLog, | ||
updatePackageJson | ||
|
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
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