NPM Publish #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: NPM Publish | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
inputs: | |
action: | |
type: choice | |
description: Select action to excute | |
options: | |
- Release | |
- Dry-run | |
default: Dry-run | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
jobs: | |
cancel-previous: | |
name: 'Cancel Previous Runs' | |
runs-on: ubuntu-latest | |
timeout-minutes: 3 | |
steps: | |
- uses: styfle/cancel-workflow-action@0.12.0 | |
with: | |
access_token: ${{ github.token }} | |
semantic-version: | |
name: Semantic release | |
runs-on: ubuntu-latest | |
needs: [cancel-previous] | |
timeout-minutes: 2 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Bump version and push tag | |
id: tag_version | |
uses: mathieudutour/github-tag-action@v6.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
custom_release_rules: major:major:Major Changes,minor:minor:Minor Changes,chore:patch:Chores | |
dry_run: ${{ github.event.inputs.action != 'Release' }} | |
outputs: | |
new_version: ${{ steps.tag_version.outputs.new_version }} | |
publish: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
needs: [cancel-previous, semantic-version] | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} # used to work for npm publish, but stopped working | |
NPM_TOKEN: ${{secrets.NPM_TOKEN}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18.19 | |
- name: Install dependencies | |
run: npm ci | |
- name: Run build | |
run: npm run build | |
- name: Bump package version | |
run: | | |
git config user.email "devops@energyweb.org" | |
git config user.name "ewf-devops" | |
npm version "${{ needs.semantic-version.outputs.new_version }}" | |
- name: Publish to NPM | |
run: | | |
if [[ "${{ github.event.inputs.action }}" == 'Release' ]]; then | |
npm publish --access public | |
else | |
npm publish --access public --dry-run | |
fi |