Publish code-block publicly on npm. #131
Workflow file for this run
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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: Node.js CI | |
env: | |
NODE_VERSION: 20.x | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
publish: | |
description: 'Publish the package to npm' | |
required: true | |
type: boolean | |
default: false | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- run: yarn install | |
- run: yarn test | |
build-and-publish: | |
runs-on: ubuntu-latest | |
needs: [test] | |
if: github.ref == 'refs/heads/main' || github.event.inputs.publish == 'true' | |
strategy: | |
matrix: | |
# TODO(florian): either remove the remaining packages or handle them. | |
# package: [testing-utils, code-block, cookie-consent] | |
package: [code-block] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- run: yarn install | |
working-directory: packages/${{ matrix.package }} | |
- run: yarn build | |
working-directory: packages/${{ matrix.package }} | |
# Ideally all of the following code is handled by a GitHub action, but | |
# unfortunately the npm-publish action has issues when tagging the release. | |
- run: echo "https://registry.npmjs.org/:_authToken=${{ secrets.NPM_LEON_ACCESS_TOKEN }}" >> ~/.npmrc | |
- uses: flood-io/is-published-on-npm@v1 | |
id: is-published | |
with: | |
dir: packages/${{ matrix.package }} | |
- name: Publish new version if versions differ | |
if: ${{ steps.is-published.outputs.published == 'false' }} | |
run: yarn publish --access public | |
working-directory: packages/${{ matrix.package }} |