Skip to content

Commit c6581eb

Browse files
Fix change detection reference for PRs that have merged- ie CI running on main should use HEAD-1 as the reference because HEAD is the current change
1 parent 54cd15b commit c6581eb

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

.github/scripts/parse-affected-targets.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ def generate_matrix_json(targets: List[str]) -> str:
196196

197197
def main():
198198
if len(sys.argv) < 3:
199-
print(f"Usage: {sys.argv[0]} <btd_output.json> <output_dir>", file=sys.stderr)
199+
print(f"Usage: {sys.argv[0]} <btd_output.json> <output_dir> [--fallback]", file=sys.stderr)
200200
sys.exit(1)
201201

202202
btd_json = sys.argv[1]
203203
output_dir = Path(sys.argv[2])
204+
fallback = '--fallback' in sys.argv
204205
output_dir.mkdir(parents=True, exist_ok=True)
205206

206207
# Get all targets from BXL/cquery
@@ -211,10 +212,15 @@ def main():
211212
print("Parsing BTD output...", file=sys.stderr)
212213
affected_targets = parse_btd_output(btd_json)
213214

214-
# If BTD returned no targets (fallback case), run everything
215-
if len(affected_targets) == 0:
216-
print("No affected targets from BTD (fallback mode) - running all targets", file=sys.stderr)
215+
# Only fall back to running everything when BTD itself failed
216+
# (indicated by --fallback); zero targets from a successful BTD
217+
# run means nothing was affected.
218+
if fallback:
219+
print("BTD failed (--fallback) - running all targets", file=sys.stderr)
217220
affected_by_category = all_targets
221+
affected_targets = set()
222+
for targets in all_targets.values():
223+
affected_targets.update(targets)
218224
else:
219225
# Filter to affected only
220226
affected_by_category = filter_affected(all_targets, affected_targets)

.github/workflows/build.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ jobs:
3636
- name: Get changed files and base commit
3737
id: changed-files
3838
run: |
39-
# Always compare against origin/main to detect all changes in the branch
40-
BASE_COMMIT="origin/main"
39+
# On main (post-merge), compare against the previous commit;
40+
# on branches, compare against origin/main to detect all changes.
41+
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
42+
BASE_COMMIT="HEAD~1"
43+
else
44+
BASE_COMMIT="origin/main"
45+
fi
4146
4247
# Generate list of changed files in BTD format: "M path/to/file"
4348
# BTD expects Mercurial-like format with status code (M/A/D) and space separator
@@ -95,6 +100,7 @@ jobs:
95100
echo "Found $TARGETS affected targets"
96101
echo "BTD output preview:"
97102
head -20 /tmp/btd_output.json || true
103+
echo "succeeded=true" >> "$GITHUB_OUTPUT"
98104
else
99105
EXIT_CODE=$?
100106
echo "::error::BTD command failed with exit code $EXIT_CODE"
@@ -103,24 +109,30 @@ jobs:
103109
echo "BTD stderr:"
104110
cat /tmp/btd_stderr.txt || echo "No stderr file generated"
105111
echo "::warning::BTD failed, will run all targets"
106-
echo '{"targets": []}' > /tmp/btd_output.json
112+
echo '[]' > /tmp/btd_output.json
113+
echo "succeeded=false" >> "$GITHUB_OUTPUT"
107114
fi
108115
else
109116
echo "::warning::supertd not installed, will run all targets"
110117
echo "PATH: $PATH"
111-
# Fallback: empty targets means run everything
112-
echo '{"targets": []}' > /tmp/btd_output.json
118+
echo '[]' > /tmp/btd_output.json
119+
echo "succeeded=false" >> "$GITHUB_OUTPUT"
113120
fi
114121
115122
- name: Parse affected targets
116123
id: parse
117124
run: |
118125
mkdir -p /tmp/btd_results
119126
120-
# Run parser script
127+
# Run parser script; --fallback means BTD failed so run everything
128+
FALLBACK_FLAG=""
129+
if [ "${{ steps.btd.outputs.succeeded }}" != "true" ]; then
130+
FALLBACK_FLAG="--fallback"
131+
fi
132+
121133
python3 .github/scripts/parse-affected-targets.py \
122134
/tmp/btd_output.json \
123-
/tmp/btd_results || {
135+
/tmp/btd_results $FALLBACK_FLAG || {
124136
echo "::warning::Parser failed, creating empty matrices"
125137
# Create empty matrices on failure
126138
for matrix in vunit_matrix bsv_test_matrix ice40_matrix ecp5_matrix vivado_matrix; do

.github/workflows/simulation.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ jobs:
3333
- name: Get changed files and base commit
3434
id: changed-files
3535
run: |
36-
# Always compare against origin/main to detect all changes in the branch
37-
BASE_COMMIT="origin/main"
36+
# On main (post-merge), compare against the previous commit;
37+
# on branches, compare against origin/main to detect all changes.
38+
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
39+
BASE_COMMIT="HEAD~1"
40+
else
41+
BASE_COMMIT="origin/main"
42+
fi
3843
3944
# Generate list of changed files in BTD format: "M path/to/file"
4045
# BTD expects Mercurial-like format with status code (M/A/D) and space separator
@@ -92,6 +97,7 @@ jobs:
9297
echo "Found $TARGETS affected targets"
9398
echo "BTD output preview:"
9499
head -20 /tmp/btd_output.json || true
100+
echo "succeeded=true" >> "$GITHUB_OUTPUT"
95101
else
96102
EXIT_CODE=$?
97103
echo "::error::BTD command failed with exit code $EXIT_CODE"
@@ -100,24 +106,30 @@ jobs:
100106
echo "BTD stderr:"
101107
cat /tmp/btd_stderr.txt || echo "No stderr file generated"
102108
echo "::warning::BTD failed, will run all targets"
103-
echo '{"targets": []}' > /tmp/btd_output.json
109+
echo '[]' > /tmp/btd_output.json
110+
echo "succeeded=false" >> "$GITHUB_OUTPUT"
104111
fi
105112
else
106113
echo "::warning::supertd not installed, will run all targets"
107114
echo "PATH: $PATH"
108-
# Fallback: empty targets means run everything
109-
echo '{"targets": []}' > /tmp/btd_output.json
115+
echo '[]' > /tmp/btd_output.json
116+
echo "succeeded=false" >> "$GITHUB_OUTPUT"
110117
fi
111118
112119
- name: Parse affected targets
113120
id: parse
114121
run: |
115122
mkdir -p /tmp/btd_results
116123
117-
# Run parser script
124+
# Run parser script; --fallback means BTD failed so run everything
125+
FALLBACK_FLAG=""
126+
if [ "${{ steps.btd.outputs.succeeded }}" != "true" ]; then
127+
FALLBACK_FLAG="--fallback"
128+
fi
129+
118130
python3 .github/scripts/parse-affected-targets.py \
119131
/tmp/btd_output.json \
120-
/tmp/btd_results || {
132+
/tmp/btd_results $FALLBACK_FLAG || {
121133
echo "::warning::Parser failed, creating empty matrices"
122134
# Create empty matrices on failure
123135
for matrix in vunit_matrix bsv_test_matrix ice40_matrix ecp5_matrix vivado_matrix; do

0 commit comments

Comments
 (0)