Skip to content

Commit 9d058a9

Browse files
davsclausclaude
andauthored
fix(#1650): skip PR builds when only draft blog posts changed (#1654)
Adds a detect-drafts job that checks if all changed files belong to draft blog posts. If so, the full build/checks/preview pipeline is skipped entirely. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7804de3 commit 9d058a9

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,49 @@ env:
2828
HUGO_OPTIONS: '--buildFuture'
2929

3030
jobs:
31+
detect-drafts:
32+
runs-on: ubuntu-latest
33+
outputs:
34+
drafts-only: ${{ steps.check.outputs.drafts-only }}
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v5
38+
- name: Check if PR only changes draft blog posts
39+
id: check
40+
run: |
41+
CHANGED=$(gh pr diff ${{ github.event.pull_request.number }} --name-only)
42+
DRAFTS_ONLY=true
43+
for file in $CHANGED; do
44+
case "$file" in
45+
content/blog/*/index.md)
46+
if ! grep -q '^draft: true' "$file" 2>/dev/null; then
47+
DRAFTS_ONLY=false
48+
break
49+
fi
50+
;;
51+
content/blog/*)
52+
# assets (images, SVGs) alongside a draft post are fine
53+
dir=$(dirname "$file")
54+
index="$dir/index.md"
55+
if [ ! -f "$index" ] || ! grep -q '^draft: true' "$index" 2>/dev/null; then
56+
DRAFTS_ONLY=false
57+
break
58+
fi
59+
;;
60+
*)
61+
DRAFTS_ONLY=false
62+
break
63+
;;
64+
esac
65+
done
66+
echo "drafts-only=$DRAFTS_ONLY" >> "$GITHUB_OUTPUT"
67+
echo "Drafts only: $DRAFTS_ONLY"
68+
env:
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
3171
checks:
72+
needs: detect-drafts
73+
if: needs.detect-drafts.outputs.drafts-only != 'true'
3274
runs-on: ubuntu-latest
3375
steps:
3476
- name: Checkout

0 commit comments

Comments
 (0)