Skip to content

Publish NPM (Canary) #123

Publish NPM (Canary)

Publish NPM (Canary) #123

Workflow file for this run

name: Publish NPM (Canary)
on:
workflow_dispatch:
branches:
- 'release/*'
jobs:
publish-npm-package:
runs-on: ubuntu-latest
outputs:
release_track: ${{ steps.set-variables.outputs.release_track }}
pkg_version: ${{ steps.set-variables.outputs.pkg_version }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
registry-url: "https://registry.npmjs.org"
# Defaults to the user or organization that owns the workflow file
scope: "@perp"
# See: https://github.com/actions/cache/blob/main/examples.md#node---yarn
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
- name: Set variables
id: set-variables
run: |
RELEASE_TRACK=canary
PKG_VERSION=$(npm pkg get version | sed 's/"//g')
echo "release_track=$RELEASE_TRACK" >> $GITHUB_OUTPUT
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
- name: Build package
run: yarn build
env:
TRACK: ${{ steps.set-variables.outputs.release_track }}
# update package.json version, add CHANGELOG & commit changes
- name: Publish package
id: publish-package
run: |
echo track: ${{ steps.set-variables.outputs.release_track }}
echo version: ${{ steps.set-variables.outputs.pkg_version }}
yarn release --tag ${{ steps.set-variables.outputs.release_track }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Git push version tag
run: |
PKG_VERSION=${{ steps.set-variables.outputs.pkg_version }}
git tag $PKG_VERSION
git push origin $PKG_VERSION
discord-notification-npm-package:
name: Discord Notification for publishing npm package
if: ${{ always() }}
needs: [publish-npm-package]
runs-on: ubuntu-latest
steps:
- name: issue success notification
if: needs.publish-npm-package.result == 'success'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "**[@perp/sdk-curie: ${{ needs.publish-npm-package.outputs.release_track }}]** @perp/sdk-curie version: **${{ needs.publish-npm-package.outputs.pkg_version }}** published successfully ✅"
- name: issue failure notification
if: needs.publish-npm-package.result != 'success'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "**[@perp/sdk-curie: ${{ needs.publish-npm-package.outputs.release_track }}]** @perp/sdk-curie version: **${{ needs.publish-npm-package.outputs.pkg_version }}** failed to publish 🛑"