Publish NPM Package #36
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: Publish NPM Package | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
release_version: | |
description: "Release Version" | |
required: true | |
default: "prerelease" | |
type: choice | |
options: | |
- "prerelease" | |
- "patch" | |
- "minor" | |
- "major" | |
release_variant: | |
description: "Type of release" | |
required: true | |
default: "stable" | |
type: choice | |
options: | |
- "stable" | |
- "alpha" | |
- "beta" | |
jobs: | |
publish-gpr: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
registry-url: "https://registry.npmjs.org" | |
scope: "@layer5" | |
- name: Install Dependencies | |
run: npm ci | |
- name: Configure Git | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Update Release Version | |
env: | |
RELEASE_VERSION: ${{ inputs.release_version || 'prerelease' }} | |
RELEASE_VARIANT: ${{ inputs.release_variant || 'stable' }} | |
run: | | |
set -e | |
OLD_VERSION=$(node -e "console.log(require('./package.json').version)") | |
if [ "$RELEASE_VERSION" == "prerelease" ] && [ "$RELEASE_VARIANT" != "stable" ]; then | |
npm version "${RELEASE_VERSION}" --preid "${RELEASE_VARIANT}"; | |
elif [ "$RELEASE_VERSION" == "prerelease" ] && [ "$RELEASE_VARIANT" == "stable" ]; then | |
npm version "${RELEASE_VERSION}"; | |
elif [ "$RELEASE_VERSION" != "prerelease" ] && [ "$RELEASE_VARIANT" != "stable" ]; then | |
npm version "pre${RELEASE_VERSION}" --preid "${RELEASE_VARIANT}"; | |
else | |
npm version "${RELEASE_VERSION}"; | |
fi | |
NEW_VERSION=$(node -e "console.log(require('./package.json').version)") | |
echo "Updated Package Version" >> $GITHUB_STEP_SUMMARY | |
echo "info Old Version: ${OLD_VERSION}" >> $GITHUB_STEP_SUMMARY | |
echo "info New Version: ${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY | |
- name: Build Package | |
run: | | |
set -e | |
npm run build | |
echo "Build New Package" >> $GITHUB_STEP_SUMMARY | |
- name: Publish Package | |
run: | | |
set -e | |
npm publish --verbose | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Commit and Push Version Changes | |
run: | | |
set -e | |
git add package.json package-lock.json | |
git commit -m "chore: bump version to ${NEW_VERSION}" || echo "No changes to commit" | |
git pull --rebase | |
git push --force | |
echo "Pushed Package Changes" >> $GITHUB_STEP_SUMMARY |