Skip to content

Commit 00bf489

Browse files
committed
rework CI jobs, cleanups
1 parent b7d911b commit 00bf489

File tree

4 files changed

+161
-81
lines changed

4 files changed

+161
-81
lines changed

.github/dependabot.yml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
version: 2
22
updates:
3-
# Maintain dependencies for GitHub Actions
4-
- package-ecosystem: "github-actions"
5-
directory: "/"
6-
schedule:
7-
interval: "weekly"
8-
- package-ecosystem: cargo
9-
directory: "/"
10-
schedule:
11-
interval: daily
12-
time: "02:00"
13-
open-pull-requests-limit: 10
3+
4+
# Maintain dependencies for GitHub Actions
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
groups:
10+
all-actions-version-updates:
11+
applies-to: version-updates
12+
patterns:
13+
- "*"
14+
all-actions-security-updates:
15+
applies-to: security-updates
16+
patterns:
17+
- "*"
18+
19+
# Update Rust dependencies
20+
- package-ecosystem: cargo
21+
directory: "/"
22+
schedule:
23+
interval: daily
24+
time: "02:00"
25+
open-pull-requests-limit: 10
26+
groups:
27+
all-cargo-version-updates:
28+
applies-to: version-updates
29+
patterns:
30+
- "*"
31+
all-cargo-security-updates:
32+
applies-to: security-updates
33+
patterns:
34+
- "*"

.github/workflows/ci.yml

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,88 @@ jobs:
1818
name: Test
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: taiki-e/install-action@v2
22-
with: { tool: 'just,cargo-llvm-cov' }
2321
- uses: actions/checkout@v4
2422
with: { submodules: recursive }
23+
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
24+
uses: Swatinem/rust-cache@v2
25+
- uses: taiki-e/install-action@v2
26+
with: { tool: just }
2527
- if: github.event_name == 'release'
2628
name: Ensure this crate has not yet been published (on release)
2729
run: just check-if-published
28-
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
29-
uses: Swatinem/rust-cache@v2
30-
- run: RUST_BACKTRACE=1 just -v ci-test
30+
- run: just ci-test
3131
- name: Check semver
3232
uses: obi1kenobi/cargo-semver-checks-action@v2
33-
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
34-
name: Generate code coverage
35-
run: just ci-coverage
36-
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
37-
name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@v5
39-
with:
40-
token: ${{ secrets.CODECOV_TOKEN }}
41-
files: target/llvm-cov/codecov.info
42-
fail_ci_if_error: false
43-
- name: Test packaging for publish
44-
run: |
45-
rustup install nightly --profile minimal
46-
just test-publish
4733

48-
msrv:
49-
name: Test MSRV
34+
test-nightly:
35+
name: Test
5036
runs-on: ubuntu-latest
5137
steps:
38+
- uses: actions/checkout@v4
39+
with: { submodules: recursive }
40+
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
41+
uses: Swatinem/rust-cache@v2
5242
- uses: taiki-e/install-action@v2
5343
with: { tool: just }
44+
- run: rustup install nightly --profile minimal
45+
- run: just test-publish
46+
47+
test-msrv:
48+
name: Test MSRV
49+
runs-on: ubuntu-latest
50+
steps:
5451
- uses: actions/checkout@v4
5552
with: { submodules: recursive }
5653
- if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
5754
uses: Swatinem/rust-cache@v2
55+
- uses: taiki-e/install-action@v2
56+
with: { tool: just }
5857
- name: Read MSRV
5958
id: msrv
60-
run: echo "value=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT
59+
run: echo "value=$(just get-msrv)" >> $GITHUB_OUTPUT
6160
- name: Install MSRV Rust ${{ steps.msrv.outputs.value }}
6261
uses: dtolnay/rust-toolchain@stable
6362
with:
6463
toolchain: ${{ steps.msrv.outputs.value }}
6564
components: rustfmt
66-
- run: just -v ci-test-msrv
65+
- run: just ci-test-msrv
66+
env:
67+
# Ignore warnings in MSRV. Sadly, this cannot be done inside `just ci-test-msrv`
68+
CI: ''
6769

