Skip to content

Commit c51ffa2

Browse files
markkovariclaude
andauthored
chore/run only tests where changes where (#10)
* fix: resolve Go test failures in 2019 and 2024 (#9) * fix: resolve Go test failures in 2019 and 2024 - Remove unused 'errors' import in 2024/golang/cmd/04.go - Add filepath parameter to readCommands() function in 2019/go/cmd/15 to match test expectations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: replace deprecated drain_filter with stable alternative in 2021/_4 - Remove unstable feature flag #![feature(drain_filter)] - Replace drain_filter with iter_mut + retain pattern - All Rust tests in 2021 now compile and pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: markkovari <kovarimarkofficial@gmail.com> * docs: add README rocket * fix: prevent empty matrix values when no projects change When only non-code files (like README.md) change, the change detection was outputting [""] instead of []. This caused jobs to run with empty matrix values, leading to failures: - cargo test failing with "could not find Cargo.toml" - dotnet restore failing with "no project or solution file" Now properly outputs [] when no projects are detected, preventing jobs from running with empty matrix values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Signed-off-by: markkovari <kovarimarkofficial@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent e9e2d96 commit c51ffa2

File tree

2 files changed

+96
-21
lines changed

2 files changed

+96
-21
lines changed

.github/workflows/tests.yml

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,101 @@ on:
1010
- main
1111

1212
jobs:
13+
detect_changes:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
rust_projects: ${{ steps.filter.outputs.rust_projects }}
17+
go_projects: ${{ steps.filter.outputs.go_projects }}
18+
csharp_projects: ${{ steps.filter.outputs.csharp_projects }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Detect changed projects
24+
id: filter
25+
run: |
26+
# Get changed files
27+
if [ "${{ github.event_name }}" == "pull_request" ]; then
28+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
29+
else
30+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
31+
fi
32+
33+
echo "Changed files:"
34+
echo "$CHANGED_FILES"
35+
36+
# Define all projects
37+
ALL_RUST_PROJECTS=("2015" "2018" "2019/aoc_rust" "2020/01" "2021/_1" "2021/_2" "2021/_3" "2021/_4" "2021/_5" "2021/_6" "2021/_7" "2022")
38+
ALL_GO_PROJECTS=("2017" "2019/go" "2020/02" "2024/golang")
39+
ALL_CSHARP_PROJECTS=("2021/cs/1" "2021/cs/2")
40+
41+
# Check for workflow changes - if workflow changed, run all tests
42+
if echo "$CHANGED_FILES" | grep -q "^.github/workflows/tests.yml"; then
43+
echo "Workflow changed, running all tests"
44+
RUST_PROJECTS=$(printf '%s\n' "${ALL_RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
45+
GO_PROJECTS=$(printf '%s\n' "${ALL_GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
46+
CSHARP_PROJECTS=$(printf '%s\n' "${ALL_CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
47+
else
48+
# Detect Rust projects
49+
RUST_PROJECTS=()
50+
for project in "${ALL_RUST_PROJECTS[@]}"; do
51+
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
52+
RUST_PROJECTS+=("$project")
53+
fi
54+
done
55+
56+
# Detect Go projects
57+
GO_PROJECTS=()
58+
for project in "${ALL_GO_PROJECTS[@]}"; do
59+
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
60+
GO_PROJECTS+=("$project")
61+
fi
62+
done
63+
64+
# Detect C# projects
65+
CSHARP_PROJECTS=()
66+
for project in "${ALL_CSHARP_PROJECTS[@]}"; do
67+
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
68+
CSHARP_PROJECTS+=("$project")
69+
fi
70+
done
71+
72+
if [ ${#RUST_PROJECTS[@]} -eq 0 ]; then
73+
RUST_PROJECTS="[]"
74+
else
75+
RUST_PROJECTS=$(printf '%s\n' "${RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
76+
fi
77+
78+
if [ ${#GO_PROJECTS[@]} -eq 0 ]; then
79+
GO_PROJECTS="[]"
80+
else
81+
GO_PROJECTS=$(printf '%s\n' "${GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
82+
fi
83+
84+
if [ ${#CSHARP_PROJECTS[@]} -eq 0 ]; then
85+
CSHARP_PROJECTS="[]"
86+
else
87+
CSHARP_PROJECTS=$(printf '%s\n' "${CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
88+
fi
89+
fi
90+
91+
echo "rust_projects=$RUST_PROJECTS" >> $GITHUB_OUTPUT
92+
echo "go_projects=$GO_PROJECTS" >> $GITHUB_OUTPUT
93+
echo "csharp_projects=$CSHARP_PROJECTS" >> $GITHUB_OUTPUT
94+
95+
echo "Rust projects to test: $RUST_PROJECTS"
96+
echo "Go projects to test: $GO_PROJECTS"
97+
echo "C# projects to test: $CSHARP_PROJECTS"
98+
1399
rust_tests:
100+
needs: detect_changes
101+
if: needs.detect_changes.outputs.rust_projects != '[]'
14102
runs-on: ubuntu-latest
15103
continue-on-error: true
16104
strategy:
17105
fail-fast: false
18106
matrix:
19-
project:
20-
- 2015
21-
- 2018
22-
- 2019/aoc_rust
23-
- 2020/01
24-
- 2021/_1
25-
- 2021/_2
26-
- 2021/_3
27-
- 2021/_4
28-
- 2021/_5
29-
- 2021/_6
30-
- 2021/_7
31-
- 2022
107+
project: ${{ fromJson(needs.detect_changes.outputs.rust_projects) }}
32108
steps:
33109
- uses: actions/checkout@v4
34110
- name: Install Rust Stable
@@ -53,16 +129,14 @@ jobs:
53129
working-directory: ${{ matrix.project }}
54130

55131
go_tests:
132+
needs: detect_changes
133+
if: needs.detect_changes.outputs.go_projects != '[]'
56134
runs-on: ubuntu-latest
57135
continue-on-error: true
58136
strategy:
59137
fail-fast: false
60138
matrix:
61-
project:
62-
- 2017
63-
- 2019/go
64-
- 2020/02
65-
- 2024/golang
139+
project: ${{ fromJson(needs.detect_changes.outputs.go_projects) }}
66140
steps:
67141
- uses: actions/checkout@v4
68142
- name: Set up Go
@@ -87,14 +161,14 @@ jobs:
87161
working-directory: 2024/golang
88162

89163
csharp_tests:
164+
needs: detect_changes
165+
if: needs.detect_changes.outputs.csharp_projects != '[]'
90166
runs-on: ubuntu-latest
91167
continue-on-error: true
92168
strategy:
93169
fail-fast: false
94170
matrix:
95-
project:
96-
- 2021/cs/1
97-
- 2021/cs/2
171+
project: ${{ fromJson(needs.detect_changes.outputs.csharp_projects) }}
98172
steps:
99173
- uses: actions/checkout@v4
100174
- name: Set up .NET

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Advent of Code collection
22

3+
LETSGOO :rocket:

0 commit comments

Comments
 (0)