-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (151 loc) · 5.74 KB
/
Copy pathtests.yml
File metadata and controls
162 lines (151 loc) · 5.74 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
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 }}
zig_projects: ${{ steps.filter.outputs.zig_projects }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Filter changes
id: filter
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" == "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then
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: $CHANGED_FILES"
# Shared files that trigger all tests
TRIGGER_ALL="^.github/workflows/|^rust/common/|^rust/Cargo.toml|^rust/Cargo.lock|^golang/common/|^justfile"
ALL_RUST_PROJECTS=("2015" "2018" "2019" "2020" "2021" "2022" "2023" "2025" "runner")
ALL_GO_PROJECTS=("2017" "2019" "2020" "2024")
ALL_ZIG_PROJECTS=("2021" "2024")
if echo "$CHANGED_FILES" | grep -qE "$TRIGGER_ALL"; then
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 .)
ZIG_PROJECTS=$(printf '%s\n' "${ALL_ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
else
RUST_PROJECTS=()
for project in "${ALL_RUST_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^rust/${project}/"; then RUST_PROJECTS+=("$project"); fi
done
GO_PROJECTS=()
for project in "${ALL_GO_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^golang/${project}/"; then GO_PROJECTS+=("$project"); fi
done
ZIG_PROJECTS=()
for project in "${ALL_ZIG_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^zig/${project}/"; then ZIG_PROJECTS+=("$project"); fi
done
RUST_PROJECTS=$(printf '%s\n' "${RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
GO_PROJECTS=$(printf '%s\n' "${GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
ZIG_PROJECTS=$(printf '%s\n' "${ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
echo "rust_projects=$RUST_PROJECTS" >> $GITHUB_OUTPUT
echo "go_projects=$GO_PROJECTS" >> $GITHUB_OUTPUT
echo "zig_projects=$ZIG_PROJECTS" >> $GITHUB_OUTPUT
rust_tests:
needs: detect_changes
if: needs.detect_changes.outputs.rust_projects != '[]'
runs-on: ubuntu-latest
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
- name: Install Rust Nightly for 2021/_4
uses: dtolnay/rust-toolchain@nightly
if: ${{ matrix.project == '2021' }}
- name: Set up cargo-nextest
uses: taiki-e/install-action@nextest
- name: Install just
uses: taiki-e/install-action@just
- name: Restore cache
uses: actions/cache@v4
with:
path: .cache
key: ${{ runner.os }}-rust-cache-${{ hashFiles('rust/Cargo.lock', 'rust/common/src/**') }}-${{ matrix.project }}
restore-keys: |
${{ runner.os }}-rust-cache-
- name: Run Clippy
run: cargo clippy --workspace -- -A warnings
working-directory: rust/
continue-on-error: true
- name: Run Rust tests
run: just test-project-rust ${{ matrix.project }}
${{ matrix.project }}
env:
RUSTFLAGS: --cfg advent_of_code_ci
go_tests:
needs: detect_changes
if: needs.detect_changes.outputs.go_projects != '[]'
runs-on: ubuntu-latest
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.22.x'
cache: false
- name: Install just
uses: taiki-e/install-action@just
- name: Restore cache
uses: actions/cache@v4
with:
path: .cache
key: ${{ runner.os }}-go-cache-${{ hashFiles('golang/**/go.mod', 'golang/common/**') }}-${{ matrix.project }}
restore-keys: |
${{ runner.os }}-go-cache-
- name: Run Go tests
run: just test-project-go ${{ matrix.project }}
${{ matrix.project }}
zig_tests:
needs: detect_changes
if: needs.detect_changes.outputs.zig_projects != '[]'
runs-on: ubuntu-latest
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: 0.14.0
- name: Install just
uses: taiki-e/install-action@just
- name: Restore cache
uses: actions/cache@v4
with:
path: .cache
key: ${{ runner.os }}-zig-cache-${{ matrix.project }}
restore-keys: |
${{ runner.os }}-zig-cache-
- name: Run Zig tests
run: just test-project-zig ${{ matrix.project }}
continue-on-error: true