Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vighnesh153/d4079043ac2a3434fb279723c5499694 to your computer and use it in GitHub Desktop.
Save vighnesh153/d4079043ac2a3434fb279723c5499694 to your computer and use it in GitHub Desktop.
name: nodejs-publish
on:
workflow_dispatch:
inputs:
shouldUpdateVersion:
required: true
type: choice
description: Update the version?
default: "false"
options:
- true
- false
shouldGitTag:
required: true
type: choice
description: Create a tag commit?
default: "false"
options:
- true
- false
shouldPublishToNPM:
required: true
type: choice
description: Publish to NPM
default: "false"
options:
- true
- false
newVersion:
required: true
description: Specify the new version (if not updating, specify the current one)
publishArgs:
required: false
description: customize the arguments passed to 'npm publish'
default: "--workspace nodejs-packages --tag latest"
jobs:
nodejs-publish:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./nodejs-tools
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup nodejs
uses: actions/setup-node@v3
with:
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"
- name: install dependencies in nodejs-tools
run: npm ci
- name: build packages
run: npm run build -- --filter=./nodejs-packages/*
- name: Config git metadata
run: |
git config --global user.name 'Vighnesh Raut'
git config --global user.email '[email protected]'
- name: Update the version in the packages
if: ${{ inputs.shouldUpdateVersion == 'true' }}
run: |
npm version ${{ inputs.newVersion }} --git-tag-version=false --allow-same-version=true --workspace=./nodejs-packages
git add .
git commit -m "build: update the npm version to ${{ inputs.newVersion }}" --no-verify
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish the packages
if: ${{ inputs.shouldPublishToNPM == 'true' }}
run: |
npm run changeStarToSpecificVersion
GIT_PAGER=cat git diff
npm publish ${{ inputs.publishArgs }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a git tag and push
if: ${{ inputs.shouldGitTag == 'true' }}
run: |
git tag v${{ inputs.newVersion }}
git push --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment