Skip to content
name: Node.js Package Workflow
on:
push:
branches:
- main
release:
types: [created]
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
NODE_VERSION: 18
jobs:
list-packages:
name: List packages
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.list-packages.outputs.packages }}
steps:
- uses: actions/checkout@v3
- id: list-packages
run: |
echo "packages=$(ls packages/ | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
format-and-lint:
name: Format and lint
needs: list-packages
strategy:
matrix:
package: ${{ fromJson(needs.list-packages.outputs.packages) }}
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
cache: 'yarn'
- run: corepack enable
- run: yarn workspace @lib-lib/${{ matrix.package }} install
- run: yarn workspace @lib-lib/${{ matrix.package }} format
- run: yarn workspace @lib-lib/${{ matrix.package }} lint
outputs:
package: ${{ matrix.package }}
build-and-test:
name: Build and test
needs: format-and-lint
strategy:
matrix:
package: ${{ fromJson(needs.format-and-lint.outputs.package) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
cache: 'yarn'
- run: corepack enable
- run: yarn workspace @lib-lib/${{ matrix.package }} install
- run: yarn workspace @lib-lib/${{ matrix.package }} build
- run: yarn workspace @lib-lib/${{ matrix.package }} test
outputs:
package: ${{ matrix.package }}
publish:
name: Publish
needs: build-and-test
if: github.event_name == 'release' && github.event.action == 'created'
strategy:
matrix:
package: ${{ fromJson(needs.build-and-test.outputs.package) }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
registry-url: https://npm.pkg.github.com/
cache: 'yarn'
- run: corepack enable
- run: yarn workspace @lib-lib/${{ matrix.package }} install
- run: yarn workspace @lib-lib/${{ matrix.package }} publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}