Release Workflow #1
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 Workflow | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseType: | |
description: 'Release Type' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
draft: | |
description: 'Create a draft release' | |
required: false | |
default: false | |
type: boolean | |
prerelease: | |
description: 'Mark release as a prerelease' | |
required: false | |
default: false | |
type: boolean | |
releaseMessage: | |
description: 'Release Message' | |
required: false | |
default: '' | |
type: string | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '14' | |
- name: Fetch tags | |
run: git fetch --depth=1 --tags | |
- name: Get latest tag or set default | |
id: latest_tag | |
run: | | |
TAG=$(git tag -l --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
if [ -z "$TAG" ]; then | |
TAG="0.0.0" | |
fi | |
echo "::set-output name=tag::$TAG" | |
- name: Create dummy package.json | |
run: | | |
echo "{\"version\": \"${{ steps.latest_tag.outputs.tag }}\"}" > package.json | |
cat package.json | |
- name: Calculate next version | |
id: next_version | |
run: | | |
npm --no-git-tag-version version ${{ github.event.inputs.releaseType }} | |
NEXT_VERSION=$(node -p "require('./package.json').version") | |
echo "Next version: $NEXT_VERSION" | |
echo "::set-output name=version::$NEXT_VERSION" | |
- name: Create Git tag | |
run: git tag ${{ steps.next_version.outputs.version }} | |
- name: Push Git tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git push origin ${{ steps.next_version.outputs.version }} | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.next_version.outputs.version }} | |
release_name: Release v${{ steps.next_version.outputs.version }} | |
body: ${{ github.event.inputs.releaseMessage }} | |
draft: ${{ github.event.inputs.draft }} | |
prerelease: ${{ github.event.inputs.prerelease }} |