-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (130 loc) · 4.28 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
name: ci
on:
push:
branches: ['**']
paths:
- "Cargo.*"
- "**/*.rs"
- "crates/*/testdata/**"
- ".github/workflows/ci.yml"
pull_request:
branches: [main]
paths:
- "Cargo.*"
- "crates/*/src/**"
jobs:
setup:
runs-on: ubuntu-latest
outputs:
rust-version: ${{ steps.vars.outputs.rust-version }}
steps:
- name: Checkout code to determine the minimum supported rust version
uses: actions/checkout@v4
- name: Set rust versions to test against
id: vars
run: |
min_ver=$(sed -rn '/^rust-version\s*=/ s/^.*=\s*"([0-9](\.[0-9]+)+)(.*)/\1/p' Cargo.toml)
if [[ -n ${min_ver} ]]; then
echo "rust-version=['${min_ver}', 'stable']" >> $GITHUB_OUTPUT
else
exit 1
fi
test:
needs: setup
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust-version: ${{ fromJson(needs.setup.outputs.rust-version) }}
include:
- os: macos-latest
rust-version: stable
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up rust toolchain
uses: dtolnay/rust-toolchain@master
id: rust
with:
toolchain: ${{ matrix.rust-version }}
components: llvm-tools-preview
- name: Restore cache
uses: actions/cache/restore@v4
id: restore-cache
with:
path: |
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
target
key: ${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-rust-${{ steps.rust.outputs.cachekey }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Remove old caches
if: ${{ matrix.rust-version != 'stable' && github.ref_name == 'main' && steps.restore-cache.outputs.cache-hit != 'true' }}
continue-on-error: true
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
KEY=${{ github.workflow }}-${{ github.job }}-
# find matching caches
mapfile -t cache_keys < <( gh actions-cache list -R $REPO -B $BRANCH --key $KEY --sort created-at --order desc | cut -f 1 )
# remove all matching caches
for key in ${cache_keys[@]}
do
gh actions-cache delete $key -R $REPO -B $BRANCH --confirm
done
exit 0
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install cargo-llvm-cov
if: ${{ matrix.rust-version == 'stable' && runner.os == 'Linux' }}
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Build and run tests
run: |
# set up environment for coverage support
if [[ ${{ matrix.rust-version }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
source <(cargo llvm-cov show-env --export-prefix)
fi
cargo nextest run --features test --workspace --tests
# generate coverage report
if [[ ${{ matrix.rust-version }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
cargo llvm-cov report --lcov --output-path lcov.info
fi
- name: Upload build artifacts
if: ${{ matrix.rust-version == 'stable' && runner.os == 'Linux' }}
uses: actions/upload-artifact@v4
with:
name: coverage
path: lcov.info
if-no-files-found: error
retention-days: 3
- name: Save cache
if: ${{ github.ref_name == 'main' && steps.restore-cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: |
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
target
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
coverage:
if: ${{ github.ref_name == 'main' }}
needs: test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/lcov.info
fail_ci_if_error: true