From a9c357fa8bee991e0a793ca9636084e383b79522 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 25 Nov 2024 13:41:17 -0600 Subject: [PATCH] Build and publish each JS package separately in CI --- .github/workflows/typescript.yml | 44 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index 07229176..6579e44e 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -9,9 +9,26 @@ on: types: [published] jobs: - build: + detect-packages: runs-on: ubuntu-latest + outputs: + packages: ${{ steps.find-packages.outputs.packages }} + steps: + - uses: actions/checkout@v4 + - name: Find JS packages + id: find-packages + working-directory: src + run: | + PACKAGES=$(find . -name package.json -not -path "*/node_modules/*" -exec dirname {} \; | sed 's/^\.\///' | jq -R -s -c 'split("\n")[:-1]') + echo "packages=$PACKAGES" >> $GITHUB_OUTPUT + build: + needs: [detect-packages] + strategy: + matrix: + package: ${{ fromJson(needs.detect-packages.outputs.packages) }} + name: Build ${{ matrix.package }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -20,14 +37,24 @@ jobs: node-version: 18 cache: npm - - run: npm ci - - run: npm run build + - name: Install dependencies + working-directory: src/${{ matrix.package }} + run: npm ci + + - name: Build package + working-directory: src/${{ matrix.package }} + run: npm run build publish: runs-on: ubuntu-latest + needs: [build, detect-packages] if: github.event_name == 'release' environment: release - needs: build + + strategy: + matrix: + package: ${{ fromJson(needs.detect-packages.outputs.packages) }} + name: Publish ${{ matrix.package }} permissions: contents: read @@ -41,9 +68,12 @@ jobs: cache: npm registry-url: "https://registry.npmjs.org" - - run: npm ci + - name: Install dependencies + working-directory: src/${{ matrix.package }} + run: npm ci - # TODO: Add --provenance once the repo is public - - run: npm run publish-all + - name: Publish package + working-directory: src/${{ matrix.package }} + run: npm publish --provenance env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}