1616 rust_projects : ${{ steps.filter.outputs.rust_projects }}
1717 go_projects : ${{ steps.filter.outputs.go_projects }}
1818 csharp_projects : ${{ steps.filter.outputs.csharp_projects }}
19+ zig_projects : ${{ steps.filter.outputs.zig_projects }}
1920 steps :
2021 - uses : actions/checkout@v4
2122 with :
2728 if [ "${{ github.event_name }}" == "pull_request" ]; then
2829 CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
2930 else
30- CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
31+ # Handle first push or null before hash
32+ BEFORE="${{ github.event.before }}"
33+ if [ "$BEFORE" == "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then
34+ # Get files changed in the last commit
35+ CHANGED_FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null || git ls-files)
36+ else
37+ CHANGED_FILES=$(git diff --name-only $BEFORE ${{ github.sha }})
38+ fi
3139 fi
3240
3341 echo "Changed files:"
@@ -37,13 +45,15 @@ jobs:
3745 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")
3846 ALL_GO_PROJECTS=("2017" "2019/go" "2020/02" "2024/golang")
3947 ALL_CSHARP_PROJECTS=("2021/cs/1" "2021/cs/2")
48+ ALL_ZIG_PROJECTS=("2024/zig")
4049
4150 # Check for workflow changes - if workflow changed, run all tests
4251 if echo "$CHANGED_FILES" | grep -q "^.github/workflows/tests.yml"; then
4352 echo "Workflow changed, running all tests"
4453 RUST_PROJECTS=$(printf '%s\n' "${ALL_RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
4554 GO_PROJECTS=$(printf '%s\n' "${ALL_GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
4655 CSHARP_PROJECTS=$(printf '%s\n' "${ALL_CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
56+ ZIG_PROJECTS=$(printf '%s\n' "${ALL_ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
4757 else
4858 # Detect Rust projects
4959 RUST_PROJECTS=()
6979 fi
7080 done
7181
82+ # Detect Zig projects
83+ ZIG_PROJECTS=()
84+ for project in "${ALL_ZIG_PROJECTS[@]}"; do
85+ if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
86+ ZIG_PROJECTS+=("$project")
87+ fi
88+ done
89+
7290 if [ ${#RUST_PROJECTS[@]} -eq 0 ]; then
7391 RUST_PROJECTS="[]"
7492 else
@@ -86,15 +104,23 @@ jobs:
86104 else
87105 CSHARP_PROJECTS=$(printf '%s\n' "${CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
88106 fi
107+
108+ if [ ${#ZIG_PROJECTS[@]} -eq 0 ]; then
109+ ZIG_PROJECTS="[]"
110+ else
111+ ZIG_PROJECTS=$(printf '%s\n' "${ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
112+ fi
89113 fi
90114
91115 echo "rust_projects=$RUST_PROJECTS" >> $GITHUB_OUTPUT
92116 echo "go_projects=$GO_PROJECTS" >> $GITHUB_OUTPUT
93117 echo "csharp_projects=$CSHARP_PROJECTS" >> $GITHUB_OUTPUT
118+ echo "zig_projects=$ZIG_PROJECTS" >> $GITHUB_OUTPUT
94119
95120 echo "Rust projects to test: $RUST_PROJECTS"
96121 echo "Go projects to test: $GO_PROJECTS"
97122 echo "C# projects to test: $CSHARP_PROJECTS"
123+ echo "Zig projects to test: $ZIG_PROJECTS"
98124
99125 rust_tests :
100126 needs : detect_changes
@@ -181,3 +207,22 @@ jobs:
181207 - name : Run C# tests in ${{ matrix.project }}
182208 run : dotnet test
183209 working-directory : ${{ matrix.project }}
210+
211+ zig_tests :
212+ needs : detect_changes
213+ if : needs.detect_changes.outputs.zig_projects != '[]'
214+ runs-on : ubuntu-latest
215+ continue-on-error : true
216+ strategy :
217+ fail-fast : false
218+ matrix :
219+ project : ${{ fromJson(needs.detect_changes.outputs.zig_projects) }}
220+ steps :
221+ - uses : actions/checkout@v4
222+ - name : Set up Zig
223+ uses : goto-bus-stop/setup-zig@v2
224+ with :
225+ version : master
226+ - name : Run Zig tests in ${{ matrix.project }}
227+ run : zig build test
228+ working-directory : ${{ matrix.project }}
0 commit comments