Repository navigation
174 lines (163 loc) · 6.36 KB
/
Copy pathrust-core.yml
File metadata and controls
174 lines (163 loc) · 6.36 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
name: Rust Core
# Builds, lints and tests only the Rust Core crates a pull request can affect:
# the crates whose files changed and every crate that depends on them, as
# chosen by scripts/rust-core/affected-crates.mjs. Linux checks every selected
# crate. macOS and Windows run the tests of the selected crates that declare
# those hosts, once the pull request is ready for review and Linux passed.
#
# There is no path filter: a change that affects no crate still reports the
# "Rust Core gate" check, which branch rules can require.
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: rust-core-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# CI compiles each crate once: incremental state and full debug information
# would only cost time and disk space.
CARGO_INCREMENTAL: 0
CARGO_PROFILE_DEV_DEBUG: line-tables-only
jobs:
select:
name: Select crates
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
rust: ${{ steps.select.outputs.rust }}
packages: ${{ steps.select.outputs.packages }}
test-args: ${{ steps.select.outputs.test-args }}
crate-directories: ${{ steps.select.outputs.crate-directories }}
hosts: ${{ steps.select.outputs.hosts }}
steps:
- uses: actions/checkout@v7
with:
# A pull request checks out its merge commit, whose first parent is
# the branch it merges into.
fetch-depth: 2
- uses: actions/setup-node@v6
with:
node-version: 22
- uses: dtolnay/rust-toolchain@1.100.0
- name: Test the CI scripts
run: node --test scripts/rust-core/*.test.mjs
- name: Check that every test runs on a host CI tests its crate on
run: node scripts/rust-core/verify-platform-tests.mjs
- name: Select crates
id: select
env:
# A manual run checks every crate.
SCOPE: ${{ github.event_name == 'pull_request' && '--base HEAD^1' || '--all' }}
run: |
read -ra scope <<< "$SCOPE"
node scripts/rust-core/affected-crates.mjs --github "${scope[@]}"
linux:
name: Linux
needs: select
if: needs.select.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
env:
# One build directory for the lints, Rustdoc and the tests.
CARGO_TARGET_DIR: ${{ github.workspace }}/rust/target
PACKAGES: ${{ needs.select.outputs.packages }}
TEST_ARGS: ${{ needs.select.outputs.test-args }}
CRATE_DIRECTORIES: ${{ needs.select.outputs.crate-directories }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
- uses: dtolnay/rust-toolchain@1.100.0
with:
components: clippy, rustfmt
targets: x86_64-pc-windows-msvc
# Only downloaded crates are cached: build output would not fit the
# repository cache quota next to the SDK end-to-end cache.
- uses: actions/cache@v6
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: rust-core-cargo-${{ hashFiles('rust/Cargo.lock', 'scripts/rust-core/comment-lexer/Cargo.lock') }}
restore-keys: rust-core-cargo-
- name: Check formatting
run: cargo fmt --manifest-path rust/Cargo.toml --all -- --check
- name: Check the log event catalog
run: node scripts/logging/generate-log-events.mjs --check
- name: Check comments
run: |
read -ra directories <<< "$CRATE_DIRECTORIES"
scripts/rust-core/verify-rust-core-comments.sh "${directories[@]}"
- name: Lint
run: |
read -ra packages <<< "$PACKAGES"
cargo clippy --locked --manifest-path rust/Cargo.toml "${packages[@]}" --all-targets --all-features -- -D warnings
# Code behind cfg(windows) compiles only for Windows. Checking it here
# finds its errors without a Windows runner; default features only,
# because the remote server feature targets Unix hosts. Clippy only
# checks and never links, so the C dependencies use host pkg-config
# metadata instead of compiling for MSVC on a Linux runner.
- name: Install Windows lint metadata
run: sudo apt-get install -y libzstd-dev
- name: Lint for Windows
env:
LIBSQLITE3_SYS_USE_PKG_CONFIG: "1"
ZSTD_SYS_USE_PKG_CONFIG: "1"
PKG_CONFIG_ALLOW_CROSS: "1"
run: |
read -ra packages <<< "$PACKAGES"
cargo clippy --locked --manifest-path rust/Cargo.toml "${packages[@]}" --all-targets --target x86_64-pc-windows-msvc -- -D warnings
- name: Test
run: |
read -ra arguments <<< "$TEST_ARGS"
cargo test --locked --manifest-path rust/Cargo.toml "${arguments[@]}"
hosts:
name: ${{ matrix.name }}
needs: [select, linux]
# Draft pull requests run Linux only, like the desktop repository.
if: needs.select.outputs.hosts != '[]' && (github.event_name != 'pull_request' || !github.event.pull_request.draft)
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.select.outputs.hosts) }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
defaults:
run:
shell: bash
env:
TEST_ARGS: ${{ matrix.test-args }}
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@1.100.0
- name: Test
run: |
read -ra arguments <<< "$TEST_ARGS"
cargo test --locked --manifest-path rust/Cargo.toml "${arguments[@]}"
gate:
name: Rust Core gate
needs: [select, linux, hosts]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# A job that had nothing to check is skipped; any other result fails.
- name: Require every job to pass or be skipped
env:
NEEDS: ${{ toJSON(needs) }}
run: |
jq -r 'to_entries[] | "\(.key): \(.value.result)"' <<< "$NEEDS"
failed="$(jq -r '[to_entries[] | select(.value.result != "success" and .value.result != "skipped") | .key] | join(", ")' <<< "$NEEDS")"
if [[ -n "$failed" ]]; then
echo "::error::Rust Core jobs did not pass: $failed"
exit 1
fi