Skip to content

Commit da4fd64

Browse files
committed
metadata changes
- move pre-commit local hooks into CI workflow and call org's reusable workflow - separate CLI options into categories and add a version subcommand (to print cpp-linter version) - consolidate cpp-linter-cli crate into cpp-linter-lib crate. - add vscode workspace config for recommended extensions - increment version in toml during CI runs
1 parent 7169129 commit da4fd64

26 files changed

+282
-185
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# to native line endings on checkout.
66
*.py text eol=lf
77
*.rst text eol=lf
8+
*.rs text eol=lf
9+
*.yaml text eol=lf
10+
*.yml text eol=lf
811
*.sh text eol=lf
912
*.cpp text eol=lf
1013
*.hpp text eol=lf

.github/dependabot.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: github-actions
9+
directory: /
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"
16+
- package-ecosystem: pip
17+
directory: /
18+
schedule:
19+
interval: "daily"
20+
groups:
21+
pip:
22+
patterns:
23+
- "*"

.github/workflows/binary-builds.yml

+30-65
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ jobs:
5353
permissions:
5454
contents: write
5555
steps:
56-
- name: Calculate Release Version
57-
id: calc-version
58-
run: |
59-
if [ "${{ github.event_name }}" = "pull_request" ]; then
60-
short_sha=$(echo "${{ github.sha }}" | awk '{print substr($0,0,5)}')
61-
echo "RELEASE_VERSION=nightly-$(date '+%Y-%m-%d')-$short_sha" >> $GITHUB_OUTPUT
62-
else
63-
echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
64-
fi
65-
6656
- name: Install native OpenSSL on Linux
6757
if: runner.os == 'Linux' && !(startsWith(matrix.target, 'aarch64') || endsWith(matrix.target, 'musl'))
6858
run: sudo apt-get install -y pkg-config libssl-dev
@@ -94,6 +84,15 @@ jobs:
9484
- name: Checkout
9585
uses: actions/checkout@v4
9686

87+
- uses: actions/setup-python@v5
88+
if: startsWith(github.ref, 'refs/tags/')
89+
with:
90+
python-version: '3.x'
91+
92+
- name: Increment version
93+
if: startsWith(github.ref, 'refs/tags/')
94+
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
95+
9796
- name: Setup Rust
9897
uses: dtolnay/rust-toolchain@stable
9998
with:
@@ -111,41 +110,21 @@ jobs:
111110
env:
112111
# problems with cross-compiling aarch64 linux with gnu
113112
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: /usr/bin/aarch64-linux-gnu-gcc
114-
run: cargo build --manifest-path cpp-linter-cli/Cargo.toml --release --bin cpp-linter-cli --target ${{ matrix.target }} ${{ steps.is-openssl-vendored.outputs.enabled }}
113+
run: cargo build --manifest-path cpp-linter-lib/Cargo.toml --release --bin cpp-linter --target ${{ matrix.target }} ${{ steps.is-openssl-vendored.outputs.enabled }}
115114

116-
- name: Prepare artifacts [Windows]
117-
shell: bash
118-
if: matrix.os == 'windows-latest'
119-
id: prep-artifacts-windows
120-
run: |
121-
release_dir="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}"
122-
artifact_path="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}-${{ matrix.target }}.zip"
123-
echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_OUTPUT
124-
mkdir $release_dir
125-
cp target/${{ matrix.target }}/release/cpp-linter-cli.exe $release_dir/
126-
cp LICENSE $release_dir/
127-
7z a -tzip $artifact_path $release_dir/
128-
- name: Prepare artifacts [Unix]
129-
shell: bash
130-
id: prep-artifacts-unix
131-
if: matrix.os != 'windows-latest'
132-
run: |
133-
release_dir="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}"
134-
artifact_path="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}-${{ matrix.target }}.tar.gz"
135-
echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_OUTPUT
136-
mkdir $release_dir
137-
cp target/${{ matrix.target }}/release/cpp-linter-cli $release_dir/
138-
cp LICENSE $release_dir
139-
tar -czvf $artifact_path $release_dir/
115+
- name: Prepare artifacts
116+
run: mv target/${{ matrix.target }}/release/cpp-linter${{ runner.os == 'Windows' && '.exe' || '' }} ./cpp-linter${{ runner.os == 'Windows' && '.exe' || '' }}
140117
- name: Upload artifacts
141118
uses: actions/upload-artifact@v4
142119
with:
143-
name: ${{ steps.prep-artifacts-unix.outputs.ARTIFACT_PATH || steps.prep-artifacts-windows.outputs.ARTIFACT_PATH }}
144-
path: ${{ steps.prep-artifacts-unix.outputs.ARTIFACT_PATH || steps.prep-artifacts-windows.outputs.ARTIFACT_PATH }}
120+
name: cpp-linter-${{ matrix.target }}
121+
path: |
122+
cpp-linter-${{ matrix.target }}
123+
cpp-linter-${{ matrix.target }}.exe
145124
if-no-files-found: error
146125

