Skip to content

Commit ff2538f

Browse files
committed
ci: skip dev-build for documentation-only and release commits
1 parent b0ca14f commit ff2538f

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

.github/workflows/ci.yml

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,96 @@ jobs:
116116
exit-code: '1'
117117
severity: 'CRITICAL,HIGH'
118118

119+
check-build-needed:
120+
name: Check if build is needed
121+
runs-on: ubuntu-latest
122+
needs: [test]
123+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
124+
outputs:
125+
should-build: ${{ steps.check.outputs.should-build }}
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v5
129+
with:
130+
fetch-depth: 0
131+
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
132+
sha: ${{ github.event.workflow_run.head_sha || github.sha }}
133+
134+
- name: Check if build should be skipped
135+
id: check
136+
run: |
137+
# Only check for push and workflow_run events (dev-build only runs on these)
138+
if [ "${{ github.event_name }}" != "push" ] && [ "${{ github.event_name }}" != "workflow_run" ]; then
139+
echo "should-build=false" >> $GITHUB_OUTPUT
140+
exit 0
141+
fi
142+
143+
# Get the current commit SHA
144+
CURRENT_SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
145+
146+
# Get commit message from git log (works for both push and workflow_run)
147+
COMMIT_MSG=$(git log -1 --format="%s" "$CURRENT_SHA" 2>/dev/null || echo "")
148+
149+
echo "Checking commit: $CURRENT_SHA"
150+
echo "Commit message: $COMMIT_MSG"
151+
152+
# Check if it's a release commit (pattern: "chore(main): release" or similar)
153+
if echo "$COMMIT_MSG" | grep -qiE "^(chore|release|version).*(release|version|changelog)"; then
154+
echo "Skip reason: Release commit detected"
155+
echo "should-build=false" >> $GITHUB_OUTPUT
156+
exit 0
157+
fi
158+
159+
# For push events, check changed files against base branch
160+
if [ "${{ github.event_name }}" = "push" ]; then
161+
# Get the base commit (previous commit for single commits, or base of range)
162+
BASE_SHA="${{ github.event.before }}"
163+
HEAD_SHA="${{ github.event.after }}"
164+
165+
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
166+
# Initial commit or no base, check all files
167+
CHANGED_FILES=$(git ls-tree -r --name-only HEAD)
168+
else
169+
# Get list of changed files
170+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
171+
fi
172+
else
173+
# For workflow_run events, we need to compare against main branch
174+
BASE_SHA="origin/main"
175+
HEAD_SHA="$CURRENT_SHA"
176+
git fetch origin main || true
177+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" 2>/dev/null || git diff --name-only HEAD~1 HEAD)
178+
fi
179+
180+
if [ -z "$CHANGED_FILES" ]; then
181+
echo "No changed files detected, skipping build"
182+
echo "should-build=false" >> $GITHUB_OUTPUT
183+
exit 0
184+
fi
185+
186+
# Documentation file patterns to ignore
187+
DOC_PATTERNS="^README\.md$|^CHANGELOG\.md$|^docs/|\.md$|^LICENSE"
188+
189+
# Check if all changed files are documentation
190+
NON_DOC_FILES=$(echo "$CHANGED_FILES" | grep -vE "$DOC_PATTERNS" || true)
191+
192+
if [ -z "$NON_DOC_FILES" ]; then
193+
echo "Skip reason: Only documentation files changed"
194+
echo "Changed files:"
195+
echo "$CHANGED_FILES" | sed 's/^/ - /'
196+
echo "should-build=false" >> $GITHUB_OUTPUT
197+
else
198+
echo "Build needed: Non-documentation files changed"
199+
echo "Non-doc files:"
200+
echo "$NON_DOC_FILES" | sed 's/^/ - /'
201+
echo "should-build=true" >> $GITHUB_OUTPUT
202+
fi
203+
119204
dev-build:
120205
name: Development Build
121206
runs-on: ubuntu-latest
122-
needs: [test]
123-
if: github.event_name == 'push' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
207+
needs: [test, check-build-needed]
208+
if: needs.check-build-needed.outputs.should-build == 'true'
124209
permissions:
125210
contents: read
126211
packages: write

0 commit comments

Comments
 (0)