@@ -16,12 +16,25 @@ jobs:
1616 build :
1717 name : Build Storybooks
1818 runs-on : ubuntu-latest
19+ outputs :
20+ has_storybooks : ${{ steps.check-affected.outputs.has_storybooks || 'true' }}
1921
2022 steps :
2123 - name : Checkout repository
2224 uses : actions/checkout@v6
2325 with :
2426 ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
27+ fetch-depth : 0
28+ filter : tree:0
29+
30+ - name : Set NX_BASE and NX_HEAD for affected detection
31+ if : github.event_name == 'pull_request'
32+ run : |
33+ git fetch origin ${{ github.base_ref }}
34+ MERGE_BASE=$(git merge-base HEAD origin/${{ github.base_ref }})
35+ echo "NX_BASE=$MERGE_BASE" >> $GITHUB_ENV
36+ echo "NX_HEAD=HEAD" >> $GITHUB_ENV
37+ echo "Comparing against merge-base: $MERGE_BASE"
2538
2639 - name : Setup Node.js
2740 uses : actions/setup-node@v6
@@ -35,15 +48,36 @@ jobs:
3548 - name : Clone l10n repository
3649 run : _scripts/l10n/clone.sh
3750
38- - name : Build all Storybooks
51+ - name : Check if any projects with storybook are affected (PR)
52+ id : check-affected
53+ if : github.event_name == 'pull_request'
54+ run : |
55+ AFFECTED=$(npx nx show projects --affected -t build-storybook)
56+ if [ -z "$AFFECTED" ]; then
57+ echo "has_storybooks=false" >> $GITHUB_OUTPUT
58+ echo "No storybook projects affected"
59+ else
60+ echo "has_storybooks=true" >> $GITHUB_OUTPUT
61+ echo "Affected storybook projects:"
62+ echo "$AFFECTED"
63+ fi
64+
65+ - name : Build Storybooks for affected packages (PR)
66+ if : github.event_name == 'pull_request' && steps.check-affected.outputs.has_storybooks == 'true'
67+ run : npx nx affected -t build-storybook
68+
69+ - name : Build all Storybooks (main branch)
70+ if : github.event_name == 'push'
3971 run : npx nx run-many -t build-storybook
4072
4173 - name : Organize Storybooks for deployment
74+ if : github.event_name == 'push' || steps.check-affected.outputs.has_storybooks == 'true'
4275 run : node _scripts/organize-storybooks.js
4376 env :
4477 DEPLOY_DIR : deploy/
4578
4679 - name : Upload storybooks artifact
80+ if : github.event_name == 'push' || steps.check-affected.outputs.has_storybooks == 'true'
4781 uses : actions/upload-artifact@v6
4882 with :
4983 name : storybooks-${{ github.event_name == 'pull_request' && github.event.pull_request.number || 'main' }}
5488 name : Deploy to GitHub Pages
5589 runs-on : ubuntu-latest
5690 needs : build
91+ if : needs.build.outputs.has_storybooks == 'true'
5792 # Single concurrency group to prevent conflicts
5893 concurrency :
5994 group : gh-pages-deploy
0 commit comments