Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/cpp-bmn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ permissions:
contents: read

jobs:
cargo:
runs-on: ubuntu-latest
defaults:
run:
working-directory: cpp/extractor/bmn
steps:
- uses: actions/checkout@v5
- name: Check formatting
run: cargo fmt --check
- name: Check
run: cargo check
- name: Test
run: cargo test

bazel:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ql-for-ql-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
~/.cargo/git
target
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}
- name: Check formatting
run: cd ql; cargo fmt -p codeql-extractor-ql -p buramu -p tree-sitter-blame -- --check
- name: Build extractor
run: |
cd ql;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Clippy on changed Rust code
name: Rust checks

# Run on every PR; package selection below skips lint setup for unrelated changes.
# Run on every PR; package selection below skips checks for unrelated changes.
on:
pull_request:
push:
Expand All @@ -14,11 +14,11 @@ permissions:
concurrency:
# Cancel superseded PR checks; each push gets its own group so GitHub cannot
# replace an already-pending push run with a newer one.
group: cargo-clippy-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
group: rust-checks-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
clippy:
rust-checks:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
Expand All @@ -28,15 +28,13 @@ jobs:
# PRs compare the merge commit with its first parent; pushes need full
# history to compare the event's before SHA across multi-commit pushes.
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Test package selection
run: python3 -m unittest discover -s misc/scripts/cargo-clippy
- name: Select affected packages
id: select
env:
# Use the PR merge base's actual first parent, or the push's before SHA.
BASE: ${{ github.event_name == 'pull_request' && 'HEAD^1' || github.event.before }}
run: |
packages=$(python3 misc/scripts/cargo-clippy/cargo_clippy.py select --base "$BASE")
packages=$(python3 misc/scripts/rust-checks/rust_checks.py select --base "$BASE")
echo "packages=$packages" >> "$GITHUB_OUTPUT"
echo "Selected packages: $packages" | tee -a "$GITHUB_STEP_SUMMARY"
- name: Restore Cargo cache
Expand All @@ -48,9 +46,9 @@ jobs:
~/.cargo/registry
~/.cargo/git
target
key: cargo-clippy-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}-${{ github.sha }}
key: rust-checks-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}-${{ github.sha }}
restore-keys: |
cargo-clippy-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}-
rust-checks-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}-
- name: Show stable toolchain and cache
if: steps.select.outputs.packages != '[]'
env:
Expand All @@ -62,11 +60,23 @@ jobs:
- name: Inject ast-generator sources
if: contains(fromJSON(steps.select.outputs.packages), 'ast-generator')
run: bazel run //rust/ast-generator:inject-sources
- name: Clippy
- name: Check formatting
if: steps.select.outputs.packages != '[]'
env:
PACKAGES: ${{ steps.select.outputs.packages }}
run: python3 misc/scripts/rust-checks/rust_checks.py format "$PACKAGES"
- name: Run Clippy
if: steps.select.outputs.packages != '[]'
env:
PACKAGES: ${{ steps.select.outputs.packages }}
# For the unified extractor: skip linking the native Swift shim and
# only check Rust code.
SWIFT_SYNTAX_RS_CHECK_ONLY: "1"
run: python3 misc/scripts/cargo-clippy/cargo_clippy.py lint "$PACKAGES"
run: python3 misc/scripts/rust-checks/rust_checks.py lint "$PACKAGES"
- name: Run tests
if: steps.select.outputs.packages != '[]'
env:
PACKAGES: ${{ steps.select.outputs.packages }}
# Skips the unified extractor crates, whose tests need a Swift toolchain,
# and ast-generator, which has no tests of its own.
run: python3 misc/scripts/rust-checks/rust_checks.py test "$PACKAGES"
34 changes: 0 additions & 34 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,6 @@ permissions:
contents: read

