Merge pull request #2 from ensuro/npm-action #1
Workflow file for this run
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 Package | |
on: | |
push: | |
branches-ignore: | |
- "**" | |
tags: | |
- v* | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Package version" | |
required: true | |
tag: | |
description: "Package tag" | |
required: true | |
default: "latest" | |
type: choice | |
options: | |
- latest | |
- beta | |
jobs: | |
npm-upload: | |
name: NPM Package Build and Upload | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: "20" | |
cache: "npm" | |
- run: npm ci | |
- run: npm run build:lib # create the ./lib directory with the files to publish | |
- run: sed "s/%%VERSION%%/$VERSION/" package.json > "./lib/package.json" | |
- id: semver | |
run: | | |
SEMVER="${{ github.event.inputs.version }}" | |
if [ -z "$SEMVER" ]; then | |
# No manual input, we must be running on a tag | |
SEMVER="${GITHUB_REF/refs\/tags\/v/}" | |
fi | |
echo "::set-output name=semver::${SEMVER}" | |
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN }}" > ./lib/.npmrc | |
- run: | | |
RELEASE_TAG="${{ github.event.inputs.tag }}" | |
if [ -z "$RELEASE_TAG" ]; then | |
if grep -q -- '-beta' <<< "${{ steps.semver.outputs.semver }}"; then | |
RELEASE_TAG=beta | |
else | |
# No manual input, we must be running on a tag | |
RELEASE_TAG=latest | |
fi | |
fi | |
npm publish --tag "$RELEASE_TAG" --access public | |
working-directory: ./lib |