Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(release): add pre/post increment #426

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 73 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ on:

workflow_dispatch:
inputs:
increment:
description: Increment version before release
default: patch
type: choice
options:
- patch
- minor
- major
- none

post-increment:
description: Increment version after release
default: none
type: choice
options:
- patch
- minor
- major
- none

dry-run:
description: Dry run
required: false
Expand All @@ -20,6 +40,8 @@ permissions:

env:
INPUTS_DRY_RUN: ${{ github.event.inputs.dry-run }}
INPUTS_INCREMENT: ${{ github.event.inputs.increment }}
INPUTS_POST_INCREMENT: ${{ github.event.inputs.post-increment }}
DRY_RUN_OPTION: ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }}


Expand Down Expand Up @@ -51,7 +73,7 @@ jobs:

echo "Local version: $local_version"
echo "NPM version: $npm_version"

npm install -g semver

if semver -r ">${npm_version}" "${local_version}"; then
Expand Down Expand Up @@ -81,15 +103,21 @@ jobs:
npm ci
npm run test

# requires npm which we get from setup-node
- name: Increment version
if: ${{ github.event.inputs.increment != 'none' }}
run: |
npm version $INPUTS_INCREMENT --no-git-tag-version

- name: Publish to npm
run: npm publish --access public $DRY_RUN_OPTION
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

- name: Get Version
- name: get version
id: get-version
run: |
echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT
echo "new-version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT

- name: Parse CHANGELOG.md
id: parse-changelog
Expand All @@ -98,6 +126,48 @@ jobs:
version: '${{ steps.get-version.outputs.version }}'
title-regex: '^##\s+\[\d.*$'

- name: Create a GitHub release
if: ${{ github.event.inputs.dry-run == 'false' }}
uses: ncipollo/release-action@v1
with:
tag: 'v${{ steps.get-version.outputs.new-version }}'
body: '${{ steps.parse-changelog.outputs.body }}'

# add missing template to change log for new development
# -E extended mode for \s support, -i inplace
# 0,: only operate on the first match.
# & is the matched string
- name: Add version template to CHANGELOG.md
run: |
sed -i -E '0,/^##\s+.*$/s//## [Unreleased]\
\
### Added\
### Changed\
### Deprecated\
### Removed\
### Fixed\
### Security\
\
&/' CHANGELOG.md

# increment version for next development
- name: Post increment version
if: ${{ github.event.inputs.post-increment != 'none' }}
run: |
npm version $INPUTS_POST_INCREMENT --no-git-tag-version

# commit and push branch
- name: Commit changes
env:
NEW_VERSION: ${{ steps.get-version.outputs.new-version }}
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "[email protected]"

git add -u .
git commit -m "chore(version): $INPUTS_INCREMENT version $NEW_VERSION"
git push origin $BRANCH $DRY_RUN_OPTION

- name: Create a GitHub release
if: ${{ github.event.inputs.dry-run == 'false' }}
uses: ncipollo/release-action@v1
Expand Down
Loading