diff --git a/.github/actions/setup-test-environment/action.yml b/.github/actions/setup-test-environment/action.yml new file mode 100644 index 00000000..a075722e --- /dev/null +++ b/.github/actions/setup-test-environment/action.yml @@ -0,0 +1,42 @@ +name: "Setup Test Environment" +description: "Setup common environment for testing jobs" + +inputs: + python-version: + description: "Python version to setup" + required: true + default: "3.8" + +runs: + using: "composite" + steps: + - name: Setup protobuf compiler + uses: arduino/setup-protoc@v3 + with: + version: "26.1" + repo-token: ${{ github.token }} + + - name: Setup buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ github.token }} + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Setup caching for Rust + uses: Swatinem/rust-cache@v2 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + cache: "pip" + + - name: Setup ruff + shell: bash + run: | + pip install "ruff >= 0.7.0, < 0.8.0" + ruff --version diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c7b46196..89d4b1b1 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -14,27 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup protobuf compiler - uses: arduino/setup-protoc@v3 - with: - version: "26.1" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup buf - uses: bufbuild/buf-setup-action@v1 - with: - github_token: ${{ github.token }} - - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.8" - cache: "pip" - - - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Install dependencies run: | @@ -60,20 +41,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.8" - cache: "pip" - - - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - - - name: Install dependencies - run: | - pip install "python/ommx/[dev]" + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Regenerate stub file uses: actions-rs/cargo@v1 @@ -94,16 +63,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - name: Setup Environment + uses: ./.github/actions/setup-test-environment with: python-version: ${{ matrix.python-version }} - cache: "pip" - - - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - name: Install ommx run: | @@ -156,20 +119,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.8" - cache: "pip" - - - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - - - name: Install Dependencies - run: | - pip install -v -e 'python/ommx/[dev]' + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Format run: | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2ae37ef8..60df402d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,9 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Run cargo fmt run: cargo fmt --all -- --check @@ -25,13 +24,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy + + - name: Setup Environment + uses: ./.github/actions/setup-test-environment + - uses: giraffate/clippy-action@v1 with: reporter: "github-pr-check" - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ github.token }} clippy_flags: -- -Dwarnings test: @@ -40,10 +40,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Run tests run: cargo test @@ -54,18 +52,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - - - name: Setup protobuf compiler - uses: arduino/setup-protoc@v3 - with: - version: "26.1" - repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Environment + uses: ./.github/actions/setup-test-environment - name: Regenerate Rust codes from proto files run: cargo run --bin=protogen diff --git a/python/ommx-python-mip-adapter/pyproject.toml b/python/ommx-python-mip-adapter/pyproject.toml index acbb03b7..7257d3b3 100644 --- a/python/ommx-python-mip-adapter/pyproject.toml +++ b/python/ommx-python-mip-adapter/pyproject.toml @@ -41,7 +41,7 @@ dev = [ "numpy", "pyright", "pytest", - "ruff", + "ruff >= 0.7.0, < 0.8.0", "sphinx", "sphinx-autoapi", "sphinx_fontawesome", diff --git a/python/ommx/pyproject.toml b/python/ommx/pyproject.toml index 0ea3713e..f2cfbb27 100644 --- a/python/ommx/pyproject.toml +++ b/python/ommx/pyproject.toml @@ -43,7 +43,7 @@ dev = [ "networkx", "pyright", "pytest", - "ruff >= 0.4.4, < 0.5.0", + "ruff >= 0.7.0, < 0.8.0", "sphinx", "sphinx-autoapi", "sphinx_fontawesome", diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..43f86042 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,2 @@ +[format] +exclude = ["*.ipynb"]