Skip to content

Commit 73fe180

Browse files
committed
Add a workflow to test building on pull requests
1 parent 76fa960 commit 73fe180

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Build Packages
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- pnpm-lock.yaml
9+
- packages/*
10+
11+
jobs:
12+
discover:
13+
name: Discover packages to build
14+
runs-on: ubuntu-latest
15+
outputs:
16+
packages: ${{ steps.export.outputs.packages }}
17+
steps:
18+
- name: Checking-out code
19+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Find Publishable Packages
24+
run: |
25+
packages=$(
26+
(for package in $(find ./packages -type f -name package.json -depth 2); do
27+
if [[ $(jq '.private != true' "$package") == "true" ]]; then
28+
printf '"%s"\n' $(sed -E 's|^./packages/(.*)/package.json$|\1|' <<< "$package")
29+
fi
30+
done) | jq -c --slurp '.'
31+
)
32+
printf "::debug::All packages: %s" $packages
33+
34+
- name: Find Changed Packages
35+
run: |
36+
changed=$(
37+
git diff --name-only ${{ github.base_ref }}..HEAD \
38+
| grep "packages/.*" \
39+
| sed -E 's|^packages/([^/]*).*$|"\1"|g' \
40+
| jq -c --slurp '. | unique'
41+
)
42+
printf "::debug::Changed packages: %s" $changed
43+
44+
- name: List Packages to Build
45+
id: export
46+
run: |
47+
lock_changed = $(git diff --name-only ${{ github.base_ref }}..HEAD | grep "pnpm-lock.yaml")
48+
49+
if [[ -n "$lock_changed" ]]; then
50+
echo "Build all packages"
51+
echo "packages=$packages" >> "$GITHUB_OUTPUT"
52+
exit 0
53+
fi
54+
55+
to_build=$(jq -n -c --argjson packages "$packages" --argjson changed "$changed" '$packages - ($packages - $changed)')
56+
printf "::debug::Packages to build: %s" "$to_build"
57+
echo "packages=$to_build" >> "$GITHUB_OUTPUT"
58+
59+
build:
60+
name: Build NPM packages
61+
runs-on: ubuntu-latest
62+
needs: discover
63+
if: ${{ needs.discover.outputs.packages != '[]' }}
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
package: ${{ fromJSON(needs.discover.outputs.packages) }}
68+
steps:
69+
- name: Check-out code
70+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
71+
72+
- name: Setup pnpm
73+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda #v4.1.0
74+
with:
75+
version: 10
76+
77+
- name: Setup node
78+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
79+
with:
80+
node-version-file: ".nvmrc"
81+
cache: 'pnpm'
82+
83+
- name: Install dependencies
84+
working-directory: ./packages/${{ matrix.package }}
85+
run: pnpm install
86+
87+
- name: Pack package
88+
working-directory: ./packages/${{ matrix.package }}
89+
run: pnpm pack
90+

0 commit comments

Comments
 (0)