Release SDK to NPM #4
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: Release SDK to NPM | |
on: | |
workflow_dispatch: | |
inputs: | |
channel: | |
type: choice | |
description: 'Choose the release channel/tag' | |
options: | |
- beta | |
- production | |
default: 'beta' | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Release | |
working-directory: code | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
curr_version="$(npm pkg get version | sed "s/\"//g")" | |
if [ "${{ inputs.channel }}" == "production" ]; then | |
echo "Publishing a production release: $curr_version" | |
npm i | |
npx tsc | |
npm publish | |
elif [ "${{ inputs.channel }}" == "beta" ]; then | |
suffix_pattern="-beta.[0-9]+" | |
if [[ ! "$curr_version" =~ $suffix_pattern$ ]]; then | |
version="$curr_version-beta.$(date +%s)" | |
else | |
version="$curr_version" | |
fi | |
echo "Publishing a beta release: $version" | |
npm version "$version" --allow-same-version | |
npm i | |
npx tsc | |
npm publish --tag beta | |
fi |