do not push to npm

This commit is contained in:
phips28 2019-10-26 19:35:58 +02:00
parent fbfd53a737
commit a0ace87e9b
7 changed files with 1730 additions and 88 deletions

View File

@ -1,12 +1,12 @@
FROM node:10-slim FROM node:10-slim
LABEL version="1.0.0" LABEL version="1.0.0"
LABEL repository="http://github.com/mikeal/merge-release" LABEL repository="http://github.com/phips28/gh-action-bump-version"
LABEL homepage="http://github.com/merge-release" LABEL homepage="http://github.com/gh-action-bump-version"
LABEL maintainer="Mikeal Rogers <mikeal.rogers@gmail.com>" LABEL maintainer="Philipp Holly <phips28@gmx.at>"
LABEL com.github.actions.name="Automated releases for npm packages." LABEL com.github.actions.name="Automated version bump for npm packages."
LABEL com.github.actions.description="Release npm package based on commit metadata." LABEL com.github.actions.description="Automated version bump for npm packages."
LABEL com.github.actions.icon="package" LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="red" LABEL com.github.actions.color="red"
COPY LICENSE README.md / COPY LICENSE README.md /

View File

@ -1,6 +1,6 @@
## merge-release ## gh-action-bump-version
GitHub Action for automated npm publishing. GitHub Action for automated npm version bump.
This Action publishes a package to npm. It is meant to be used on every successful merge to master but This Action publishes a package to npm. It is meant to be used on every successful merge to master but
you'll need to configured that workflow yourself. You can look to the you'll need to configured that workflow yourself. You can look to the

View File

@ -21,15 +21,15 @@ fi
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git config user.name "Merge Release" git config user.name "Bump Version"
git config user.email "merge-release@users.noreply.github.com" git config user.email "gh-action-bump-version@users.noreply.github.com"
git remote add merge-release "${remote_repo}" git remote add gh-action-bump-version "${remote_repo}"
if [ "$GITHUB_REPOSITORY" = "mikeal/merge-release" ] if [ "$GITHUB_REPOSITORY" = "phips28/gh-action-bump-version" ]
then then
echo "node merge-release-run.js" echo "node gh-action-bump-version-run.js"
sh -c "node merge-release-run.js $*" sh -c "node gh-action-bump-version-run.js $*"
else else
echo "npx merge-release" echo "npx gh-action-bump-version"
sh -c "npx merge-release $*" sh -c "npx gh-action-bump-version $*"
fi fi

View File

@ -0,0 +1,33 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString())
let pkg = require(path.join(process.cwd(), 'package.json'))
const run = async () => {
if (!process.env.NPM_AUTH_TOKEN) throw new Error('gh-action-bump-version requires NPM_AUTH_TOKEN')
let 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'
}
const exec = str => process.stdout.write(execSync(str))
let current = execSync(`npm view ${pkg.name} version`).toString()
exec(`npm version --allow-same-version=true --git-tag-version=false ${current} `)
console.log('current:', current, '/', 'version:', version)
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
console.log('new version:', newVersion)
exec(`git checkout package.json`) // cleanup
exec(`git tag ${newVersion}`)
exec(`git push gh-action-bump-version --tags`)
}
run()

View File

@ -1,65 +0,0 @@
#!/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 pkg = require(path.join(process.cwd(), 'package.json'))
const run = async () => {
if (!process.env.NPM_AUTH_TOKEN) throw new Error('Merge-release requires NPM_AUTH_TOKEN')
let latest
try {
latest = await get(pkg.name + '/latest')
} catch (e) {
// unpublished
}
let messages
if (latest) {
if (latest.gitHead === process.env.GITHUB_SHA) return console.log('SHA matches latest release, skipping.')
if (latest.gitHead) {
try {
let logs = await getlog({ from: latest.gitHead, to: process.env.GITHUB_SHA })
messages = logs.all.map(r => r.message + '\n' + r.body)
} catch (e) {
latest = null
}
// 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'
}
const exec = str => process.stdout.write(execSync(str))
let current = execSync(`npm view ${pkg.name} version`).toString()
exec(`npm version --allow-same-version=true --git-tag-version=false ${current} `)
console.log('current:', current, '/', 'version:', version)
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
console.log('new version:', newVersion)
exec(`npm publish --access=public`)
exec(`git checkout package.json`) // cleanup
exec(`git tag ${newVersion}`)
exec(`git push merge-release --tags`)
}
run()

View File

@ -1,27 +1,25 @@
{ {
"name": "merge-release", "name": "gh-action-bump-version",
"version": "0.0.0-dev", "version": "1.0.0",
"description": "", "description": "",
"scripts": { "scripts": {
"test": "standard" "test": "standard"
}, },
"bin": { "bin": {
"merge-release": "./merge-release-run.js" "gh-action-bump-version": "./gh-action-bump-version-run.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/mikeal/auto-release.git" "url": "git+https://github.com/phips28/gh-action-bump-version.git"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/mikeal/auto-release/issues" "url": "https://github.com/phips28/gh-action-bump-version/issues"
}, },
"homepage": "https://github.com/mikeal/auto-release#readme", "homepage": "https://github.com/phips28/gh-action-bump-version#readme",
"dependencies": { "dependencies": {
"bent": "1.5.13",
"simple-git": "^1.113.0",
"yargs": "^12.0.5" "yargs": "^12.0.5"
}, },
"devDependencies": { "devDependencies": {

1676
yarn.lock Normal file

File diff suppressed because it is too large Load Diff