Skip to content

Commit

Permalink
replace basic checks with pre-commit via action
Browse files Browse the repository at this point in the history
  • Loading branch information
drink7036290 committed Dec 18, 2024
1 parent ef64ac0 commit 7e064bb
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 115 deletions.
46 changes: 46 additions & 0 deletions .github/actions/basics/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Basic Checks"

runs:
using: "composite"
steps:
# 1. Check out repository
- uses: actions/checkout@v4

# 2. Set up Rust nightly toolchain
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.rust_nightly }}
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2

# 3. Set up Node.js for markdownlint
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"

- name: Install pre-commit
run: |
python3 -m venv venv
source venv/bin/activate
pip install pre-commit
# 4. Run pre-commit hooks on all files
- name: Run pre-commit
run: pre-commit run --all-files

# 5. Run linkspector
- name: Run linkspector
uses: umbrelladocs/action-linkspector@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
fail_on_error: true

inputs:
rust_nightly:
description: "Rust nightly toolchain version"
required: false
default: "nightly"
58 changes: 2 additions & 56 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,62 +287,8 @@ jobs:
# Basic actions that must pass before we kick off more expensive tests.
basics:
name: basic checks
runs-on: ubuntu-latest
needs:
- clippy
- rustfmt
- markdownlint
steps:
- run: exit 0

rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ env.rust_nightly }}
uses: dtolnay/rust-toolchain@stable
- uses: ./.github/actions/basics
with:
toolchain: ${{ env.rust_nightly }}
components: rustfmt
- uses: Swatinem/rust-cache@v2
# Check rustfmt
- name: "rustfmt --check"
# Workaround for rust-lang/cargo#7732
run: |
if ! rustfmt --check --edition 2024 $(git ls-files '*.rs'); then
printf "Please run \`rustfmt --edition 2024 \$(git ls-files '*.rs')\` to fix rustfmt errors.\n" >&2
exit 1
fi
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ env.rust_nightly }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_nightly }}
components: clippy
- uses: Swatinem/rust-cache@v2
# Run clippy
- name: "clippy --all"
run: cargo clippy --all --tests --all-features --no-deps

markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install markdownlint-cli
run: npm install -g markdownlint-cli

- name: Run markdownlint
run: markdownlint '**/*.md' --ignore node_modules
rust_nightly: ${{ env.rust_nightly }}
31 changes: 0 additions & 31 deletions .github/workflows/pr-cargo-deny.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/pr-check-link.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: PR Checks

on:
pull_request:

jobs:
basics:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/basics
with:
rust_nightly: nightly-2024-12-02
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
repos:
- repo: local
hooks:
# Rustfmt formatting check
- id: rustfmt
name: Rustfmt
language: system
entry: rustfmt
args: ["--edition", "2024", "--check"]
pass_filenames: true
files: \.rs$

# Cargo Clippy linting
- id: cargo-clippy
name: Cargo Clippy
language: system
entry: cargo
args:
[
"clippy",
"--all",
"--tests",
"--all-features",
"--no-deps",
"--",
"-D",
"warnings",
]
pass_filenames: false

# Cargo deny check
- id: cargo-deny
name: Cargo Deny
language: system
entry: cargo
args: ["deny", "check"]
pass_filenames: false

# Markdown linting
- id: markdownlint
name: Markdownlint
language: node
entry: markdownlint
args: ["--ignore", "node_modules"]
pass_filenames: true
files: \.md$
2 changes: 1 addition & 1 deletion implementations/q146_lru_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ intrusive-collections = "0.9.7"
rand = "0.8.5"
proptest = "1.5.0"
mockall = "0.13.1"
cache_util = { path = "../../utilities/cache_util" }
cache_util = { path = "../../utilities/cache_util", version = "0.1.0" }

[dev-dependencies]
rstest = "0.23.0"
Expand Down
2 changes: 1 addition & 1 deletion implementations/q460_lfu_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
[dependencies]
priority-queue = "2.1.1"
intrusive-collections = "0.9.7"
cache_util = { path = "../../utilities/cache_util" }
cache_util = { path = "../../utilities/cache_util", version = "0.1.0" }

[dev-dependencies]
rstest = "0.23.0"
Expand Down
12 changes: 0 additions & 12 deletions utilities/pre-commit

This file was deleted.

0 comments on commit 7e064bb

Please sign in to comment.