Skip to content

Commit adecf1f

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 adecf1f

26 files changed

+295
-169
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

+28-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,19 @@ 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-${{ matrix.target }}${{ 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: cpp-linter-${{ matrix.target }}*
145122
if-no-files-found: error
146123

147124
create-release:
148-
if: startswith(github.ref, 'refs/tags')
125+
if: startswith(github.ref, 'refs/tagsv')
149126
runs-on: ubuntu-latest
150127
needs: [create-assets]
151128
permissions:
@@ -156,38 +133,24 @@ jobs:
156133
persist-credentials: false
157134
- name: Install Rust
158135
run: rustup update stable --no-self-update
136+
- uses: actions/setup-python@v5
137+
with:
138+
python-version: '3.x'
139+
- name: Increment version
140+
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
159141
- run: cargo package
142+
- name: Download built assets
143+
uses: actions/download-artifact@v4
144+
with:
145+
pattern: cpp-linter-*
146+
path: dist
160147
- name: Create a Github Release
161-
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
162148
env:
163149
GH_TOKEN: ${{ github.token }}
164-
run: gh release create ${{ github.ref_name }} --generate-notes
150+
run: |
151+
files=$(ls dist/cpp-linter*
152+
gh release create ${{ github.ref_name }} --generate-notes $files
165153
- run: cargo publish
166154
working-directory: cpp-linter-lib
167155
env:
168156
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

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

55
jobs:
6-
build:
7-
permissions:
8-
contents: write
6+
build-sphinx:
97
runs-on: ubuntu-latest
108
steps:
119
- uses: actions/checkout@v4
12-
1310
- uses: actions/setup-python@v5
1411
with:
1512
python-version: 3.x
1613

17-
- name: Install docs dependencies
14+
- name: Install dependencies
1815
working-directory: cpp-linter-py
1916
run: pip install -r docs/requirements.txt
2017

2118
- name: Build docs
2219
working-directory: cpp-linter-py
2320
run: sphinx-build docs docs/_build/html
2421

25-
- name: upload docs build as artifact
22+
- name: Upload docs build as artifact
2623
uses: actions/upload-artifact@v4
2724
with:
28-
name: "cpp-linter-py-docs"
25+
name: cpp-linter-py_docs
2926
path: cpp-linter-py/docs/_build/html
3027

31-
- name: upload to github pages
28+
- name: Upload to github pages
3229
# only publish doc changes from main branch
3330
if: github.ref == 'refs/heads/main'
34-
uses: peaceiris/actions-gh-pages@v3
31+
uses: peaceiris/actions-gh-pages@v4
3532
with:
3633
github_token: ${{ secrets.GITHUB_TOKEN }}
3734
publish_dir: cpp-linter-py/docs/_build/html
35+
36+
build-rustdoc:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- run: rustup update --no-self-update
41+
- run: cargo doc --no-deps --manifest-path cpp-linter-lib/Cargo.toml
42+
- name: upload rustdoc build as artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
path: target/doc
46+
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

+16-3
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
@@ -77,8 +84,11 @@ jobs:
7784
- uses: actions/checkout@v4
7885
- uses: actions/setup-python@v5
7986
with:
80-
python-version: '3.10'
87+
python-version: '3.x'
8188
architecture: ${{ matrix.target }}
89+
- name: Increment version
90+
if: startsWith(github.ref, 'refs/tags/')
91+
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
8292
- name: Build wheels
8393
uses: PyO3/maturin-action@v1
8494
with:
@@ -100,7 +110,10 @@ jobs:
100110
- uses: actions/checkout@v4
101111
- uses: actions/setup-python@v5
102112
with:
103-
python-version: '3.10'
113+
python-version: '3.x'
114+
- name: Increment version
115+
if: startsWith(github.ref, 'refs/tags/')
116+
run: python .github/workflows/replace_version_spec.py --new-version=${{ github.ref_name }}
104117
- name: Build wheels
105118
uses: PyO3/maturin-action@v1
106119
with:
+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.

0 commit comments

Comments
 (0)