jobs:
rust-ast-generator:
runs-on: ubuntu-latest
defaults:
run:
working-directory: rust/ast-generator
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Inject sources
shell: bash
run: |
bazel run //rust/ast-generator:inject-sources
- name: Format
shell: bash
run: |
cargo fmt --check
- name: Compilation
shell: bash
run: cargo check
rust-code:
runs-on: ubuntu-latest
defaults:
run:
working-directory: rust/extractor
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Format
shell: bash
run: |
cargo fmt --check
- name: Compilation
shell: bash
run: cargo check
rust-codegen:
runs-on: ubuntu-latest
steps:
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/tree-sitter-extractor-test.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/yeast-test.yml

This file was deleted.

52 changes: 0 additions & 52 deletions misc/scripts/cargo-clippy/test_cargo_clippy.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env python3
"""Select root-workspace packages affected by a PR or push, and lint them with Clippy."""
"""Select root-workspace packages affected by a PR or push, then run Rust checks.

When changing this script, run its tests with:
python3 -m unittest discover -s misc/scripts/rust-checks
"""

import argparse
import json
Expand All @@ -16,9 +20,11 @@
"rust-toolchain.toml",
"clippy.toml",
".clippy.toml",
"rustfmt.toml",
".rustfmt.toml",
".cargo/",
".github/workflows/cargo-clippy.yml",
"misc/scripts/cargo-clippy/",
".github/workflows/rust-checks.yml",
"misc/scripts/rust-checks/",
)

# Inputs read by build scripts outside their package's directory.
Expand All @@ -30,6 +36,14 @@
".bazelversion": "rust/ast-generator",
}

# We skip running tests for:
# - The unified extractor and swift-syntax-rs: the tests link the swift-syntax
# parser, which needs a Swift toolchain that this workflow does not install.
# - The ast-generator: its only test comes from the injected rust-analyzer
# sources. They make no sense to run and expect the rust-analyzer repository
# layout.
UNTESTED_PACKAGES = {"codeql-extractor-unified", "swift-syntax-rs", "ast-generator"}


# Read workspace packages and map each package to its path dependents.
def workspace(root):
Expand Down Expand Up @@ -111,7 +125,28 @@ def lint(packages):
return subprocess.run([*args, "--", "-D", "warnings"]).returncode


# Parse the command and dispatch selection or linting.
# Run rustfmt on the selected packages and return its exit code.
def check_format(packages):
if not packages:
return 0
args = ["cargo", "fmt"]
for package in packages:
args.extend(["--package", package])
return subprocess.run([*args, "--", "--check"]).returncode


# Run tests for the selected packages and return Cargo's exit code.
def test(packages):
packages = [package for package in packages if package not in UNTESTED_PACKAGES]
if not packages:
return 0
args = ["cargo", "test", "--locked", "--no-fail-fast"]
for package in packages:
args.extend(["--package", package])
return subprocess.run(args).returncode


# Parse the command and dispatch selection or checks.
def main():
parser = argparse.ArgumentParser(description=__doc__)
commands = parser.add_subparsers(dest="command", required=True)
Expand All @@ -122,14 +157,27 @@ def main():
"--base", required=True,
help="PR merge's first parent, or push event's before SHA (zero for a new branch)",
)

lint_parser = commands.add_parser("lint", help="run Clippy on the given packages")
lint_parser.add_argument("packages", help="JSON list printed by the select command")

format_parser = commands.add_parser("format", help="check formatting of the given packages")
format_parser.add_argument("packages", help="JSON list printed by the select command")

test_parser = commands.add_parser("test", help="run tests for the given packages")
test_parser.add_argument("packages", help="JSON list printed by the select command")

args = parser.parse_args()
root = Path(__file__).resolve().parents[3]

if args.command == "select":
print(json.dumps(select(root, changed_files(root, args.base))))
else:
elif args.command == "lint":
raise SystemExit(lint(json.loads(args.packages)))
elif args.command == "format":
raise SystemExit(check_format(json.loads(args.packages)))
else:
raise SystemExit(test(json.loads(args.packages)))

if __name__ == "__main__":
main()
Loading
Loading