-
Notifications
You must be signed in to change notification settings - Fork 25
207 lines (198 loc) · 8.45 KB
/
ci.yml
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
# spell-checker:ignore (rust) clippy rustdoc rustfmt rustup RUSTC RUSTFLAGS Zpanic Cpanic RUSTDOCFLAGS Ccodegen Coverflow profraw
# spell-checker:ignore (abbrevs/acronyms) MSVC (bash) alnum esac (jargon) maint (utils) codecov grcov lcov markdownlint sccache (vars) tempfile () ntempfile uutils
# spell-checker:ignore (people) dtolnay ; Swatinem ; DavidAnson
on: [push, pull_request]
name: CI
env:
PROJECT_NAME: platform-info
PROJECT_DESC: 'Cross-platform host machine info'
PROJECT_AUTH: 'uutils'
# * `rust` caching configuration
RUSTC_WRAPPER: 'sccache'
SCCACHE_GHA_ENABLED: 'true'
# terminate execution of the current workflow group when there is a newer changeset detected
# * the group is defined by "WORKFLOW_NAME-REF", where REF can be a branch, tag, or pull-request reference
# * workflows executing for the default branch are excluded from termination
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
jobs:
style_format:
name: Style/format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- run: cargo fmt --all -- --check
style_lint:
name: Style/lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- uses: DavidAnson/markdownlint-cli2-action@v15
with:
fix: true
globs: |
*.md
docs/src/**/*.md
src/**/*.md
- run: cargo clippy --all-targets -- -D warnings
style_spellcheck:
name: Style/spellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: streetsidesoftware/cspell-action@v5 ## ref: <https://github.com/streetsidesoftware/cspell-action>
with:
incremental_files_only: false
verbose: true
test:
name: Build/Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: Build/Test Info
shell: bash
run: |
## Build/Test Info
# repo/commit info
echo "## repo/commit"
echo GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
echo GITHUB_REF=${GITHUB_REF}
echo GITHUB_SHA=${GITHUB_SHA}
# environment
echo "## environment"
echo "CI='${CI}'"
echo "PWD='${PWD}'"
# tooling info display
echo "## tooling"
which gcc >/dev/null 2>&1 && (gcc --version | head -1) || true
rustup -V 2>/dev/null
rustup show active-toolchain
cargo -V
rustc -V
# dependencies
echo "## crate dependency list"
# * note: for applications, use `--locked` for `cargo fetch`` and `cargo tree`) and commit *Cargo.lock*
cargo fetch --quiet
cargo tree --edges=no-dev --prefix=none --workspace | grep -vE "\(.*[/\\]${GITHUB_REPOSITORY##*/}\)" | sort --unique
- run: cargo test --all-features -- --test-threads 1
env:
RUST_BACKTRACE: '1'
coverage:
name: Code Coverage
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: true
matrix:
job:
- { os: ubuntu-latest }
- { os: macos-latest }
- { os: windows-latest }
steps:
- uses: actions/checkout@v4
- name: Initialize/setup workflow
id: vars
shell: bash
run: |
## VARs and paths setup
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
# toolchain
TOOLCHAIN="nightly" ## default to "nightly" toolchain (required for certain required unstable compiler flags) ## !maint: refactor when stable channel has needed support
# * specify gnu-type TOOLCHAIN for windows; `grcov` requires gnu-style code coverage data files
case ${{ matrix.job.os }} in windows-*) TOOLCHAIN="$TOOLCHAIN-x86_64-pc-windows-msvc" ;; esac;
# * use requested TOOLCHAIN if specified
if [ -n "${{ matrix.job.toolchain }}" ]; then TOOLCHAIN="${{ matrix.job.toolchain }}" ; fi
outputs TOOLCHAIN
# target-specific options
# * CARGO_FEATURES_OPTION
CARGO_FEATURES_OPTION='--all-features' ; ## default to '--all-features' for code coverage
if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features=${{ matrix.job.features }}' ; fi
outputs CARGO_FEATURES_OPTION
# * CODECOV_FLAGS
CODECOV_FLAGS=$( echo "${{ matrix.job.os }}" | sed 's/[^[:alnum:]]/_/g' )
outputs CODECOV_FLAGS
# * code coverage
COVERAGE_REPORT_DIR="target/debug/coverage"
PROFILES_DIR="${COVERAGE_REPORT_DIR}/profiles"
mkdir -p "${COVERAGE_REPORT_DIR}" "${PROFILES_DIR}"
outputs COVERAGE_REPORT_DIR PROFILES_DIR
LLVM_PROFILE_FILE="${PROFILES_DIR}/profile-%p-%m.profraw"
outputs LLVM_PROFILE_FILE
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.vars.outputs.TOOLCHAIN }}
components: llvm-tools
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- run: cargo install grcov
- name: Test
shell: bash
env:
CARGO_INCREMENTAL: '0'
LLVM_PROFILE_FILE: ${{ steps.vars.outputs.LLVM_PROFILE_FILE }}
RUSTC_WRAPPER: ''
RUSTFLAGS: '-C instrument-coverage'
RUSTDOCFLAGS: ''
run: |
## Test
cargo test ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --no-fail-fast -- --test-threads 1
- name: Test examples
shell: bash
env:
CARGO_INCREMENTAL: '0'
LLVM_PROFILE_FILE: ${{ steps.vars.outputs.LLVM_PROFILE_FILE }}
RUSTC_WRAPPER: ''
RUSTFLAGS: '-C instrument-coverage'
RUSTDOCFLAGS: ''
run: |
## Test examples
cargo test ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --examples --no-fail-fast -- --test-threads 1
- name: Generate coverage data (via `grcov`)
id: coverage
shell: bash
run: |
## Generate coverage data
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
#
COVERAGE_REPORT_DIR='${{ steps.vars.outputs.COVERAGE_REPORT_DIR }}'
LLVM_PROFILE_FILE='${{ steps.vars.outputs.LLVM_PROFILE_FILE }}'
PROFILES_DIR='${{ steps.vars.outputs.PROFILES_DIR }}'
BINARY_PATH='target/debug'
COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info"
# display coverage files
grcov . --binary-path "${BINARY_PATH}" --source-dir . --output-type files --ignore build.rs --ignore "examples/*" --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique
# generate coverage report
grcov . --binary-path "${BINARY_PATH}" --source-dir . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --ignore build.rs --ignore "examples/*" --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"
report=${COVERAGE_REPORT_FILE}
outputs report
- name: Upload coverage results (to Codecov.io)
uses: codecov/codecov-action@v4
# if: steps.vars.outputs.HAS_CODECOV_TOKEN
with:
# token: ${{ secrets.CODECOV_TOKEN }}
file: ${{ steps.coverage.outputs.report }}
## flags: IntegrationTests, UnitTests, ${{ steps.vars.outputs.CODECOV_FLAGS }}
flags: ${{ steps.vars.outputs.CODECOV_FLAGS }}
name: codecov-umbrella
fail_ci_if_error: false