Skip to content

Publish Package to npm #7

Publish Package to npm

Publish Package to npm #7

Workflow file for this run

name: Publish Package to npm
on:
release:
types: [published]
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.repository.default_branch }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Update package.json with release tag
run: |
TAG="${{ github.event.release.tag_name }}"
echo "Updating package.json version to $TAG"
npm version "$TAG" --no-git-tag-version --allow-same-version
- name: Commit and push version update
run: |
TAG="${{ github.event.release.tag_name }}"
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add package.json package-lock.json
git commit -m "Update package.json to version $TAG"
git push origin ${{ github.event.repository.default_branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build TypeScript
run: |
npx tsc --target es2018 --module commonjs --declaration --outDir ./dist --strict --esModuleInterop --skipLibCheck --forceConsistentCasingInFileNames src/**/*.ts
ls -la dist/
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}