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" # Labels for GitHub to read your action
LABEL repository="http://github.com/phips28/gh-action-bump-version" LABEL "com.github.actions.name"="Automated version bump for npm packages."
LABEL homepage="http://github.com/gh-action-bump-version" LABEL "com.github.actions.description"="Automated version bump for npm packages."
LABEL maintainer="Philipp Holly <phips28@gmx.at>" # 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." # Copy the package.json and package-lock.json
LABEL com.github.actions.description="Automated version bump for npm packages." COPY package*.json ./
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="red"
COPY LICENSE README.md /
RUN apt-get update # Install dependencies
RUN apt-get -y install git RUN npm ci
COPY "entrypoint.sh" "/entrypoint.sh" # Copy the rest of your action's code
ENTRYPOINT ["/entrypoint.sh"] COPY . .
CMD ["help"]
# 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", "name": "gh-action-bump-version",
"version": "1.0.5", "version": "1.0.5",
"description": "",
"scripts": {
"test": "standard"
},
"bin": {
"gh-action-bump-version": "./gh-action-bump-version-run.js"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/phips28/gh-action-bump-version.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" "url": "https://github.com/phips28/gh-action-bump-version/issues"
}, },
"homepage": "https://github.com/phips28/gh-action-bump-version#readme", "homepage": "https://github.com/phips28/gh-action-bump-version#readme",
"private": true,
"main": "index.js",
"scripts": {
"start": "node ./index.js",
"test": "jest"
},
"dependencies": { "dependencies": {
"actions-toolkit": "^2.2.0",
"yargs": "^14.2.0" "yargs": "^14.2.0"
}, },
"devDependencies": { "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