Skip to content

Commit c0cda05

Browse files
committed
use just
[`just`][just] is a task manager/runner written in rust for any project. It makes executing common dev workflows commands simple and easily repeated. > [!tip] > See [`just` docs][just]. This also updates some other minor things. [just]: https://just.systems
1 parent d746a94 commit c0cda05

11 files changed

+148
-64
lines changed

.github/workflows/binary-builds.yml

+9-21
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ on:
1212
branches: [main]
1313

1414
env:
15-
CARGO_INCREMENTAL: 0
16-
CARGO_NET_GIT_FETCH_WITH_CLI: true
17-
CARGO_NET_RETRY: 10
1815
CARGO_TERM_COLOR: always
1916
RUST_BACKTRACE: 1
20-
RUSTFLAGS: -D warnings
21-
RUSTUP_MAX_RETRIES: 10
2217

2318
defaults:
2419
run:
@@ -99,15 +94,6 @@ jobs:
9994
- name: Checkout
10095
uses: actions/checkout@v4
10196

102-
- uses: actions/setup-python@v5
103-
if: startsWith(github.ref, 'refs/tags/')
104-
with:
105-
python-version: '3.x'
106-
107-
- name: Increment version
108-
if: startsWith(github.ref, 'refs/tags/')
109-
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
110-
11197
- name: Setup Rust
11298
uses: dtolnay/rust-toolchain@stable
11399
with:
@@ -119,13 +105,15 @@ jobs:
119105
with:
120106
tool: cross
121107

122-
- name: Build (native)
123-
if: ${{ !matrix.cross }}
124-
run: cargo build --manifest-path cpp-linter-lib/Cargo.toml --release --bin cpp-linter --target ${{ matrix.target }} ${{ matrix.vendered && '--features openssl-vendored' || '' }}
125-
126-
- name: Build (cross)
127-
if: matrix.cross
128-
run: cross build --manifest-path cpp-linter-lib/Cargo.toml --release --bin cpp-linter --target ${{ matrix.target }} ${{ matrix.vendered && '--features openssl-vendored' || '' }}
108+
- name: Build
109+
run: >-
110+
${{ matrix.cross && 'cross' || 'cargo '}}
111+
build
112+
--manifest-path cpp-linter-lib/Cargo.toml
113+
--bin cpp-linter
114+
--release
115+
--target ${{ matrix.target }}
116+
${{ matrix.vendered && '--features openssl-vendored' || '' }}
129117
130118
- name: Prepare artifacts
131119
run: mv target/${{ matrix.target }}/release/cpp-linter${{ runner.os == 'Windows' && '.exe' || '' }} ./cpp-linter-${{ matrix.target }}${{ runner.os == 'Windows' && '.exe' || '' }}

.github/workflows/build-docs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: [push, workflow_dispatch]
44

55
env:
66
CARGO_TERM_COLOR: always
7+
RUST_BACKTRACE: 1
78

89
jobs:
910
cache-deps:

.github/workflows/bump_version.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import argparse
2+
from pathlib import Path
3+
import sys
4+
import re
5+
6+
VER_PATTERN = re.compile(r'^version = "(\d+)\.(\d+)\.(\d+)[^"]*" # auto', re.MULTILINE)
7+
VER_REPLACE = 'version = "%d.%d.%d" # auto'
8+
COMPONENTS = ["major", "minor", "patch"]
9+
10+
11+
class Args(argparse.Namespace):
12+
component: str = "patch"
13+
14+
15+
def replace(match: re.Match | None) -> str:
16+
assert match is not None, "Could not find version in Cargo.toml"
17+
ver = [int(x) for x in match.groups()[:3]]
18+
assert len(ver) == 3
19+
print("old version:", ".".join([str(x) for x in ver]))
20+
index = COMPONENTS.index(Args.component)
21+
ver[index] += 1
22+
for i in range(index + 1, 3):
23+
ver[i] = 0
24+
print("new version:", ".".join([str(x) for x in ver]))
25+
return VER_REPLACE % tuple(ver)
26+
27+
28+
def main():
29+
parser = argparse.ArgumentParser()
30+
parser.add_argument("component", default="patch", choices=COMPONENTS)
31+
parser.parse_args(namespace=Args)
32+
cargo_path = Path("Cargo.toml")
33+
doc = cargo_path.read_text(encoding="utf-8")
34+
doc = VER_PATTERN.sub(replace, doc)
35+
cargo_path.write_text(doc, encoding="utf-8", newline="\n")
36+
return 0
37+
38+
39+
if __name__ == "__main__":
40+
sys.exit(main())

.github/workflows/pre-commit-hooks.yml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ jobs:
1212

1313
cargo-tools:
1414
runs-on: ubuntu-latest
15+
16+
env:
17+
CARGO_TERM_COLOR: always
18+
RUST_BACKTRACE: 1
19+
1520
steps:
1621
- uses: actions/checkout@v4
1722
- run: rustup update

.github/workflows/python-packaging.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
permissions:
1717
contents: read
1818

19+
env:
20+
CARGO_TERM_COLOR: always
21+
RUST_BACKTRACE: 1
22+
1923
jobs:
2024
linux:
2125
runs-on: ubuntu-latest
@@ -35,10 +39,6 @@ jobs:
3539
with:
3640
python-version: '3.x'
3741

38-
- name: Increment version
39-
if: startsWith(github.ref, 'refs/tags/')
40-
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
41-
4242
- name: Calculate openssl-vendored
4343
shell: bash
4444
id: is-openssl-vendored