68-
publish:
69-
if: startsWith(github.ref, 'refs/tags/')
70+
coverage:
71+
name: Code Coverage
72+
if: github.event_name != 'release'
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@v4
76+
- uses: Swatinem/rust-cache@v2
77+
- uses: taiki-e/install-action@v2
78+
with: { tool: 'just,cargo-llvm-cov' }
79+
- name: Generate code coverage
80+
run: just ci-coverage
81+
- name: Upload coverage to Codecov
82+
uses: codecov/codecov-action@v5
83+
with:
84+
token: ${{ secrets.CODECOV_TOKEN }}
85+
files: target/llvm-cov/codecov.info
86+
fail_ci_if_error: true
87+
88+
# This job checks if any of the previous jobs failed or were canceled.
89+
# This approach also allows some jobs to be skipped if they are not needed.
90+
ci-passed:
91+
if: always()
92+
needs: [ test, test-msrv, coverage ]
93+
runs-on: ubuntu-latest
94+
steps:
95+
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
96+
run: exit 1
97+
98+
release:
99+
# Some dependencies of the `ci-passed` job might be skipped, but we still want to run if the `ci-passed` job succeeded.
100+
if: always() && startsWith(github.ref, 'refs/tags/') && needs.ci-passed.result == 'success'
70101
name: Publish to crates.io
71-
needs: [ test, msrv ]
102+
needs: [ ci-passed ]
72103
runs-on: ubuntu-latest
73104
steps:
74105
- uses: actions/checkout@v4

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
*.pdb
33
.idea/
44
.vscode/
5-
Cargo.lock
65
codecov*
76
debug/
87
target/
98
temp/
109
tmp/
1110
venv/
11+
12+
# This is a library, no lock
13+
Cargo.lock

justfile

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
#!/usr/bin/env just --justfile
22

3+
main_crate := 'fastpfor'
4+
5+
# if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set
6+
# Use `CI=true just ci-test` to run the same tests as in GitHub CI.
7+
# Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS
8+
export RUSTFLAGS := env('RUSTFLAGS', if env('CI', '') == 'true' {'-D warnings'} else {''})
9+
export RUSTDOCFLAGS := env('RUSTDOCFLAGS', if env('CI', '') == 'true' {'-D warnings'} else {''})
10+
export RUST_BACKTRACE := env('RUST_BACKTRACE', if env('CI', '') == 'true' {'1'} else {''})
11+
312
@_default:
413
just --list
514

6-
# Run tests, and accept their results. Requires insta to be installed.
7-
bless: (cargo-install "cargo-insta")
8-
TRYBUILD=overwrite cargo insta test --accept --all-features
15+
# Run integration tests and save its output as the new expected output
16+
bless *args: (cargo-install 'cargo-insta')
17+
TRYBUILD=overwrite cargo insta test --accept --unreferenced=delete --all-features
918

10-
# Default build
11-
build *ARGS:
12-
cargo build --all-targets --workspace --all-features {{ARGS}}
19+
# Build the project
20+
build:
21+
cargo build --workspace --all-targets --all-features
1322

1423
# Quick compile without building a binary
1524
check:
1625
cargo check --workspace --all-targets --all-features
1726

1827
# Verify that the current version of the crate is not the same as the one published on crates.io
19-
check-if-published: (assert "jq")
28+
check-if-published: (assert 'jq')
2029
#!/usr/bin/env bash
2130
set -euo pipefail
22-
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
23-
echo "Detected crate version: $LOCAL_VERSION"
24-
CRATE_NAME="$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')"
25-
echo "Detected crate name: $CRATE_NAME"
31+
LOCAL_VERSION="$({{just_executable()}} get-crate-field version)"
32+
echo "Detected crate version: '$LOCAL_VERSION'"
33+
CRATE_NAME="$({{just_executable()}} get-crate-field name)"
34+
echo "Detected crate name: '$CRATE_NAME'"
2635
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
27-
echo "Published crate version: $PUBLISHED_VERSION"
36+
echo "Published crate version: '$PUBLISHED_VERSION'"
2837
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
2938
echo "ERROR: The current crate version has already been published."
3039
exit 1
@@ -39,64 +48,81 @@ ci-coverage: && \
3948
mkdir -p target/llvm-cov
4049

4150
# Run all tests as expected by CI
42-
ci-test: rust-info test-fmt
43-
RUSTFLAGS='-D warnings' {{just_executable()}} build
44-
{{just_executable()}} clippy -- -D warnings
45-
RUSTFLAGS='-D warnings' {{just_executable()}} test
46-
RUSTDOCFLAGS='-D warnings' {{just_executable()}} test-doc
51+
ci-test: env-info test-fmt build clippy test test-doc
52+
#!/usr/bin/env bash
53+
set -euo pipefail
54+
if [ -n "$(git status --untracked-files --porcelain)" ]; then
55+
>&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.'
56+
>&2 echo '######### git status ##########'
57+
git status
58+
exit 1
59+
fi
4760

4861
# Run minimal subset of tests to ensure compatibility with MSRV
49-
ci-test-msrv: rust-info test
62+
ci-test-msrv: env-info test
5063

5164
# Clean all build artifacts
5265
clean:
5366
cargo clean
5467
rm -f Cargo.lock
5568

