Release #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The next version to release, e.g. 0.1.0' | |
required: true | |
type: string | |
release_kind: | |
description: 'Select the release kind: major, minor, or patch' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate version format | |
id: validate_version | |
run: | | |
if ! [[ "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Invalid version format. Please use Semantic Versioning (SemVer) format, e.g., 0.1.0" | |
exit 1 | |
fi | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Check if version exists | |
id: check_version | |
run: | | |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then | |
echo "Version already exists. Aborting release." | |
exit 1 | |
fi | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Bump version | |
id: bump_version | |
run: | | |
npm version ${{ inputs.version }} --no-git-tag-version | |
- name: Commit version | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add package.json | |
git commit -m "[Release] ${{ inputs.release_kind }} v${{ inputs.version }}" | |
- name: Tag version | |
run: | | |
git tag v${{ inputs.version }} | |
- name: Push version | |
run: | | |
git branch -f released | |
git push origin released:released --force --tags |