Skip to content

Publish NPM Package #135

Publish NPM Package

Publish NPM Package #135

Workflow file for this run

name: Publish NPM Package
on:
workflow_dispatch:
inputs:
version:
description: New version
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
# push:
# branches:
# - main
jobs:
publish:
name: Publish new ${{ github.event_name == 'push' && 'patch' || github.event.inputs.version }} version
runs-on: ubuntu-latest
steps:
- name: Set version variable 📝
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "VERSION=patch" >> $GITHUB_ENV
else
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi
- name: Checkout to 'main' Branch ✔️
uses: actions/checkout@v4
- name: Use Node.js v20.x 👀
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Install dependencies using pnpm 📦
uses: pnpm/action-setup@v2
with:
version: latest
run_install: true
- name: Building Package 🏗️
run: pnpm build
- name: Setting up SSH key 🔑
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.JARVIS_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Configure git and npm with SSH key and author 🛠️
run: |
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_rsa
git config --global commit.gpgsign true
git config --global user.email "[email protected]"
git config --global user.name "Jarvis"
npm config set sign-git-tag true
- name: Delete old version tags 🔖
run: git ls-remote --tags origin | awk -F/ '/\/tags\// {print ":" $NF}' | grep -Ev "\^" | xargs -I{} git push origin {}
- name: Generate new version tag 🏷️
run: npm version $VERSION -m "🤖 Jarvis published a $VERSION version"
- name: Push new version tag to repository 🎉
run: git push --follow-tags
- name: Publishing Package 🚀
run: npm publish --access public