Skip to content

Publish package to NPM #29

Publish package to NPM

Publish package to NPM #29

Workflow file for this run

name: Publish package to NPM
on:
workflow_dispatch:
inputs:
release-type:
type: choice
description: 'Release type (one of): patch, minor, major'
options:
- patch
- minor
- major
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checkout project repository
- name: Checkout
uses: actions/checkout@v3
# Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.14.2
registry-url: https://registry.npmjs.org/
# Configure Git
- name: Git configuration
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
# Bump package version
- name: Bump release version
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
# Update changelog unreleased section with new version
- name: Update changelog
uses: superfaceai/release-changelog-action@v2
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.NEW_VERSION }}
operation: release
# Commit changes
- name: Commit package.json changes and create tag
run: |
git add "package.json"
git add "package-lock.json"
git add "CHANGELOG.md"
git commit -m "release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
# Publish version to public repository
- name: Publish
run: |
npm ci
npm run build
npm publish --tag ${{ env.RELEASE_TAG }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
# Push repository changes
- name: Push changes to repository
run: git push origin && git push --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Read version changelog
- id: get-changelog
name: Get version changelog
uses: superfaceai/release-changelog-action@v1
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.NEW_VERSION }}
operation: read
# Update GitHub release with changelog
- name: Update GitHub release documentation
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
body: ${{ steps.get-changelog.outputs.changelog }}
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}