.github/workflows/replace_version_spec.py

-30
This file was deleted.

.github/workflows/run-dev-tests.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919

2020
env:
2121
CARGO_TERM_COLOR: always
22+
RUST_BACKTRACE: 1
2223

2324
jobs:
2425
cache-deps:
@@ -63,10 +64,10 @@ jobs:
6364
# if: runner.os == 'Windows'
6465
# run: vcpkg install openssl
6566

66-
- name: Install cargo-nextest and cargo-llvm-cov
67+
- name: Install third-party binaries
6768
uses: taiki-e/install-action@v2
6869
with:
69-
tool: cargo-nextest,cargo-llvm-cov,cargo-binstall
70+
tool: cargo-nextest,cargo-llvm-cov,cargo-binstall,just
7071

7172
- name: Install llvm-cov-pretty (HTML report generator)
7273
run: cargo binstall -y llvm-cov-pretty
@@ -116,15 +117,13 @@ jobs:
116117
working-directory: cpp-linter-lib
117118
env:
118119
CLANG_VERSION: ${{ matrix.version }}
119-
run: cargo llvm-cov --lib --no-report nextest
120+
run: just test
120121

121122
- name: Generate Coverage HTML report
122123
working-directory: cpp-linter-lib
123124
env:
124125
CLANG_VERSION: ${{ matrix.version }}
125-
run: |
126-
cargo llvm-cov report --json --output-path .coverage.json
127-
llvm-cov-pretty .coverage.json
126+
run: just pretty-cov
128127

129128
- name: Upload coverage data
130129
uses: actions/upload-artifact@v4

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ book
199199
# ignore generated files
200200
.cpp-linter_cache/
201201
cpp-linter-py/docs/cli_args.rst
202+
lcov.info
203+
coverage.json

cpp-linter-lib/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ library.
1111
See also the [CLI document hosted on github][gh-pages].
1212

1313
[pypi-org]: https://pypi.org/project/cpp-linter
14-
[gh-pages]: https://cpp-linter.github.io/cpp_linter_rs/cli_args.html
14+
[gh-pages]: https://cpp-linter.github.io/cpp_linter_rs/cli.html

cpp-linter-lib/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#![doc(html_logo_url = "https://github.com/cpp-linter/cpp-linter/raw/main/docs/_static/logo.png")]
21
#![doc(
3-
html_favicon_url = "https://github.com/cpp-linter/cpp-linter/raw/main/docs/_static/favicon.ico"
2+
html_logo_url = "https://github.com/cpp-linter/cpp_linter_rs/raw/main/docs/theme/favicon.png"
3+
)]
4+
#![doc(
5+
html_favicon_url = "https://github.com/cpp-linter/cpp_linter_rs/raw/main/docs/theme/favicon.png"
46
)]
57
#![doc = include_str!("../README.md")]
68

justfile

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
2+
3+
# activate python venv
4+
[group("python")]
5+
[windows]
6+
venv:
7+
./.env/Scripts/activate
8+
9+
# activate python venv
10+
[group("python")]
11+
[linux]
12+
venv:
13+
. ./.env/bin/activate
14+
15+
# install python bindings
16+
[group("python")]
17+
py-dev:
18+
maturin dev --manifest-path cpp-linter-py/Cargo.toml
19+
20+
# run the test suite
21+
[group("code coverage")]
22+
test:
23+
cargo llvm-cov --no-report nextest --manifest-path cpp-linter-lib/Cargo.toml --lib
24+
25+
# generate and open pretty coverage report
26+
[group("code coverage")]
27+
pretty-cov *args='':
28+
cargo llvm-cov report --json --output-path coverage.json
29+
@llvm-cov-pretty coverage.json {{ args }}
30+
31+
# generate and open detailed coverage report
32+
[group("code coverage")]
33+
llvm-cov *args='':
34+
cargo llvm-cov report --html {{ args }}
35+
36+
# This is useful for IDE gutter indicators of line coverage.
37+
# See Coverage Gutters ext in VSCode.
38+
# generate lcov.info
39+
[group("code coverage")]
40+
lcov:
41+
@cargo llvm-cov report --lcov --output-path lcov.info
42+
43+
# serve docs
44+
[group("docs")]
45+
docs open='':
46+
@mdbook serve docs {{ open }}
47+
48+
# build docs
49+
[group("docs")]
50+
docs-build:
51+
mdbook build docs --open
52+
53+
# rust docs
54+
[group("docs")]
55+
docs-rs:
56+
cargo doc --no-deps --lib --manifest-path cpp-linter-lib/Cargo.toml --open
57+
58+
# run cpp-linter native binary
59+
[group("bin")]
60+
run *args:
61+
cargo run --bin cpp-linter --manifest-path cpp-linter-lib/Cargo.toml -- {{ args }}
62+
63+
# The tool parameter can be set to 'cross' when cross compiling.
64+
65+
# build the native binary
66+
[group("bin")]
67+
build *args='':
68+
cargo build --bin cpp-linter --manifest-path cpp-linter-lib/Cargo.toml {{ args }}
69+
70+
# run clippy and rustfmt
71+
lint:
72+
cargo clippy --allow-staged --allow-dirty --fix
73+
cargo fmt
74+
75+
# bump version in root Cargo.toml
76+
bump component='patch':
77+
@python .github/workflows/bump_version.py {{ component }}

0 commit comments

Comments
 (0)