-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document the branch layout & versioning system (#116)
Document how the branches play together, what the versions will be, and how to make changes to griff. This also adds a script (run with `yarn release`) to determine the new version number, publish a release, and push the tag to GitHub.
- Loading branch information
1 parent
961a4e4
commit 4cfe5bf
Showing
3 changed files
with
83 additions
and
7 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
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,61 @@ | ||
#!/usr/bin/env node | ||
|
||
const shell = require('shelljs'); | ||
const semver = require('semver'); | ||
const pkg = require('../package.json'); | ||
|
||
// Abort on any shell error. | ||
shell.set('-e'); | ||
|
||
// See which versions have already been published.} | ||
|
||
function getPublishedVersions() { | ||
const { name } = pkg; | ||
const cmd = `yarn info ${name} versions --json`; | ||
const result = shell.exec(cmd, { | ||
silent: true, | ||
shell: '/bin/bash', | ||
}); | ||
if (result.code !== 0) { | ||
console.error(`Unable to fetch versions for ${name}`); | ||
console.log(result.stdout); | ||
console.error(result.stderr); | ||
process.exit(result.code); | ||
} | ||
try { | ||
return JSON.parse(result.stdout).data; | ||
} catch (e) { | ||
return []; | ||
} | ||
} | ||
|
||
function findVersionToBump(currentVersion, versions) { | ||
const current = { | ||
major: semver.major(currentVersion), | ||
minor: semver.minor(currentVersion), | ||
patch: semver.patch(currentVersion), | ||
}; | ||
const valid = (versions || getPublishedVersions()) | ||
.filter(v => semver.major(v) === current.major) | ||
.filter(v => semver.minor(v) === current.minor) | ||
.sort((a, b) => semver.patch(b) - semver.patch(a)) | ||
.sort( | ||
(a, b) => | ||
(semver.prerelease(b) || [semver.patch(b)])[0] - | ||
(semver.prerelease(a) || [semver.patch(a)])[0] | ||
); | ||
return valid.length ? valid[0] : currentVersion; | ||
} | ||
|
||
const publishedVersion = findVersionToBump(pkg.version); | ||
|
||
// Calculate the new version. | ||
const newVersion = semver.prerelease(publishedVersion) | ||
? semver.inc(publishedVersion, 'prerelease') | ||
: semver.inc(publishedVersion, 'patch'); | ||
|
||
// Publish a new release with this version. | ||
shell.exec(`yarn publish --new-version "${newVersion}"`); | ||
|
||
// Push the version tag to GitHub. | ||
shell.exec('git push origin --tags'); |