-
Notifications
You must be signed in to change notification settings - Fork 1
236 lines (234 loc) · 7.73 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
---
name: CI
"on":
push:
branches:
- master
pull_request:
branches:
- master
jobs:
pre_ci:
name: pre ci
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
permissions: {}
outputs:
repo: ${{ steps.repo.outputs.repo }}
steps:
- name: get repo name
id: repo
run: |
REPO_NAME="${GITHUB_REPOSITORY#"$GITHUB_REPOSITORY_OWNER/"}"
echo "Repo: ${REPO_NAME}"
echo "repo=${REPO_NAME}" >> "$GITHUB_OUTPUT"
changes:
name: filter changes
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
bash: ${{ steps.filter.outputs.bash }}
markdown: ${{ steps.filter.outputs.markdown }}
python: ${{ steps.filter.outputs.python }}
rust: ${{ steps.filter.outputs.rust }}
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50
id: filter
with:
filters: |
bash:
- '**/*.sh'
markdown:
- 'src/cli.rs'
- 'Cargo.lock'
- 'Cargo.toml'
- 'TEMPLATE.md'
- 'rust-toolchain.toml'
python:
- '**/*.py'
- '.github/workflows/requirements.txt'
rust:
- '**/*.rs'
- 'Cargo.lock'
- 'Cargo.toml'
- 'rust-toolchain.toml'
lint_rs:
name: lint rust ci
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: check cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
id: cache
with:
path: |
~/.cargo/
~/.rustup/
target/
key: ${{ runner.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('Cargo.lock') }}
- name: cargo fmt check
run: |
cargo fmt -- --check --verbose
- name: cargo clippy main
run: |
cargo clippy --locked --workspace
- name: cargo clippy tests
run: |
cargo clippy --locked --tests
- name: cargo rustdoc
run: |
cargo rustdoc
lint_py:
name: lint python ci
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: setup python
run: |
set -x
python3 -m venv .venv
.venv/bin/pip install -r .github/workflows/requirements.txt
- name: black/ruff python
run: |
set -x
md=".github/workflows/md.py"
.venv/bin/black -v "$md"
.venv/bin/ruff -v "$md"
lint_sh:
name: lint bash ci
needs: changes
if: ${{ needs.changes.outputs.bash == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: shellcheck bash
run: |
shopt -s globstar
shellcheck -s bash ./*.sh .github/**/*.sh
test:
name: test ci
needs: lint_rs
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
coverage: ${{ steps.coverage.outputs.coverage }}
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: check cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
id: cache
with:
path: |
~/.cargo/
~/.rustup/
target/
key: ${{ runner.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('Cargo.lock') }}
- name: install cargo-tarpaulin
uses: taiki-e/install-action@6801bd56b9711500292d943350f0b1f3559d7acb
with:
tool: cargo-tarpaulin
checksum: true
- name: cargo test coverage
run: |
cargo tarpaulin --locked --tests --line -o xml --exclude-files src/cli.rs src/main.rs
- name: report (total lines) coverage
if: ${{ (github.event_name == 'push') && !(startsWith(github.event.head_commit.message, 'build(deps):')) }}
id: coverage
run: |
COVERAGE="$(grep -E -o 'line-rate="[^"]+"' cobertura.xml \
| head -1 | cut -d\" -f2 | awk '{print int($0*100+0.5)}')"
echo "coverage=${COVERAGE}" >> "$GITHUB_OUTPUT"
- name: cov summary md
if: ${{ (github.event_name == 'pull_request') && (github.actor != 'dependabot[bot]') }}
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95
with:
filename: cobertura.xml
format: 'markdown'
hide_complexity: true
hide_branch_rate: true
output: both
- name: cov pr comment
if: ${{ (github.event_name == 'pull_request') && (github.actor != 'dependabot[bot]') }}
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd
with:
message: Coverage Report
recreate: true
path: code-coverage-results.md
badge:
name: coverage badge
needs:
- pre_ci
- test
if: ${{ (github.event_name == 'push') && !(startsWith(github.event.head_commit.message, 'build(deps):')) }}
runs-on: ubuntu-latest
permissions: {}
env:
gist_id: 0e20cd331d0800e3299298a3868aab7a
steps:
- name: generate dynamic badge
uses: schneegans/dynamic-badges-action@5d424ad4060f866e4d1dab8f8da0456e6b1c4f56
with:
auth: ${{ secrets.GIST_TOKEN }}
filename: ${{ needs.pre_ci.outputs.repo }}__${{ github.ref_name }}.json
gistID: ${{ env.gist_id }}
label: coverage
message: ${{ needs.test.outputs.coverage }}%
namedLogo: github
style: flat-square
valColorRange: ${{ needs.test.outputs.coverage }}
maxColorRange: 100
minColorRange: 0
- name: badge image url
run: |
URL="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/${{ github.actor }}/${{ env.gist_id }}/raw/${{ needs.pre_ci.outputs.repo }}__${{ github.ref_name }}.json"
MARKDOWN="![Coverage](${URL})"
echo "Badge URL: ${URL}"
echo "Badge image for Markdown: ${MARKDOWN}"
md:
name: update readme
needs: changes
if: ${{ (github.event_name == 'push') && !(startsWith(github.event.head_commit.message, 'build(deps):')) && (needs.changes.outputs.markdown == 'true') }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: check cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
id: cache
with:
path: |
~/.cargo/
~/.rustup/
target/
key: ${{ runner.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('Cargo.lock') }}
- name: cargo build
run: |
cargo build --locked
- name: update readme
run: .github/workflows/md.py
- name: commit readme
uses: EndBug/add-and-commit@1bad3abcf0d6ec49a5857d124b0bfb52dc7bb081
with:
message: 'build(README): render from TEMPLATE'
add: 'README.md'