diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4b2698a..f4fc341 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,33 +1,21 @@ -on: push -name: Build and Publish +name: "Bump Version" + +on: + push: + branches: + - "master" + jobs: - shellLint: - name: Shell Lint + bump-version: + name: "Bump Version on master" runs-on: ubuntu-latest + steps: - - uses: actions/checkout@master - - name: Shell Lint - uses: actions/bin/shellcheck@master - with: - args: entrypoint.sh - - name: Build Docker - uses: actions/docker/cli@master - with: - args: build -t npm . - - name: Build - uses: actions/npm@master - with: - args: install - - name: Test - uses: actions/npm@master - with: - args: test - - name: Publish Filter - uses: actions/bin/filter@master - with: - args: branch master - - name: Publish - uses: mikeal/merge-release@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + - name: "Checkout source code" + - uses: actions/checkout@v1 + - with: + fetch-depth: 1 + - name: "Bump Version" + uses: phips28/gh-action-bump-version@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/gh-action-bump-version-run.js b/gh-action-bump-version-run.js index 4473b67..6dbbd51 100644 --- a/gh-action-bump-version-run.js +++ b/gh-action-bump-version-run.js @@ -3,19 +3,25 @@ const fs = require('fs') const path = require('path') const { execSync } = require('child_process') -// const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString()) +const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString()) let pkg = require(path.join(process.cwd(), 'package.json')) const run = async () => { - // let messages = event.commits.map(commit => commit.message + '\n' + commit.body) - // + let messages = event.commits.map(commit => commit.message + '\n' + commit.body) + + const commitMessage = 'version bump' + const isVersionBump = messages.map(message => message.toLowerCase().includes(commitMessage)).includes(true) + if (isVersionBump) { + 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' - // } + 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)) @@ -26,7 +32,7 @@ const run = async () => { console.log('current:', current, '/', 'version:', version) let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString() console.log('new version:', newVersion) - exec(`git commit -a -m 'ci: version bump ${newVersion}'`) + exec(`git commit -a -m 'ci: ${commitMessage} ${newVersion}'`) exec(`git push`) exec(`git tag ${newVersion}`) exec(`git push --tags`)