Skip to content

Commit 4ab17ed

Browse files
committed
Skip unnecessary rebuilds when no dependencies changed
Add a check step to the rebuild workflow that compares the last commit touching dependency files against the last dist build commit. If no dependency files changed since the last rebuild, all subsequent steps are skipped, avoiding unnecessary install and build cycles.
1 parent 3037d17 commit 4ab17ed

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

.github/workflows/rebuild.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,39 @@ jobs:
2121
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
2222
with:
2323
node-version: 22
24+
- name: Check if rebuild needed
25+
id: check
26+
run: |
27+
LAST_BUILD=$(git log -1 --format=%H -- ui/extensions/hello/src/dist/)
28+
if [ -z "$LAST_BUILD" ]; then
29+
echo "skip=false" >> "$GITHUB_OUTPUT"
30+
echo "No previous build found, rebuilding"
31+
exit 0
32+
fi
33+
CHANGES=$(git diff --name-only "$LAST_BUILD" HEAD -- ui/extensions/hello/package.json ui/extensions/hello/package-lock.json)
34+
if [ -z "$CHANGES" ]; then
35+
echo "skip=true" >> "$GITHUB_OUTPUT"
36+
echo "No dependency changes since last build, skipping"
37+
else
38+
echo "skip=false" >> "$GITHUB_OUTPUT"
39+
echo "Dependency changes detected:"
40+
echo "$CHANGES"
41+
fi
2442
- name: Install dependencies
43+
if: steps.check.outputs.skip != 'true'
2544
run: npm ci
2645
working-directory: ui/extensions/hello
2746
- name: Build React app
47+
if: steps.check.outputs.skip != 'true'
2848
run: npm run build
2949
working-directory: ui/extensions/hello
3050
- name: Create commit
51+
if: steps.check.outputs.skip != 'true'
3152
run: |
3253
git add .
3354
git commit -a -m "Rebuild UI with latest dependencies" || true
3455
- name: Create Pull Request
56+
if: steps.check.outputs.skip != 'true'
3557
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11
3658
with:
3759
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)