-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial draft of release script (see PR #840)
- Loading branch information
Showing
6 changed files
with
199 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const pify = require('pify') | ||
const rimraf = require('rimraf') | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
const getGitStatus = require('./utils/get-git-status') | ||
const getGitTags = require('./utils/get-git-tags') | ||
const execute = require('./utils/execute') | ||
|
||
const log = console.log | ||
const removeDir = pify(rimraf) | ||
const readFile = pify(fs.readFile) | ||
const writeFile = pify(fs.writeFile) | ||
|
||
const dryRun = process.argv.includes('--dry-run') | ||
const {version} = require('./package.json') | ||
|
||
;(async () => { | ||
log('Doing sanity checks...') | ||
const {currentBranch: branchToPublish, cleanWorkingTree} = await getGitStatus() | ||
if (!dryRun) { | ||
assert.equal(branchToPublish, 'master', 'Must be on master branch') | ||
} | ||
assert.equal(cleanWorkingTree, true, 'Must have clean working tree') | ||
const gitTags = await getGitTags() | ||
assert.ok(!gitTags.includes(`v${version}`), 'Must have a unique version in package.json') | ||
|
||
log('Deleting the dist folder (it will conflict with the next step)...') | ||
await removeDir('dist') | ||
|
||
log('Switching to the dist branch...') | ||
await execute('git checkout dist') | ||
|
||
log(`Merging from "${branchToPublish}" branch...`) | ||
await execute(`git merge ${branchToPublish}`) | ||
|
||
log('Running the build...') | ||
await execute('npm run build') | ||
|
||
log('Running the checks...') | ||
await execute('npm run check') | ||
|
||
if (dryRun) { | ||
log('Skipping publishing on npm...') | ||
} else { | ||
log('Publishing on npm...') | ||
await execute('npm publish') | ||
} | ||
|
||
log('Removing "dist" from .gitignore...') | ||
const gitignore = await readFile('.gitignore', 'utf8') | ||
const gitignoreWithoutDist = gitignore.split(/\r?\n/).filter(line => line !== 'dist').join('\n') | ||
await writeFile('.gitignore', gitignoreWithoutDist) | ||
|
||
log('Committing the dist dir...') | ||
await execute(`git add dist/ && git commit -m "Release v${version}"`) | ||
|
||
log('Reverting the change to .gitignore...') | ||
await execute('git reset --hard HEAD') | ||
|
||
log(`Tagging commit as "v${version}"...`) | ||
await execute(`git tag "v${version}"`) | ||
|
||
if (dryRun) { | ||
log('Skipping pushing to Github...') | ||
} else { | ||
log('Pushing to Github...') | ||
await execute('git push origin dist:dist --tags') | ||
} | ||
|
||
log(`Switching back to "${branchToPublish}" (so you can continue to work)...`) | ||
await execute(`git checkout "${branchToPublish}"`) | ||
|
||
log('OK!') | ||
})() |
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,19 @@ | ||
const execa = require('execa') | ||
const es = require('event-stream') | ||
|
||
module.exports = function execute (command, {skipLogging} = {}) { | ||
const proc = execa.shell(command) | ||
|
||
if (!skipLogging) { | ||
const formatLine = (line, label) => ` (pid:${proc.pid})\t[${label}]\t${line}\n` | ||
const formatStream = (stream, label) => stream | ||
.pipe(es.split()) | ||
.pipe(es.map((line, cb) => cb(null, formatLine(line, label)))) | ||
|
||
process.stdout.write(formatLine(command, 'cmd')) | ||
es.merge(formatStream(proc.stdout, 'out'), formatStream(proc.stderr, 'ERR')) | ||
.pipe(process.stdout) | ||
} | ||
|
||
return proc | ||
} |
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,16 @@ | ||
const execute = require('./execute') | ||
const assert = require('assert') | ||
|
||
async function getGitStatus () { | ||
const lines = (await execute('git status')).stdout.split(/\r?\n/) | ||
|
||
const match = lines[0].match(/^On branch (\S+)$/) | ||
assert.ok(match, 'Unable to determine current branch') | ||
const currentBranch = match[1] | ||
|
||
const cleanWorkingTree = lines.includes('nothing to commit, working tree clean') | ||
|
||
return {currentBranch, cleanWorkingTree} | ||
} | ||
|
||
module.exports = getGitStatus |
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,8 @@ | ||
const execute = require('./execute') | ||
|
||
async function getGitTags () { | ||
const {stdout} = await execute('git tag', {skipLogging: true}) | ||
return stdout.split(/\r?\n/).filter(Boolean) | ||
} | ||
|
||
module.exports = getGitTags |
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