Skip to content

Commit ab96f9d

Browse files
authored
chore(dev): review CI (#195)
- resolves #182 by replacing rust-based benchmark with nushell script (which employs `hyperfine`) - satisfies `zizmor` linting of CI workflows - migrate from `nox` to `nur` for dev task runner (uses nushell script) - updated pre-commit hooks - updated locked python deps - automatically cancel CI runs when a new run is triggered (does not apply to default branch)
1 parent 02c500c commit ab96f9d

25 files changed

+1044
-1010
lines changed

.config/.readthedocs.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ build:
1717
curl -LsSf https://astral.sh/uv/install.sh | sh
1818
build:
1919
html:
20-
- ${HOME}/.local/bin/uvx nox -s docs-build
20+
- >-
21+
${HOME}/.local/bin/uv sync
22+
--package cli-gen
23+
--all-groups
24+
--reinstall-package cli-gen
25+
- ${HOME}/.local/bin/uv run mkdocs build --config-file docs/mkdocs.yml
2126
post_build:
2227
- mkdir -p $READTHEDOCS_OUTPUT/html/
2328
- mv docs/site/* $READTHEDOCS_OUTPUT/html

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
*.code-workspace text eol=lf
2828
*.clang-tidy text eol=lf
2929
*.clang-format text eol=lf
30+
nurfile text eol=lf
31+
*.nu text eol=lf

.github/workflows/benchmark.yml

Lines changed: 109 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,138 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- cpp-linter/src/
8-
- cpp-linter/benches/
7+
- cpp-linter/src/**
98
- cpp-linter/Cargo.toml
109
- Cargo.toml
1110
- Cargo.lock
1211
- .github/workflows/benchmark.yml
13-
tags-ignore: ['*']
1412
pull_request:
1513
branches: [main]
1614
paths:
17-
- cpp-linter/src/
18-
- cpp-linter/benches/
15+
- cpp-linter/src/**
1916
- cpp-linter/Cargo.toml
2017
- Cargo.toml
2118
- Cargo.lock
2219
- .github/workflows/benchmark.yml
23-
# `workflow_dispatch` allows CodSpeed to trigger back-test
24-
# performance analysis in order to generate initial data.
25-
workflow_dispatch:
2620

27-
# This CI workflow can take up to 2 hours.
28-
# This setting will auto-cancel a old run if a new run is started.
21+
permissions: {}
22+
2923
concurrency:
3024
group: ${{ github.workflow }}-${{ github.ref }}
31-
cancel-in-progress: true
25+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
3226

3327
jobs:
28+
build-bin:
29+
name: Build ${{ matrix.name }} binary
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
include:
34+
- commit: ${{ github.sha }}
35+
name: current
36+
- commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
37+
name: previous
38+
env:
39+
BIN: target/release/cpp-linter
40+
steps:
41+
- name: Checkout ${{ matrix.name }}
42+
uses: actions/checkout@v5
43+
with:
44+
ref: ${{ matrix.commit }}
45+
persist-credentials: false
46+
- name: Cache base ref build
47+
uses: actions/cache@v4
48+
id: cache
49+
with:
50+
key: bin-cache-${{ hashFiles('cpp-linter/src/**', 'Cargo.toml', 'Cargo.lock', 'cpp-linter/Cargo.toml') }}
51+
path: ${{ env.BIN }}
52+
- name: Validate cached binary
53+
if: steps.cache.outputs.cache-hit == 'true'
54+
id: validate
55+
run: |
56+
chmod +x ${{ env.BIN }}
57+
if ! ${{ env.BIN }} version; then
58+
echo "Cached binary is invalid, rebuilding..."
59+
echo "cache-valid=false" >> "$GITHUB_OUTPUT"
60+
fi
61+
- run: rustup update --no-self-update
62+
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
63+
- run: cargo build --bin cpp-linter --release
64+
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
65+
- name: Upload build artifact
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: ${{ matrix.name }}
69+
path: ${{ env.BIN }}
70+
71+
build-py-binding:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v5
75+
with:
76+
persist-credentials: false
77+
- name: Set up Python
78+
uses: actions/setup-python@v4
79+
id: setup-python
80+
with:
81+
python-version: '3.x'
82+
- name: Build wheels
83+
uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4
84+
with:
85+
target: x86_64
86+
args: --release --out dist --find-interpreter
87+
manylinux: auto
88+
before-script-linux: |
89+
# NOTE: rust-cross/manylinux docker images are CentOS based
90+
yum update -y
91+
yum install -y openssl openssl-devel
92+
- name: Upload wheels
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: wheel
96+
path: dist/*
97+
3498
benchmark:
99+
name: Measure Performance Difference
100+
needs: [build-bin, build-py-binding]
35101
runs-on: ubuntu-latest
36102
steps:
37103
- uses: actions/checkout@v5
38-
# using the generated compilation database,
39-
# we will use cpp-linter to scan libgit2 src/libgit2/**.c files.
104+
with:
105+
persist-credentials: false
40106
- name: Checkout libgit2
41107
uses: actions/checkout@v5
42108
with:
43109
repository: libgit2/libgit2
44110
ref: v1.8.1
45-
path: cpp-linter/benches/libgit2
46-
- name: Generate compilation database
47-
working-directory: cpp-linter/benches/libgit2
48-
run: |
49-
mkdir build && cd build
50-
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
111+
path: benchmark/libgit2
112+
persist-credentials: false
113+
114+
- name: Download built binaries
115+
uses: actions/download-artifact@v5
116+
51117
- name: Install cargo-binstall
52-
uses: cargo-bins/cargo-binstall@main
53-
- name: Install cargo-codspeed
54-
run: cargo binstall -y cargo-codspeed
55-
- name: Build the benchmark target(s)
56-
run: cargo codspeed build
57-
- name: Run benchmarks
58-
uses: CodSpeedHQ/action@v4
59-
with:
60-
mode: instrumentation
61-
run: cargo codspeed run
62-
token: ${{ secrets.CODSPEED_TOKEN }}
118+
uses: cargo-bins/cargo-binstall@38e8f5e4c386b611d51e8aa997b9a06a3c8eb67a # v1.15.6
119+
env:
120+
GITHUB_TOKEN: ${{ github.token }}
121+
- name: Install hyperfine
122+
env:
123+
GITHUB_TOKEN: ${{ github.token }}
124+
run: cargo binstall -y hyperfine
125+
- name: Install nushell
126+
uses: hustcer/setup-nu@985d59ec83ae3e3418f9d36471cda38b9d8b9879 # v3.20
127+
- name: Install uv
128+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
129+
130+
- name: Run benchmark script
131+
working-directory: benchmark
132+
shell: nu {0}
133+
run: |-
134+
let new_py = (
135+
glob "../wheel/cpp_linter-*.whl"
136+
| first
137+
| path expand
138+
)
139+
let prev_bin = "../previous/cpp-linter" | path expand
140+
let curr_bin = "../current/cpp-linter" | path expand
141+
nu benchmark.nu --new-py $new_py --rust-bin $curr_bin --prev-rust-bin $prev_bin

.github/workflows/binary-builds.yml

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Binary builds
22

3-
permissions:
4-
contents: read
5-
63
on:
74
push:
85
branches: [main]
@@ -25,12 +22,13 @@ env:
2522
CARGO_TERM_COLOR: always
2623
RUST_BACKTRACE: 1
2724

28-
defaults:
29-
run:
30-
shell: bash
25+
permissions: {}
3126

32-
jobs:
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.ref }}
29+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
3330

31+
jobs:
3432
create-assets:
3533
name: ${{ matrix.target }}
3634
strategy:
@@ -103,19 +101,27 @@ jobs:
103101
steps:
104102
- name: Checkout
105103
uses: actions/checkout@v5
104+
with:
105+
persist-credentials: false
106106

107107
- name: Setup Rust
108-
uses: dtolnay/rust-toolchain@stable
109-
with:
110-
target: ${{ matrix.target }}
108+
shell: bash
109+
env:
110+
RS_TARGET: ${{ matrix.target }}
111+
run: |-
112+
rustup update stable --no-self-update
113+
rustup target add ${RS_TARGET}
111114
115+
- name: Install cargo-binstall
116+
if: matrix.cross
117+
uses: cargo-bins/cargo-binstall@38e8f5e4c386b611d51e8aa997b9a06a3c8eb67a # v1.15.6
118+
env:
119+
GITHUB_TOKEN: ${{ github.token }}
112120
- name: Install cross (cargo cross compiler)
113121
if: matrix.cross
114-
uses: taiki-e/install-action@v2
115122
env:
116123
GITHUB_TOKEN: ${{ github.token }}
117-
with:
118-
tool: cross
124+
run: cargo binstall -y cross
119125

120126
- name: Build
121127
run: >-
@@ -127,8 +133,25 @@ jobs:
127133
--target ${{ matrix.target }}
128134
${{ matrix.vendored && '--features openssl-vendored' || '' }}
129135
130-
- name: Prepare artifacts
131-
run: mv target/${{ matrix.target }}/release/cpp-linter${{ runner.os == 'Windows' && '.exe' || '' }} ./cpp-linter-${{ matrix.target }}${{ runner.os == 'Windows' && '.exe' || '' }}
136+
- name: Prepare artifacts (unix)
137+
if: runner.os != 'Windows'
138+
shell: bash
139+
run: |-
140+
tgt="cpp-linter"
141+
mv "target/${{ matrix.target }}/release/${tgt}" "${tgt}"
142+
arc_name="cpp-linter-${{ matrix.target }}.tar.gz"
143+
tar -a -c -v -z -f "${arc_name}" ${tgt} LICENSE
144+
- name: Prepare artifacts (windows)
145+
if: runner.os == 'Windows'
146+
shell: pwsh
147+
# `tar.exe` in powershell is different from `tar` in bash.
148+
# need to use `tar.exe` in powershell to create a valid zip file.
149+
run: |-
150+
$tgt = "cpp-linter.exe"
151+
mv "target/${{ matrix.target }}/release/${tgt}" "${tgt}"
152+
$arc_name = "cpp-linter-${{ matrix.target }}.zip"
153+
tar -a -c -v -f "${arc_name}" ${tgt} LICENSE
154+
132155
- name: Upload artifacts
133156
uses: actions/upload-artifact@v4
134157
with:
@@ -141,6 +164,7 @@ jobs:
141164
runs-on: ubuntu-latest
142165
needs: [create-assets]
143166
permissions:
167+
id-token: write
144168
contents: write
145169
steps:
146170
- uses: actions/checkout@v5
@@ -160,9 +184,14 @@ jobs:
160184
- name: Create a Github Release
161185
env:
162186
GH_TOKEN: ${{ github.token }}
187+
GIT_REF: ${{ github.ref_name }}
163188
run: |
164189
files=$(ls dist/cpp-linter*)
165-
gh release upload "${{ github.ref_name }}" $files
166-
- run: cargo publish -p cpp-linter
190+
gh release upload "$GIT_REF" $files
191+
- name: Establish provenance
192+
id: auth
193+
uses: rust-lang/crates-io-auth-action@e919bc7605cde86df457cf5b93c5e103838bd879 # v1.0.1
194+
- name: Publish package
167195
env:
168-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
196+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
197+
run: cargo publish -p cpp-linter

0 commit comments

Comments
 (0)