[WTF-2433]: Fix build before publish #1
Workflow file for this run
This file contains hidden or 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: Build Packages | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| paths: | |
| - pnpm-lock.yaml | |
| - packages/** | |
| jobs: | |
| discover: | |
| name: Discover packages to build | |
| runs-on: ubuntu-latest | |
| outputs: | |
| packages: ${{ steps.export.outputs.packages }} | |
| steps: | |
| - name: Checking-out code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Find Publishable Packages | |
| run: | | |
| packages=$( | |
| (for package in $(find ./packages -type f -name package.json -depth 2); do | |
| if [[ $(jq '.private != true' "$package") == "true" ]]; then | |
| printf '"%s"\n' $(sed -E 's|^./packages/(.*)/package.json$|\1|' <<< "$package") | |
| fi | |
| done) | jq -c --slurp '.' | |
| ) | |
| printf "::debug::All packages: %s" $packages | |
| - name: Find Changed Packages | |
| run: | | |
| changed=$( | |
| git diff --name-only ${{ github.base_ref }}..HEAD \ | |
| | grep "packages/.*" \ | |
| | sed -E 's|^packages/([^/]*).*$|"\1"|g' \ | |
| | jq -c --slurp '. | unique' | |
| ) | |
| printf "::debug::Changed packages: %s" $changed | |
| - name: List Packages to Build | |
| id: export | |
| run: | | |
| lock_changed = $(git diff --name-only ${{ github.base_ref }}..HEAD | grep "pnpm-lock.yaml") | |
| if [[ -n "$lock_changed" ]]; then | |
| echo "Build all packages" | |
| echo "packages=$packages" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| to_build=$(jq -n -c --argjson packages "$packages" --argjson changed "$changed" '$packages - ($packages - $changed)') | |
| printf "::debug::Packages to build: %s" "$to_build" | |
| echo "packages=$to_build" >> "$GITHUB_OUTPUT" | |
| build: | |
| name: Build NPM packages | |
| runs-on: ubuntu-latest | |
| needs: discover | |
| if: ${{ needs.discover.outputs.packages != '[]' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJSON(needs.discover.outputs.packages) }} | |
| steps: | |
| - name: Check-out code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda #v4.1.0 | |
| with: | |
| version: 10 | |
| - name: Setup node | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version-file: ".nvmrc" | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| working-directory: ./packages/${{ matrix.package }} | |
| run: pnpm install | |
| - name: Pack package | |
| working-directory: ./packages/${{ matrix.package }} | |
| run: pnpm pack | |