Publish React Component to NPM on Demand #180
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 React Component to NPM on Demand | |
on: workflow_dispatch | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: CD | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Setup Cognite CICD NPM | |
run: | | |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc | |
npm whoami | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
- name: Setup Cognite CICD Yarn | |
run: | | |
echo " | |
npmScopes: | |
cognite: | |
npmAlwaysAuth: true | |
npmAuthToken: \"\${NPM_TOKEN}\" | |
npmRegistryServer: "https://registry.npmjs.org" | |
" >> .yarnrc.yml | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
- name: Install NPM dependencies | |
working-directory: react-components | |
run: yarn install --immutable | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
- name: Build production version | |
working-directory: react-components | |
run: yarn run build | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
- name: Publish to NPM | |
working-directory: react-components | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npm publish |