5669
# Run cargo clippy to lint the code
57-
clippy *ARGS:
58-
cargo clippy --workspace --all-targets --all-features {{ARGS}}
70+
clippy *args:
71+
cargo clippy --workspace --all-targets --all-features {{args}}
5972

60-
# Generate code coverage report
61-
coverage *ARGS="--no-clean --open":
62-
cargo llvm-cov test --workspace --all-targets --all-features --include-build-script {{ARGS}}
73+
# Generate code coverage report. Will install `cargo llvm-cov` if missing.
74+
coverage *args='--no-clean --open': (cargo-install 'cargo-llvm-cov')
75+
cargo llvm-cov --workspace --all-targets --all-features --include-build-script {{args}}
6376

6477
# Build and open code documentation
6578
docs:
6679
cargo doc --no-deps --all-features --open
6780

81+
# Print environment info
82+
env-info:
83+
@echo "Running on {{os()}} / {{arch()}}"
84+
{{just_executable()}} --version
85+
rustc --version
86+
cargo --version
87+
rustup --version
88+
@echo "RUSTFLAGS='$RUSTFLAGS'"
89+
@echo "RUSTDOCFLAGS='$RUSTDOCFLAGS'"
90+
6891
# Reformat all code `cargo fmt`. If nightly is available, use it for better results
6992
fmt:
7093
#!/usr/bin/env bash
7194
set -euo pipefail
72-
if command -v cargo +nightly &> /dev/null; then
95+
if rustup component list --toolchain nightly | grep rustfmt &> /dev/null; then
7396
echo 'Reformatting Rust code using nightly Rust fmt to sort imports'
7497
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
7598
else
7699
echo 'Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
77100
cargo fmt --all
78101
fi
79102

103+
# Get any package's field from the metadata
104+
get-crate-field field package=main_crate:
105+
cargo metadata --format-version 1 | jq -r '.packages | map(select(.name == "{{package}}")) | first | .{{field}}'
106+
107+
# Get the minimum supported Rust version (MSRV) for the crate
108+
get-msrv: (get-crate-field 'rust_version')
109+
80110
# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
81-
msrv:
111+
msrv: (cargo-install 'cargo-msrv')
82112
cargo msrv find --write-msrv --component rustfmt --all-features --ignore-lockfile -- {{just_executable()}} ci-test-msrv
83113

84-
rust-info:
85-
rustc --version
86-
cargo --version
87-
88114
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
89-
semver *ARGS:
90-
cargo semver-checks {{ARGS}}
115+
semver *args: (cargo-install 'cargo-semver-checks')
116+
cargo semver-checks {{args}}
91117

92118
# Run all tests
93-
test *ARGS:
94-
cargo test --all-targets --workspace --all-features {{ARGS}}
119+
test:
120+
cargo test --workspace --all-targets --all-features
95121

96122
# Test documentation
97123
test-doc:
98124
cargo test --doc --all-features
99-
cargo doc --no-deps --all-features
125+
cargo doc --all-features --no-deps
100126

101127
# Test code formatting
102128
test-fmt:
@@ -107,7 +133,7 @@ test-publish:
107133
cargo +nightly -Z package-workspace publish --dry-run
108134

109135
# Find unused dependencies. Install it with `cargo install cargo-udeps`
110-
udeps:
136+
udeps: (cargo-install 'cargo-udeps')
111137
cargo +nightly udeps --all-targets --workspace --all-features
112138

113139
# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
@@ -117,23 +143,23 @@ update:
117143

118144
# Ensure that a certain command is available
119145
[private]
120-
assert $COMMAND:
121-
@if ! type "{{COMMAND}}" > /dev/null; then \
122-
echo "Command '{{COMMAND}}' could not be found. Please make sure it has been installed on your computer." ;\
146+
assert command:
147+
@if ! type {{command}} > /dev/null; then \
148+
echo "Command '{{command}}' could not be found. Please make sure it has been installed on your computer." ;\
123149
exit 1 ;\
124150
fi
125151

126152
# Check if a certain Cargo command is installed, and install it if needed
127153
[private]
128-
cargo-install $COMMAND $INSTALL_CMD="" *ARGS="":
154+
cargo-install $COMMAND $INSTALL_CMD='' *args='':
129155
#!/usr/bin/env bash
130156
set -euo pipefail
131157
if ! command -v $COMMAND > /dev/null; then
132158
if ! command -v cargo-binstall > /dev/null; then
133-
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} {{ARGS}}"
134-
cargo install ${INSTALL_CMD:-$COMMAND} {{ARGS}}
159+
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
160+
cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}
135161
else
136-
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{ARGS}}"
137-
cargo binstall ${INSTALL_CMD:-$COMMAND} {{ARGS}}
162+
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
163+
cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}}
138164
fi
139165
fi

0 commit comments

Comments
 (0)