feat: get full diff between releases

This commit is contained in:
Mikeal Rogers 2019-05-23 18:43:01 +00:00
parent 53a92ca2d1
commit 7a39bb7781
2 changed files with 45 additions and 16 deletions

View File

@ -1,27 +1,54 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const bent = require('bent')
const git = require('simple-git')()
const { execSync } = require('child_process')
const { promisify } = require('util')
const getlog = promisify(git.log.bind(git))
const get = bent('json', 'https://registry.npmjs.org/')
const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString())
let messages = event.commits.map(commit => commit.message)
let version = 'patch'
if (messages.map(message => message.includes('BREAKING CHANGE')).includes(true)) {
version = 'major'
} else if (messages.map(message => message.toLowerCase().startsWith('feat')).includes(true)) {
version = 'minor'
}
let pkg = require(path.join(process.cwd(), 'package.json'))
pkg.gitsha = process.env.GITHUB_SHA
const run = async () => {
let latest
try {
latest = await get(pkg.name + '/latest')
} catch (e) {
// unpublished
}
fs.writeFileSync(path.join(process.cwd(), 'package.json'), Buffer.from(JSON.stringify(pkg)))
let messages
let current = execSync(`npm view ${pkg.name} version`).toString()
process.stdout.write(execSync(`npm version --allow-same-version=true --git-tag-version=false ${current} `))
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
console.log(newVersion)
process.stdout.write(execSync(`npm publish --access=public`))
if (latest) {
if (latest.gitHead === process.env.GITHUB_SHA) return console.log('SHA matches latest release, skipping.')
if (latest.gitHead) {
let logs = await getlog({ from: latest.gitHead, to: process.env.GITHUB_SHA })
messages = logs.all.map(r => r.message + '\n' + r.body)
// g.log({from: 'f0002b6c9710f818b9385aafeb1bde994fe3b370', to: '53a92ca2d1ea3c55977f44d93e48e31e37d0bc69'}, (err, l) => console.log(l.all.map(r => r.message + '\n' + r.body)))
} else {
latest = null
}
}
if (!latest) {
messages = event.commits.map(commit => commit.message + '\n' + commit.body)
}
let version = 'patch'
if (messages.map(message => message.includes('BREAKING CHANGE')).includes(true)) {
version = 'major'
} else if (messages.map(message => message.toLowerCase().startsWith('feat')).includes(true)) {
version = 'minor'
}
let current = execSync(`npm view ${pkg.name} version`).toString()
process.stdout.write(execSync(`npm version --allow-same-version=true --git-tag-version=false ${current} `))
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
console.log(newVersion)
process.stdout.write(execSync(`npm publish --access=public`))
}
run()

View File

@ -20,6 +20,8 @@
},
"homepage": "https://github.com/mikeal/auto-release#readme",
"dependencies": {
"bent": "^1.5.13",
"simple-git": "^1.113.0",
"yargs": "^12.0.5"
},
"devDependencies": {