147126
create-release:
148-
if: startswith(github.ref, 'refs/tags')
127+
if: startswith(github.ref, 'refs/tagsv')
149128
runs-on: ubuntu-latest
150129
needs: [create-assets]
151130
permissions:
@@ -156,38 +135,24 @@ jobs:
156135
persist-credentials: false
157136
- name: Install Rust
158137
run: rustup update stable --no-self-update
138+
- uses: actions/setup-python@v5
139+
with:
140+
python-version: '3.x'
141+
- name: Increment version
142+
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
159143
- run: cargo package
144+
- name: Download built assets
145+
uses: actions/download-artifact@v4
146+
with:
147+
pattern: cpp-linter-*
148+
path: dist
160149
- name: Create a Github Release
161-
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
162150
env:
163151
GH_TOKEN: ${{ github.token }}
164-
run: gh release create ${{ github.ref_name }} --generate-notes
152+
run: |
153+
files=$(ls dist/mdbook-alerts_*/*{tar.gz,zip})
154+
gh release create ${{ github.ref_name }} --generate-notes $files
165155
- run: cargo publish
166156
working-directory: cpp-linter-lib
167157
env:
168158
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
169-
170-
upload-assets:
171-
needs: [create-release]
172-
runs-on: ubuntu-latest
173-
strategy:
174-
matrix:
175-
target:
176-
- aarch64-unknown-linux-gnu
177-
# skip this target due to cross-compiling OpenSSL for musl C lib
178-
# - aarch64-unknown-linux-musl
179-
- x86_64-unknown-linux-gnu
180-
- x86_64-unknown-linux-musl
181-
- aarch64-apple-darwin
182-
- x86_64-apple-darwin
183-
- x86_64-pc-windows-msvc
184-
steps:
185-
- name: Download build asset
186-
uses: actions/download-artifact@v4
187-
with:
188-
name: cpp-linter-cli-${{ matrix.target }}
189-
path: dist
190-
- name: Upload release assets
191-
env:
192-
GH_TOKEN: ${{ github.token }}
193-
run: gh release upload ${{ github.ref_name }} dist/cpp-linter-cli${{ contains(matrix.target, 'windows') || '.exe' }}%#%cpp-linter-cli_${{ matrix.target }} --clobber

.github/workflows/build-docs.yml

+12-27
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,20 @@ name: Docs
33
on: [push, workflow_dispatch]
44

55
jobs:
6-
build:
7-
permissions:
8-
contents: write
6+
build-sphinx:
7+
uses: cpp-linter/.github/.github/workflows/sphinx.yml@main
8+
with:
9+
path-to-doc: cpp-linter-py/docs/_build/html
10+
project-root: cpp-linter-py
11+
12+
build-rustdoc:
913
runs-on: ubuntu-latest
1014
steps:
1115
- uses: actions/checkout@v4
12-
13-
- uses: actions/setup-python@v5
14-
with:
15-
python-version: 3.x
16-
17-
- name: Install docs dependencies
18-
working-directory: cpp-linter-py
19-
run: pip install -r docs/requirements.txt
20-
21-
- name: Build docs
22-
working-directory: cpp-linter-py
23-
run: sphinx-build docs docs/_build/html
24-
25-
- name: upload docs build as artifact
16+
- run: rustup update --no-self-update
17+
- run: cargo doc --no-deps --manifest-path cpp-linter-lib/Cargo.toml
18+
- name: upload rustdoc build as artifact
2619
uses: actions/upload-artifact@v4
2720
with:
28-
name: "cpp-linter-py-docs"
29-
path: cpp-linter-py/docs/_build/html
30-
31-
- name: upload to github pages
32-
# only publish doc changes from main branch
33-
if: github.ref == 'refs/heads/main'
34-
uses: peaceiris/actions-gh-pages@v3
35-
with:
36-
github_token: ${{ secrets.GITHUB_TOKEN }}
37-
publish_dir: cpp-linter-py/docs/_build/html
21+
path: target/doc
22+
name: cpp-linter-lib_docs

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ name: Pre-commit
22

33
on:
44
push:
5+
branches: [main]
56
pull_request:
6-
types: opened
7+
branches: [main]
78

89
jobs:
9-
check-source-files:
10+
pre-commit:
11+
uses: cpp-linter/.github/.github/workflows/pre-commit.yml@main
12+
13+
cargo-tools:
1014
runs-on: ubuntu-latest
1115
steps:
1216
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v5
14-
with:
15-
python-version: '3.x'
16-
- run: python3 -m pip install pre-commit
17-
- run: pre-commit run --all-files
17+
- run: rustup update
18+
- name: cargo clippy
19+
run: cargo clippy
20+
- name: cargo fmt
21+
run: cargo fmt --check

.github/workflows/python-packaging.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
tags:
99
- '*'
1010
pull_request:
11+
branches:
12+
- main
13+
- master
1114
workflow_dispatch:
1215

1316
permissions:
@@ -30,7 +33,11 @@ jobs:
3033
- uses: actions/checkout@v4
3134
- uses: actions/setup-python@v5
3235
with:
33-
python-version: '3.10'
36+
python-version: '3.x'
37+
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 }}
3441

3542
- name: Calculate openssl-vendored
3643
shell: bash
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import argparse
2+
from pathlib import Path
3+
import sys
4+
5+
6+
class Args(argparse.Namespace):
7+
new_version: str = "2.0.0"
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("-n", "--new-version", required=True)
13+
args = parser.parse_args(namespace=Args())
14+
cargo_path = Path("Cargo.toml")
15+
if not cargo_path.exists():
16+
print("workspace Cargo.toml not in working directory")
17+
return 1
18+
doc = cargo_path.read_text(encoding="utf-8")
19+
version_pattern = 'version = "%s" # auto'
20+
old_version = version_pattern % "2.0.0"
21+
if old_version not in doc:
22+
print("Could not find version in Cargo.toml:\n", doc)
23+
return 1
24+
doc = doc.replace(old_version, version_pattern % args.new_version)
25+
cargo_path.write_text(doc, encoding="utf-8")
26+
return 0
27+
28+
29+
if __name__ == "__main__":
30+
sys.exit(main())

.pre-commit-config.yaml

-17
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,3 @@ repos:
2121
args: [ --fix ]
2222
# Run the python formatter.
2323
- id: ruff-format
24-
- repo: local
25-
# these hooks require a tools managed by the rustup installer
26-
hooks:
27-
# Run the rust formatter.
28-
# Run the rust linter.
29-
- id: cargo-clippy
30-
name: cargo clippy
31-
description: Lint all rust files with the clippy tool
32-
entry: cargo clippy --allow-staged --allow-dirty --fix
33-
language: rust
34-
pass_filenames: false
35-
- id: cargo-fmt
36-
name: cargo fmt
37-
description: Format all rust files with the rustfmt tool
38-
entry: cargo fmt
39-
language: rust
40-
pass_filenames: false

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
22

33
[workspace]
4-
members = ["cpp-linter-lib", "cpp-linter-cli", "cpp-linter-py"]
4+
members = ["cpp-linter-lib", "cpp-linter-py"]
55
resolver = "2"
66

77
[workspace.package]
8-
version = "2.0.0"
8+
version = "2.0.0" # auto
99
authors = [
1010
"Brendan Doherty",
1111
"Peter Shen",

cpp-linter-cli/.gitignore

-1
This file was deleted.

cpp-linter-cli/Cargo.toml

-14
This file was deleted.

cpp-linter-cli/LICENSE

-9
This file was deleted.

cpp-linter-lib/Cargo.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ documentation.workspace = true
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
clap = { version = ">=4.4.2" }
12-
git2 = ">=0.18.1"
11+
clap = { version = "4.5.15" }
12+
git2 = "0.19.0"
1313
lenient_semver = "0.4.2"
14-
log = ">=0.4.20"
14+
log = "0.4.22"
1515
openssl = { version = "0.10", features = ["vendored"], optional = true }
1616
openssl-probe = { version = "0.1", optional = true }
1717
regex = "1.10.2"
@@ -27,3 +27,7 @@ tempfile = "3.9.0"
2727

2828
[features]
2929
openssl-vendored = ["dep:openssl", "dep:openssl-probe"]
30+
31+
[[bin]]
32+
name = "cpp-linter"
33+
path = "src/main.rs"

cpp-linter-lib/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# cpp-linter-lib
2+
3+
This crate contains the the library used as a backend for the `cpp-linter` binary executable.
4+
5+
Since the [cpp-linter python package](https://pypi.org/project/cpp-linter/) now uses this library
6+
as a binding, the native binary's `main()` method is also present in the library.
7+
8+
See also the [CLI document hosted on github](https://cpp-linter.github.io/cpp_linter_rs/cli_args.html).

0 commit comments

Comments
 (0)