Skip to content

Commit a229b37

Browse files
authored
chore: cleanup CI and minor linting (#40)
1 parent 6474ce7 commit a229b37

File tree

12 files changed

+106
-100
lines changed

12 files changed

+106
-100
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,25 @@ updates:
33

44
# Maintain dependencies for GitHub Actions
55
- package-ecosystem: github-actions
6-
directory: "/"
7-
schedule:
8-
interval: weekly
6+
directory: '/'
7+
schedule: { interval: weekly }
98
groups:
109
all-actions-version-updates:
1110
applies-to: version-updates
12-
patterns:
13-
- "*"
11+
patterns: [ '*' ]
1412
all-actions-security-updates:
1513
applies-to: security-updates
16-
patterns:
17-
- "*"
14+
patterns: [ '*' ]
1815

1916
# Update Rust dependencies
2017
- package-ecosystem: cargo
21-
directory: "/"
22-
schedule:
23-
interval: daily
24-
time: "02:00"
18+
directory: '/'
19+
schedule: { interval: daily, time: '02:00' }
2520
open-pull-requests-limit: 10
2621
groups:
2722
all-cargo-version-updates:
2823
applies-to: version-updates
29-
patterns:
30-
- "*"
24+
patterns: [ '*' ]
3125
all-cargo-security-updates:
3226
applies-to: security-updates
33-
patterns:
34-
- "*"
27+
patterns: [ '*' ]

.github/workflows/ci.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8-
release:
9-
types: [ published ]
108
workflow_dispatch:
119

1210
defaults:
@@ -23,13 +21,8 @@ jobs:
2321
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
2422
uses: Swatinem/rust-cache@v2
2523
- uses: taiki-e/install-action@v2
26-
with: { tool: just }
27-
- if: github.event_name == 'release'
28-
name: Ensure this crate has not yet been published (on release)
29-
run: just check-if-published
24+
with: { tool: 'just,cargo-binstall' }
3025
- run: just ci-test
31-
- name: Check semver
32-
uses: obi1kenobi/cargo-semver-checks-action@v2
3326

3427
test-nightly:
3528
name: Nightly-specific tests
@@ -40,7 +33,7 @@ jobs:
4033
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
4134
uses: Swatinem/rust-cache@v2
4235
- uses: taiki-e/install-action@v2
43-
with: { tool: just }
36+
with: { tool: 'just' }
4437
- run: rustup install nightly --profile minimal
4538
- run: just test-publish
4639

@@ -53,7 +46,7 @@ jobs:
5346
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
5447
uses: Swatinem/rust-cache@v2
5548
- uses: taiki-e/install-action@v2
56-
with: { tool: just }
49+
with: { tool: 'just' }
5750
- name: Read MSRV
5851
id: msrv
5952
run: echo "value=$(just get-msrv)" >> $GITHUB_OUTPUT
@@ -81,15 +74,16 @@ jobs:
8174
with:
8275
token: ${{ secrets.CODECOV_TOKEN }}
8376
files: target/llvm-cov/codecov.info
84-
fail_ci_if_error: true
8577

8678
# This job checks if any of the previous jobs failed or were canceled.
8779
# This approach also allows some jobs to be skipped if they are not needed.
8880
ci-passed:
89-
if: always()
9081
needs: [ test, test-nightly, test-msrv ]
82+
if: always()
9183
runs-on: ubuntu-latest
9284
steps:
85+
- name: Result of the needed steps
86+
run: echo "${{ toJSON(needs) }}"
9387
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
9488
run: exit 1
9589

.github/workflows/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- name: Dependabot metadata
1212
id: metadata
13-
uses: dependabot/fetch-metadata@v2.4.0
13+
uses: dependabot/fetch-metadata@v2
1414
with:
1515
github-token: "${{ secrets.GITHUB_TOKEN }}"
1616
- name: Approve Dependabot PRs

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ repos:
1919
args: [ --fix=lf ]
2020
- id: trailing-whitespace
2121

22+
- repo: https://github.com/Lucas-C/pre-commit-hooks
23+
rev: v1.5.5
24+
hooks:
25+
- id: forbid-tabs
26+
- id: remove-tabs
27+
2228
- repo: local
2329
hooks:
2430
- id: cargo-fmt

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
name = "fastpfor"
33
version = "0.6.2"
44
description = "FastPFOR library written in Rust."
5-
authors = ["Francisco Jimenez <[email protected]>", "Yuri Astrakhan <[email protected]>"]
5+
authors = [
6+
"Francisco Jimenez <[email protected]>",
7+
"Yuri Astrakhan <[email protected]>",
8+
]
69
repository = "https://github.com/jjcfrancisco/fastpfor"
710
edition = "2021"
811
license = "MIT OR Apache-2.0"
@@ -21,26 +24,25 @@ rust = ["dep:thiserror"]
2124
cxx = { version = "1.0.136", optional = true }
2225
thiserror = { version = "2.0.7", optional = true }
2326

24-
[dev-dependencies]
25-
rand = "0.9.0"
26-
2727
[build-dependencies]
2828
cmake = { version = "0.1.52", optional = true }
2929
cxx-build = { version = "1.0.136", optional = true }
3030

31+
[dev-dependencies]
32+
rand = "0.9.0"
33+
3134
[lints.rust]
3235
dead_code = "allow"
3336
unused_assignments = "allow"
3437
unused_qualifications = "warn"
3538

3639
[lints.clippy]
40+
cargo = { level = "warn", priority = -1 }
3741
pedantic = { level = "warn", priority = -1 }
3842
cast_possible_truncation = "allow"
3943
cast_possible_wrap = "allow"
4044
cast_sign_loss = "allow"
4145
missing_errors_doc = "allow"
4246
missing_panics_doc = "allow"
4347
must_use_candidate = "allow"
44-
needless_range_loop = "allow"
45-
precedence = "allow"
4648
unreadable_literal = "allow"

LICENSE-APACHE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
193193
You may obtain a copy of the License at
194194

195-
http://www.apache.org/licenses/LICENSE-2.0
195+
http://www.apache.org/licenses/LICENSE-2.0
196196

197197
Unless required by applicable law or agreed to in writing, software
198198
distributed under the License is distributed on an "AS IS" BASIS,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,5 @@ Licensed under either of
118118

119119
Unless you explicitly state otherwise, any contribution intentionally
120120
submitted for inclusion in the work by you, as defined in the
121-
Apache-2.0 license, shall be dual licensed as above, without any
121+
Apache-2.0 license, shall be dual-licensed as above, without any
122122
additional terms or conditions.

justfile

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,42 @@
11
#!/usr/bin/env just --justfile
22

33
main_crate := 'fastpfor'
4+
features_flag := '--all-features'
45

56
# if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set
67
# Use `CI=true just ci-test` to run the same tests as in GitHub CI.
78
# Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS
8-
ci_mode := if env('CI', '') != '' { '1' } else { '' }
9+
ci_mode := if env('CI', '') != '' {'1'} else {''}
10+
# cargo-binstall needs a workaround due to caching
11+
# ci_mode might be manually set by user, so re-check the env var
12+
binstall_args := if env('CI', '') != '' {'--no-track'} else {''}
913
export RUSTFLAGS := env('RUSTFLAGS', if ci_mode == '1' {'-D warnings'} else {''})
1014
export RUSTDOCFLAGS := env('RUSTDOCFLAGS', if ci_mode == '1' {'-D warnings'} else {''})
1115
export RUST_BACKTRACE := env('RUST_BACKTRACE', if ci_mode == '1' {'1'} else {''})
1216

1317
@_default:
14-
just --list
18+
{{just_executable()}} --list
1519

1620
# Run integration tests and save its output as the new expected output
1721
bless *args: (cargo-install 'cargo-insta')
18-
TRYBUILD=overwrite cargo insta test --accept --unreferenced=delete --all-features
22+
cargo insta test --accept --unreferenced=delete {{features_flag}} {{args}}
1923

2024
# Build the project
2125
build:
22-
cargo build --workspace --all-targets --all-features
26+
cargo build --workspace --all-targets {{features_flag}}
2327

2428
# Quick compile without building a binary
2529
check:
26-
cargo check --workspace --all-targets --all-features
27-
28-
# Verify that the current version of the crate is not the same as the one published on crates.io
29-
check-if-published: (assert 'jq')
30-
#!/usr/bin/env bash
31-
set -euo pipefail
32-
LOCAL_VERSION="$({{just_executable()}} get-crate-field version)"
33-
echo "Detected crate version: '$LOCAL_VERSION'"
34-
CRATE_NAME="$({{just_executable()}} get-crate-field name)"
35-
echo "Detected crate name: '$CRATE_NAME'"
36-
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
37-
echo "Published crate version: '$PUBLISHED_VERSION'"
38-
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
39-
echo "ERROR: The current crate version has already been published."
40-
exit 1
41-
else
42-
echo "The current crate version has not yet been published."
43-
fi
30+
cargo check --workspace --all-targets {{features_flag}}
4431

4532
# Generate code coverage report to upload to codecov.io
46-
ci-coverage: && \
33+
ci-coverage: env-info && \
4734
(coverage '--codecov --output-path target/llvm-cov/codecov.info')
4835
# ATTENTION: the full file path above is used in the CI workflow
4936
mkdir -p target/llvm-cov
5037

5138
# Run all tests as expected by CI
52-
ci-test: env-info test-fmt build clippy test test-doc
53-
#!/usr/bin/env bash
54-
set -euo pipefail
55-
if [ -n "$(git status --untracked-files --porcelain)" ]; then
56-
>&2 echo 'ERROR: git repo is no longer clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified.'
57-
>&2 echo '######### git status ##########'
58-
git status
59-
exit 1
60-
fi
39+
ci-test: env-info test-fmt build clippy test test-doc && assert-git-is-clean
6140

6241
# Run minimal subset of tests to ensure compatibility with MSRV
6342
ci-test-msrv: env-info test
@@ -69,64 +48,73 @@ clean:
6948

7049
# Run cargo clippy to lint the code
7150
clippy *args:
72-
cargo clippy --workspace --all-targets --all-features {{args}}
51+
cargo clippy --workspace --all-targets {{features_flag}} {{args}}
7352

7453
# Generate code coverage report. Will install `cargo llvm-cov` if missing.
7554
coverage *args='--no-clean --open': (cargo-install 'cargo-llvm-cov')
76-
cargo llvm-cov --workspace --all-targets --all-features --include-build-script {{args}}
55+
cargo llvm-cov --workspace --all-targets {{features_flag}} --include-build-script {{args}}
7756

7857
# Build and open code documentation
79-
docs:
80-
cargo doc --no-deps --all-features --open
58+
docs *args='--open':
59+
DOCS_RS=1 cargo doc --no-deps {{args}} --workspace {{features_flag}}
8160

8261
# Print environment info
8362
env-info:
8463
@echo "Running {{if ci_mode == '1' {'in CI mode'} else {'in dev mode'} }} on {{os()}} / {{arch()}}"
64+
@echo "PWD $(pwd)"
8565
{{just_executable()}} --version
8666
rustc --version
8767
cargo --version
8868
rustup --version
8969
@echo "RUSTFLAGS='$RUSTFLAGS'"
9070
@echo "RUSTDOCFLAGS='$RUSTDOCFLAGS'"
71+
@echo "RUST_BACKTRACE='$RUST_BACKTRACE'"
9172

9273
# Reformat all code `cargo fmt`. If nightly is available, use it for better results
9374
fmt:
9475
#!/usr/bin/env bash
9576
set -euo pipefail
96-
if rustup component list --toolchain nightly | grep rustfmt &> /dev/null; then
77+
if (rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> /dev/null; then
9778
echo 'Reformatting Rust code using nightly Rust fmt to sort imports'
9879
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
9980
else
10081
echo 'Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
10182
cargo fmt --all
10283
fi
10384

85+
# Reformat all Cargo.toml files using cargo-sort
86+
fmt-toml *args: (cargo-install 'cargo-sort')
87+
cargo sort --workspace --grouped {{args}}
88+
10489
# Get any package's field from the metadata
105-
get-crate-field field package=main_crate:
106-
cargo metadata --format-version 1 | jq -r '.packages | map(select(.name == "{{package}}")) | first | .{{field}}'
90+
get-crate-field field package=main_crate: (assert-cmd 'jq')
91+
cargo metadata --format-version 1 | jq -e -r '.packages | map(select(.name == "{{package}}")) | first | .{{field}} | select(. != null)'
10792

10893
# Get the minimum supported Rust version (MSRV) for the crate
109-
get-msrv: (get-crate-field 'rust_version')
94+
get-msrv package=main_crate: (get-crate-field 'rust_version' package)
11095

11196
# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
11297
msrv: (cargo-install 'cargo-msrv')
113-
cargo msrv find --write-msrv --component rustfmt --all-features --ignore-lockfile -- {{just_executable()}} ci-test-msrv
98+
cargo msrv find --write-msrv --component rustfmt {{features_flag}} --ignore-lockfile -- {{just_executable()}} ci-test-msrv
99+
100+
# Run cargo-release
101+
release *args='': (cargo-install 'release-plz')
102+
release-plz {{args}}
114103

115104
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
116105
semver *args: (cargo-install 'cargo-semver-checks')
117-
cargo semver-checks {{args}}
106+
cargo semver-checks {{features_flag}} {{args}}
118107

119-
# Run all tests
108+
# Run all unit and integration tests
120109
test:
121-
cargo test --workspace --all-targets --all-features
110+
cargo test --workspace --all-targets {{features_flag}}
111+
cargo test --workspace --doc {{features_flag}}
122112

123-
# Test documentation
124-
test-doc:
125-
cargo test --doc --all-features
126-
cargo doc --all-features --no-deps
113+
# Test documentation generation
114+
test-doc: (docs '')
127115

128116
# Test code formatting
129-
test-fmt:
117+
test-fmt: && (fmt-toml '--check' '--check-format')
130118
cargo fmt --all -- --check
131119

132120
# Use the experimental workspace publishing with --dry-run. Requires nightly Rust.
@@ -135,7 +123,7 @@ test-publish:
135123

136124
# Find unused dependencies. Install it with `cargo install cargo-udeps`
137125
udeps: (cargo-install 'cargo-udeps')
138-
cargo +nightly udeps --all-targets --workspace --all-features
126+
cargo +nightly udeps --workspace --all-targets {{features_flag}}
139127

140128
# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
141129
update:
@@ -144,12 +132,23 @@ update:
144132

145133
# Ensure that a certain command is available
146134
[private]
147-
assert command:
135+
assert-cmd command:
148136
@if ! type {{command}} > /dev/null; then \
149137
echo "Command '{{command}}' could not be found. Please make sure it has been installed on your computer." ;\
150138
exit 1 ;\
151139
fi
152140

141+
# Make sure the git repo has no uncommitted changes
142+
[private]
143+
assert-git-is-clean:
144+
@if [ -n "$(git status --untracked-files --porcelain)" ]; then \
145+
>&2 echo "ERROR: git repo is no longer clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified." ;\
146+
>&2 echo "######### git status ##########" ;\
147+
git status ;\
148+
git --no-pager diff ;\
149+
exit 1 ;\
150+
fi
151+
153152
# Check if a certain Cargo command is installed, and install it if needed
154153
[private]
155154
cargo-install $COMMAND $INSTALL_CMD='' *args='':
@@ -160,7 +159,7 @@ cargo-install $COMMAND $INSTALL_CMD='' *args='':
160159
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
161160
cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}
162161
else
163-
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
164-
cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}}
162+
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{binstall_args}} --locked {{args}}"
163+
cargo binstall ${INSTALL_CMD:-$COMMAND} {{binstall_args}} --locked {{args}}
165164
fi
166165
fi

0 commit comments

Comments
 (0)