Skip to content

Publish NPM (Production) #34

Publish NPM (Production)

Publish NPM (Production) #34

Workflow file for this run

name: Publish NPM (Production)
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=production
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 }}
- 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
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 🛑"