new version with actions-toolkit

This commit is contained in:
phips28 2019-10-26 21:06:00 +02:00
parent 766ee26515
commit 3c7493a465
5 changed files with 3431 additions and 328 deletions

View File

@ -1,20 +1,31 @@
FROM node:10-slim
# Use the latest version of Node.js
#
# You may prefer the full image:
# FROM node
#
# or even an alpine image (a smaller, faster, less-feature-complete image):
# FROM node:alpine
#
# You can specify a version:
# FROM node:10-slim
FROM node:slim
LABEL version="1.0.0"
LABEL repository="http://github.com/phips28/gh-action-bump-version"
LABEL homepage="http://github.com/gh-action-bump-version"
LABEL maintainer="Philipp Holly <phips28@gmx.at>"
# Labels for GitHub to read your action
LABEL "com.github.actions.name"="Automated version bump for npm packages."
LABEL "com.github.actions.description"="Automated version bump for npm packages."
# Here are all of the available icons: https://feathericons.com/
LABEL "com.github.actions.icon"="chevron-up"
# And all of the available colors: https://developer.github.com/actions/creating-github-actions/creating-a-docker-container/#label
LABEL "com.github.actions.color"="blue"
LABEL com.github.actions.name="Automated version bump for npm packages."
LABEL com.github.actions.description="Automated version bump for npm packages."
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="red"
COPY LICENSE README.md /
# Copy the package.json and package-lock.json
COPY package*.json ./
RUN apt-get update
RUN apt-get -y install git
# Install dependencies
RUN npm ci
COPY "entrypoint.sh" "/entrypoint.sh"
ENTRYPOINT ["/entrypoint.sh"]
CMD ["help"]
# Copy the rest of your action's code
COPY . .
# Run `node /index.js`
ENTRYPOINT ["node", "/index.js"]

8
action.yml Normal file
View File

@ -0,0 +1,8 @@
name: gh-action-bump-version
description: asfd
runs:
using: docker
image: Dockerfile
branding:
icon: chevron-up
color: blue

51
index.js Normal file
View File

@ -0,0 +1,51 @@
const { Toolkit } = require('actions-toolkit')
const { execSync } = require('child_process')
// Run your GitHub Action!
Toolkit.run(async tools => {
console.log('context:', tools.context)
const pkg = tools.getPackageJSON()
const event = tools.context.payload
console.log('event:', event)
const messages = event.commits.map(commit => commit.message + '\n' + commit.body)
const commitMessage = 'version bump to'
const isVersionBump = messages.map(message => message.toLowerCase().includes(commitMessage)).includes(true)
if (isVersionBump) {
tools.exit.neutral('No _action_ necessary!')
return
}
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 => {
return process.stdout.write(execSync(str))
}
try {
const current = pkg.version.toString()
exec('git checkout master')
exec(`npm version --allow-same-version=true --git-tag-version=false ${current} `)
console.log('current:', current, '/', 'version:', version)
const newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
console.log('new version:', newVersion)
exec(`git commit -a -m 'ci: ${commitMessage} ${newVersion}'`)
const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`
console.log('remoteRepo:', remoteRepo)
exec(`git tag ${newVersion}`)
exec(`git push "${remoteRepo}" --follow-tags`)
exec(`git push "${remoteRepo}" --tags`)
} catch (e) {
tools.exit.failure(`Failed: ${e.toString()}`)
}
tools.exit.success('Version bumped!')
})

View File

@ -1,13 +1,6 @@
{
"name": "gh-action-bump-version",
"version": "1.0.5",
"description": "",
"scripts": {
"test": "standard"
},
"bin": {
"gh-action-bump-version": "./gh-action-bump-version-run.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/phips28/gh-action-bump-version.git"
@ -19,10 +12,18 @@
"url": "https://github.com/phips28/gh-action-bump-version/issues"
},
"homepage": "https://github.com/phips28/gh-action-bump-version#readme",
"private": true,
"main": "index.js",
"scripts": {
"start": "node ./index.js",
"test": "jest"
},
"dependencies": {
"actions-toolkit": "^2.2.0",
"yargs": "^14.2.0"
},
"devDependencies": {
"standard": "^12.0.1"
"jest": "^24.5.0",
"standard": "^14.3.1"
}
}

3642
yarn.lock

File diff suppressed because it is too large Load Diff