Manual Release and Publish #8
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: Publish to NPM and Create Release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Update type (major, minor, patch)' | |
required: true | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Validate version input | |
run: | | |
if [[ "${{ github.event.inputs.version }}" =~ ^(major|minor|patch)$ ]]; then | |
echo "Valid version input" | |
else | |
echo "Invalid version input: ${{ github.event.inputs.version }}" | |
exit 1 | |
fi | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
- name: Bump version | |
id: bump_version | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
VERSION=$(npm version ${{ github.event.inputs.version }}) | |
echo "$VERSION" > VERSION.txt | |
git add . | |
git commit -am "chore(release): $VERSION" | |
git push | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.bump_version.outputs.version }} | |
release_name: Release ${{ steps.bump_version.outputs.version }} | |
draft: false | |
prerelease: false | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} |