Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workflow for publishing npm package #260

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ on:
push:
branches:
- 'main'
- 'development'
pull_request:
branches:
- 'main'
- 'development'
workflow_dispatch:
jobs:
build:
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish NPM

on:
workflow_dispatch:
inputs:
dry-run:
type: boolean
default: true
description: Dry run publish
dist-tag:
type: choice
options:
- dev
- latest
default: dev
description: Npm dist tag
jobs:
publish:
name: Publish NPM
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Set package name from vars
if: ${{ vars.NPM_PACKAGE_NAME }}
run: |
cat package.json | jq -r '.name = "${{ vars.NPM_PACKAGE_NAME }}"' > package.json.tmp
mv package.json.tmp package.json

- name: Set version from commit
lenkan marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ inputs.dist-tag == 'dev' }}
run: |
npm version --no-git-tag-version $(cat package.json | jq .version -r)-dev.$(git rev-parse --short HEAD)

- name: Create git tag
run: git tag $(cat package.json | jq .version -r)

- name: Publish dev package (Dry run)
if: ${{ inputs.dry-run == true }}
run: npm publish --tag "${{ inputs.dist-tag }}" --dry-run

- name: Publish dev package
if: ${{ inputs.dry-run == false }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm publish --tag "${{ inputs.dist-tag }}"
git tag v$(cat package.json | jq .version -r)
git push origin v$(cat package.json | jq .version -r)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"types": "./dist/index.d.ts",
"type": "module",
"files": [
"dist"
"dist",
"src"
],
"scripts": {
"start": "npm run build:esm -- --watch",
Expand Down
Loading