Skip to content

Add GitHub Actions workflows for npm publishing #4

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

Merged
merged 2 commits into from
May 13, 2025
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
53 changes: 53 additions & 0 deletions .github/workflows/npm-publish-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: NPM Publish Beta

on:
push:
branches:
- develop
pull_request:
branches:
- master

jobs:
publish-beta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Generate beta version
id: beta-version
run: |
# Get the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")

# For PR: use PR number in version
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BETA_VERSION="$CURRENT_VERSION-beta.pr.${{ github.event.pull_request.number }}"
else
# For develop: use commit hash
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
BETA_VERSION="$CURRENT_VERSION-beta.$SHORT_SHA"
fi

# Set output for use in next step
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT

# Update package.json with new version
npm version $BETA_VERSION --no-git-tag-version

- name: Publish beta to npm
run: npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: NPM Publish

on:
push:
branches:
- master

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading