From 5f86167883ebc191addf7dbc795513c016acf1a1 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Tue, 6 May 2025 15:18:34 +0200 Subject: [PATCH] Basic CI workflow (#57) * Delete unused release jobs and upgrade cargo-dist (#56) * Basic CI workflow * Specify permissions for docker build * Recursive checkout * Configure actionlint * Allow pre-releases * Add ruff (#58) --- .github/actionlint.yaml | 11 +++++ .github/workflows/build-docker.yml | 3 ++ .github/workflows/ci.yaml | 73 ++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 9 ++++ CONTRIBUTING.md | 2 +- pyproject.toml | 36 ++++++++++++++- 6 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 .github/actionlint.yaml create mode 100644 .github/workflows/ci.yaml diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml new file mode 100644 index 0000000..c3464e3 --- /dev/null +++ b/.github/actionlint.yaml @@ -0,0 +1,11 @@ +# Configuration for the actionlint tool, which we run via pre-commit +# to verify the correctness of the syntax in our GitHub Actions workflows. + +self-hosted-runner: + # Various runners we use that aren't recognized out-of-the-box by actionlint: + labels: + - depot-ubuntu-latest-8 + - depot-ubuntu-22.04-16 + - depot-ubuntu-22.04-32 + - github-windows-2025-x86_64-8 + - github-windows-2025-x86_64-16 diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 589ba93..761c361 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -20,6 +20,9 @@ on: env: TY_BASE_IMG: ghcr.io/${{ github.repository_owner }}/ty +permissions: + contents: read + jobs: docker-build: name: Build Docker image (ghcr.io/astral-sh/ty) for ${{ matrix.platform }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b3ccb15 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,73 @@ +name: CI + +permissions: + contents: read + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +env: + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + CARGO_TERM_COLOR: always + RUSTUP_MAX_RETRIES: 10 + PACKAGE_NAME: ty + +jobs: + python-package: + name: "python package" + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + submodules: recursive + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 + - name: "Build wheels" + uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1 + with: + args: --out dist + - name: "Test wheel" + run: | + pip install --force-reinstall --find-links dist "${PACKAGE_NAME}" --pre + ty --help + python -m ty --help + - name: "Remove wheels from cache" + run: rm -rf target/wheels + + pre-commit: + name: "pre-commit" + runs-on: depot-ubuntu-22.04-16 + timeout-minutes: 10 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2 + - name: "Cache pre-commit" + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + - name: "Run pre-commit" + run: | + echo '```console' > "$GITHUB_STEP_SUMMARY" + # Enable color output for pre-commit and remove it for the summary + # Use --hook-stage=manual to enable slower pre-commit hooks that are skipped by default + SKIP=cargo-fmt,clippy,dev-generate-all uvx --python="${PYTHON_VERSION}" pre-commit run --all-files --show-diff-on-failure --color=always --hook-stage=manual | \ + tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> "$GITHUB_STEP_SUMMARY") >&1 + exit_code="${PIPESTATUS[0]}" + echo '```' >> "$GITHUB_STEP_SUMMARY" + exit "$exit_code" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b05b8c7..fd877a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,15 @@ repos: hooks: - id: check-merge-conflict + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.8 + hooks: + - id: ruff-format + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + types_or: [python, pyi] + require_serial: true + - repo: https://github.com/abravalheri/validate-pyproject rev: v0.24.1 hooks: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e7a89a5..ad148f1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,7 +73,7 @@ git commit -m "Update ruff submodule to https://github.com/astral-sh/ruff/commit To restore the Ruff submodule to a clean-state, reset, then update the submodule: -``` +```bash git -C ruff reset --hard git submodule update ``` diff --git a/pyproject.toml b/pyproject.toml index d76ac35..ba782e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,9 +13,41 @@ cache-keys = [ { file = "dist-workspace.toml" }, { file = "ruff/Cargo.toml" }, { file = "ruff/Cargo.lock" }, - { file = "**/*.rs" } + { file = "**/*.rs" }, ] +[tool.ruff] +extend-exclude = ["ruff"] + +[tool.ruff.lint] +select = [ + "E", # pycodestyle (error) + "F", # pyflakes + "B", # bugbear + "B9", + "C4", # flake8-comprehensions + "SIM", # flake8-simplify + "I", # isort + "UP", # pyupgrade + "PIE", # flake8-pie + "PGH", # pygrep-hooks + "PYI", # flake8-pyi + "RUF", +] + +ignore = [ + # only relevant if you run a script with `python -0`, + # which seems unlikely for any of the scripts in this repo + "B011", + # Leave it to the formatter to split long lines and + # the judgement of all of us. + "E501", +] + +[tool.ruff.lint.isort] +required-imports = ["from __future__ import annotations"] + + [build-system] requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" @@ -32,7 +64,7 @@ include = [ "wheel", ] }, { path = "dist-workspace.toml", format = [ - "sdist" + "sdist", ] }, { path = "LICENSE", format = "sdist" }, ]