Skip to content

Publish to NPM

Publish to NPM #303

Workflow file for this run

name: Publish to NPM
on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: Release Type
options:
- alpha
- release
required: true
default: alpha
upgrade_type:
type: choice
description: Upgrade Type
options:
- none
- patch
- minor
- major
required: false
default: none
dry_run:
type: boolean
description: "(Optional) Dry run"
required: false
default: false
jobs:
Publish:
name: Publish Workflow
runs-on: ubuntu-latest
steps:
- name: Check Public Release Branch
if: contains(github.event.inputs.release_type, 'release') && (github.ref != 'refs/heads/main')
run: failure("Public releases should be only done from main branch, current branch ${{ github.ref }}")
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Github
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Get tags
run: git fetch --tags
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache node modules
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Workout next version string
run: |
upgrade_type=${{ github.event.inputs.upgrade_type }}
if [ ${{ contains(github.event.inputs.upgrade_type, 'none') }} == true ]
then
upgrade_type=""
revision_upgrade=$( ${{ contains(github.event.inputs.release_type, 'alpha') }} && echo '--revision' || echo '')
echo $revision
fi
./.github/scripts/version-up.sh --${{github.event.inputs.release_type }} --$upgrade_type --apply $revision_upgrade
shell: bash
- name: Install dependencies
run: yarn install --immutable
- name: Lint
run: yarn lint
- name: Check Single Package Version Policy
run: yarn syncpack:check
- name: Get next version string
id: version
run: |
echo "NEXT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Update package.json version for pre (alpha) releases
if: contains(github.event.inputs.release_type, 'alpha')
run: |
tmp=$(mktemp)
jq '.version = "${{steps.version.outputs.NEXT_VERSION}}"' ./sdk/package.json > "$tmp" && mv "$tmp" ./sdk/package.json
- name: Build
run: export NODE_OPTIONS=--max-old-space-size=6144 && RELEASE_TYPE=${{ github.event.inputs.release_type }} yarn build
- name: Typecheck
run: yarn typecheck
- name: Test
run: yarn test
- name: Push tags
# Boolean inputs are not actually booleans, see https://github.com/actions/runner/issues/1483
if: github.event.inputs.dry_run == 'false'
run: |
echo "$(git push --tags)"
- name: Pre Release Step
if: contains(github.event.inputs.release_type, 'alpha')
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
access: public
package: ./sdk/package.json
tag: ${{ contains(github.event.inputs.release_type, 'alpha') && 'alpha' }}
dry-run: ${{ github.event.inputs.dry_run }}
- name: Authenticate NPM
if: contains(github.event.inputs.release_type, 'release')
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
- name: Release
if: contains(github.event.inputs.release_type, 'release')
run: yarn release --ci --no-increment --no-npm --no-git.push --no-git.commit $( ${{ github.event.inputs.dry_run }} && echo "--dry-run" || echo "") --github.tokenRef=${{ secrets.PLATFORM_SA_GITHUB_TOKEN }}