Skip to content

Commit b526665

Browse files
committed
chore: Skip Code CI for non code changes
1 parent 36f1031 commit b526665

3 files changed

Lines changed: 101 additions & 76 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Single source of truth for which PR diffs should skip code CI.
19+
#
20+
# Workflows that gate jobs on "is this a real code change?" call this
21+
# composite action; every existing job downstream then uses
22+
# `if: needs.detect-changes.outputs.has_code == 'true'`. The caller is
23+
# responsible for `actions/checkout` with `fetch-depth: 0` before invoking
24+
# this action — we need full history to compute the PR diff.
25+
26+
name: 'Detect changes'
27+
description: >-
28+
Emit has_code='true' if the PR contains any changed file that does NOT
29+
match `ignore-paths`. When every changed file matches, has_code='false'
30+
and dependent jobs should report `skipped`.
31+
32+
inputs:
33+
ignore-paths:
34+
description: |
35+
Newline-separated glob patterns. If EVERY changed file in the PR
36+
matches one of these globs, has_code='false' (code CI is skipped —
37+
only dev.yml / docs*.yaml jobs run).
38+
39+
Glob syntax matches `pull_request: paths-ignore:`:
40+
** any depth
41+
* any chars within one path segment
42+
foo/bar.txt a single specific file
43+
subdir/** everything under subdir/
44+
**.png any .png file at any depth
45+
**/CHANGELOG.md CHANGELOG.md in any directory
46+
47+
To add a new entry: append one line below. To override per-workflow,
48+
pass `with: ignore-paths: |` from the caller.
49+
required: false
50+
default: |
51+
docs/**
52+
**.md
53+
.github/ISSUE_TEMPLATE/**
54+
.github/pull_request_template.md
55+
56+
outputs:
57+
has_code:
58+
description: >-
59+
'true' if at least one changed file is outside `ignore-paths`,
60+
'false' if every changed file matches one of those globs.
61+
value: ${{ steps.filter.outputs.has_code }}
62+
63+
runs:
64+
using: composite
65+
steps:
66+
- id: filter
67+
shell: bash
68+
env:
69+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
70+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
71+
IGNORE_CODE_CI_FOR_PATHS: ${{ inputs.ignore-paths }}
72+
run: |
73+
# Fail-open: if anything goes wrong, default to running every job
74+
# rather than silently skipping (which would let broken CI merge).
75+
set +e
76+
if [ -z "$BASE_SHA" ]; then
77+
echo "has_code=true" >> "$GITHUB_OUTPUT"; exit 0
78+
fi
79+
# Translate IGNORE_CODE_CI_FOR_PATHS (one glob per line) into git
80+
# pathspec excludes; `:(exclude,glob)` activates ** globbing.
81+
excludes=()
82+
while IFS= read -r pattern; do
83+
[ -n "$pattern" ] && excludes+=( ":(exclude,glob)$pattern" )
84+
done <<< "$IGNORE_CODE_CI_FOR_PATHS"
85+
# If anything remains after stripping ignored paths, the PR has
86+
# real code changes and code CI should run.
87+
diff_output=$(git diff --name-only "$BASE_SHA..$HEAD_SHA" -- "${excludes[@]}")
88+
if [ -n "$diff_output" ]; then
89+
echo "has_code=true" >> "$GITHUB_OUTPUT"
90+
else
91+
echo "has_code=false" >> "$GITHUB_OUTPUT"
92+
fi
93+
exit 0

.github/workflows/dependencies.yml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,11 @@ jobs:
4444
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
4545
with:
4646
fetch-depth: 0
47+
# Glob list and detection logic live in
48+
# .github/actions/detect-changes/action.yml (single source of truth).
49+
# To override the patterns for this workflow, pass `with: ignore-paths:`.
4750
- id: filter
48-
env:
49-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
50-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
51-
# Skip code CI on PRs whose changed files all match one of these
52-
# globs (only dev.yml / docs*.yaml jobs run in that case).
53-
#
54-
# To add a new entry: append a line below with a glob pattern.
55-
# Syntax matches `pull_request: paths-ignore:` — `**` = any depth,
56-
# `*` = any chars within one path segment. Examples:
57-
# foo/bar.txt a single specific file
58-
# subdir/** everything under subdir/
59-
# **.png any .png file at any depth
60-
# **/CHANGELOG.md CHANGELOG.md in any directory
61-
IGNORE_CODE_CI_FOR_PATHS: |
62-
docs/**
63-
**.md
64-
.github/ISSUE_TEMPLATE/**
65-
.github/pull_request_template.md
66-
run: |
67-
# Fail-open: if anything goes wrong, default to running every job
68-
# rather than silently skipping (which would let broken CI merge).
69-
set +e
70-
if [ -z "$BASE_SHA" ]; then
71-
echo "has_code=true" >> "$GITHUB_OUTPUT"; exit 0
72-
fi
73-
excludes=()
74-
while IFS= read -r pattern; do
75-
[ -n "$pattern" ] && excludes+=( ":(exclude,glob)$pattern" )
76-
done <<< "$IGNORE_CODE_CI_FOR_PATHS"
77-
diff_output=$(git diff --name-only "$BASE_SHA..$HEAD_SHA" -- "${excludes[@]}")
78-
if [ -n "$diff_output" ]; then
79-
echo "has_code=true" >> "$GITHUB_OUTPUT"
80-
else
81-
echo "has_code=false" >> "$GITHUB_OUTPUT"
82-
fi
83-
exit 0
51+
uses: ./.github/actions/detect-changes
8452

8553
depcheck:
8654
name: Circular Dependency Check

.github/workflows/rust.yml

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,47 +55,11 @@ jobs:
5555
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
5656
with:
5757
fetch-depth: 0
58+
# Glob list and detection logic live in
59+
# .github/actions/detect-changes/action.yml (single source of truth).
60+
# To override the patterns for this workflow, pass `with: ignore-paths:`.
5861
- id: filter
59-
env:
60-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
61-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
62-
# Skip code CI on PRs whose changed files all match one of these
63-
# globs (only dev.yml / docs*.yaml jobs run in that case).
64-
#
65-
# To add a new entry: append a line below with a glob pattern.
66-
# Syntax matches `pull_request: paths-ignore:` — `**` = any depth,
67-
# `*` = any chars within one path segment. Examples:
68-
# foo/bar.txt a single specific file
69-
# subdir/** everything under subdir/
70-
# **.png any .png file at any depth
71-
# **/CHANGELOG.md CHANGELOG.md in any directory
72-
IGNORE_CODE_CI_FOR_PATHS: |
73-
docs/**
74-
**.md
75-
.github/ISSUE_TEMPLATE/**
76-
.github/pull_request_template.md
77-
run: |
78-
# Fail-open: if anything goes wrong, default to running every job
79-
# rather than silently skipping (which would let broken CI merge).
80-
set +e
81-
if [ -z "$BASE_SHA" ]; then
82-
echo "has_code=true" >> "$GITHUB_OUTPUT"; exit 0
83-
fi
84-
# Translate IGNORE_CODE_CI_FOR_PATHS (one glob per line) into git
85-
# pathspec excludes; `:(exclude,glob)` activates ** globbing.
86-
excludes=()
87-
while IFS= read -r pattern; do
88-
[ -n "$pattern" ] && excludes+=( ":(exclude,glob)$pattern" )
89-
done <<< "$IGNORE_CODE_CI_FOR_PATHS"
90-
# If anything remains after stripping ignored paths, the PR has
91-
# real code changes and code CI should run.
92-
diff_output=$(git diff --name-only "$BASE_SHA..$HEAD_SHA" -- "${excludes[@]}")
93-
if [ -n "$diff_output" ]; then
94-
echo "has_code=true" >> "$GITHUB_OUTPUT"
95-
else
96-
echo "has_code=false" >> "$GITHUB_OUTPUT"
97-
fi
98-
exit 0
62+
uses: ./.github/actions/detect-changes
9963

10064
# Check crate compiles and base cargo check passes
10165
linux-build-lib:

0 commit comments

Comments
 (0)