Skip to content

Commit

Permalink
Custom GitHub Actions for install executables (#151)
Browse files Browse the repository at this point in the history
- Gather common setups in jobs into
`.github/actions/setup-test-environment`
- Upgrade ruff to 0.7.4
- Replace `pip install -ve python/ommx[dev]` by `pip install ruff` for
some cases
  • Loading branch information
termoshtt authored Nov 19, 2024
1 parent 912bf96 commit ea8fb05
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 82 deletions.
42 changes: 42 additions & 0 deletions .github/actions/setup-test-environment/action.yml
Original file line number Diff line number Diff line change
@@ -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
65 changes: 8 additions & 57 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
34 changes: 11 additions & 23 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/ommx-python-mip-adapter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dev = [
"numpy",
"pyright",
"pytest",
"ruff",
"ruff >= 0.7.0, < 0.8.0",
"sphinx",
"sphinx-autoapi",
"sphinx_fontawesome",
Expand Down
2 changes: 1 addition & 1 deletion python/ommx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[format]
exclude = ["*.ipynb"]

0 comments on commit ea8fb05

Please sign in to comment.