-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (210 loc) · 7.96 KB
/
tests.yml
File metadata and controls
228 lines (210 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: Advent of Code Tests
on:
push:
branches:
- main
- 'chore/**'
pull_request:
branches:
- main
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
rust_projects: ${{ steps.filter.outputs.rust_projects }}
go_projects: ${{ steps.filter.outputs.go_projects }}
csharp_projects: ${{ steps.filter.outputs.csharp_projects }}
zig_projects: ${{ steps.filter.outputs.zig_projects }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect changed projects
id: filter
run: |
# Get changed files
if [ "${{ github.event_name }}" == "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
# Handle first push or null before hash
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" == "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then
# Get files changed in the last commit
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null || git ls-files)
else
CHANGED_FILES=$(git diff --name-only $BEFORE ${{ github.sha }})
fi
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Define all projects
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")
ALL_GO_PROJECTS=("2017" "2019/go" "2020/02" "2024/golang")
ALL_CSHARP_PROJECTS=("2021/cs/1" "2021/cs/2")
ALL_ZIG_PROJECTS=("2024/zig")
# Check for workflow changes - if workflow changed, run all tests
if echo "$CHANGED_FILES" | grep -q "^.github/workflows/tests.yml"; then
echo "Workflow changed, running all tests"
RUST_PROJECTS=$(printf '%s\n' "${ALL_RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
GO_PROJECTS=$(printf '%s\n' "${ALL_GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
CSHARP_PROJECTS=$(printf '%s\n' "${ALL_CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
ZIG_PROJECTS=$(printf '%s\n' "${ALL_ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
else
# Detect Rust projects
RUST_PROJECTS=()
for project in "${ALL_RUST_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
RUST_PROJECTS+=("$project")
fi
done
# Detect Go projects
GO_PROJECTS=()
for project in "${ALL_GO_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
GO_PROJECTS+=("$project")
fi
done
# Detect C# projects
CSHARP_PROJECTS=()
for project in "${ALL_CSHARP_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
CSHARP_PROJECTS+=("$project")
fi
done
# Detect Zig projects
ZIG_PROJECTS=()
for project in "${ALL_ZIG_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
ZIG_PROJECTS+=("$project")
fi
done
if [ ${#RUST_PROJECTS[@]} -eq 0 ]; then
RUST_PROJECTS="[]"
else
RUST_PROJECTS=$(printf '%s\n' "${RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
if [ ${#GO_PROJECTS[@]} -eq 0 ]; then
GO_PROJECTS="[]"
else
GO_PROJECTS=$(printf '%s\n' "${GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
if [ ${#CSHARP_PROJECTS[@]} -eq 0 ]; then
CSHARP_PROJECTS="[]"
else
CSHARP_PROJECTS=$(printf '%s\n' "${CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
if [ ${#ZIG_PROJECTS[@]} -eq 0 ]; then
ZIG_PROJECTS="[]"
else
ZIG_PROJECTS=$(printf '%s\n' "${ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
fi
echo "rust_projects=$RUST_PROJECTS" >> $GITHUB_OUTPUT
echo "go_projects=$GO_PROJECTS" >> $GITHUB_OUTPUT
echo "csharp_projects=$CSHARP_PROJECTS" >> $GITHUB_OUTPUT
echo "zig_projects=$ZIG_PROJECTS" >> $GITHUB_OUTPUT
echo "Rust projects to test: $RUST_PROJECTS"
echo "Go projects to test: $GO_PROJECTS"
echo "C# projects to test: $CSHARP_PROJECTS"
echo "Zig projects to test: $ZIG_PROJECTS"
rust_tests:
needs: detect_changes
if: needs.detect_changes.outputs.rust_projects != '[]'
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.detect_changes.outputs.rust_projects) }}
steps:
- uses: actions/checkout@v4
- name: Install Rust Stable
uses: dtolnay/rust-toolchain@stable
if: ${{ matrix.project != '2021/_4' }}
- name: Install Rust Nightly for 2021/_4
uses: dtolnay/rust-toolchain@nightly
if: ${{ matrix.project == '2021/_4' }}
- name: Set up cargo-nextest
uses: taiki-e/install-action@nextest
- name: Build 2015 binary
if: ${{ matrix.project == '2015' }}
run: cargo build --release
working-directory: ${{ matrix.project }}
- name: Run Rust tests in 2015 with cargo-nextest
if: ${{ matrix.project == '2015' }}
run: cargo nextest run
working-directory: ${{ matrix.project }}
- name: Run Rust tests in ${{ matrix.project }}
if: ${{ matrix.project != '2015' }}
run: cargo test
working-directory: ${{ matrix.project }}
go_tests:
needs: detect_changes
if: needs.detect_changes.outputs.go_projects != '[]'
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.detect_changes.outputs.go_projects) }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '^1.18'
- name: Run Go tests in 2017
if: ${{ matrix.project == '2017' }}
run: go test ./...
working-directory: 2017
- name: Run Go tests in 2019/go
if: ${{ matrix.project == '2019/go' }}
run: go test ./cmd/...
working-directory: 2019/go
- name: Run Go tests in 2020/02
if: ${{ matrix.project == '2020/02' }}
run: go test ./...
working-directory: 2020/02
- name: Run Go tests in 2024/golang
if: ${{ matrix.project == '2024/golang' }}
run: go test ./cmd/...
working-directory: 2024/golang
csharp_tests:
needs: detect_changes
if: needs.detect_changes.outputs.csharp_projects != '[]'
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.detect_changes.outputs.csharp_projects) }}
steps:
- uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
- name: Restore dependencies for ${{ matrix.project }}
run: dotnet restore
working-directory: ${{ matrix.project }}
- name: Run C# tests in ${{ matrix.project }}
run: dotnet test
working-directory: ${{ matrix.project }}
zig_tests:
needs: detect_changes
if: needs.detect_changes.outputs.zig_projects != '[]'
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.detect_changes.outputs.zig_projects) }}
steps:
- uses: actions/checkout@v4
- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: master
- name: Run Zig tests in ${{ matrix.project }}
run: zig build test
working-directory: ${{ matrix.project }}