Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
18 changes: 17 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:

steps:
- uses: actions/checkout@v5
with:
# Initialize Ruff submodule
submodules: recursive

# First check Rust tests
- name: Install Rust toolchain
Expand All @@ -30,7 +33,20 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Run Rust tests
run: cargo test
shell: bash
run: |
# Build cargo test command with -p flags for each package
# We do so because the ruff submodule also contains crates and those will
# run if we don't limit the tests to only our packages.
# And `cargo test` command doesn't allow to exclude crates based on patterns.
#
# 1. Get all directories in our `crates/` folder
packages=$(find crates -maxdepth 1 -mindepth 1 -type d | \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relates to testing in CI.

So since the djc-safe-eval package contains ruff dependencies as git submodules, then simply calling cargo test will also run tests for those ruff packages. And there is one that fails. And because this is in CI, it blocked the pipeline.

So I wanted to exclude the Ruff packages from running their tests when in CI.

But the problem is that cargo test doesn't allow to exclude packages by pattern. Then I could've used ^ruff and call it a day.

Second option was to list all local packages, so only our packages run. But that's not a good design - I'm 100% that I'd forget to add a new Rust package to this file if I created one.

So the compromise here is to have a bit of script that lists all OUR packages (those in crates/), and then format the cargo test command to use only those packages:
cargo test -p <package> -p <package>

sed 's/crates\///' | \
tr '\n' ' ')
echo "Running tests for packages: $packages"
# 2. Format as `cargo test -p <package> -p <package> ...`
cargo test $(echo "$packages" | sed 's/\([^ ]*\)/-p \1/g')

# After Rust tests pass, run Python tests next
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "crates/djc-safe-eval/submodules/ruff"]
path = crates/djc-safe-eval/submodules/ruff
url = https://github.com/astral-sh/ruff.git
# tag = 0.14.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the first time that I was using git modules. I'm surprised that it's actually managed quite implicitly?

To change a commit/tag/branch of the "submodule", you have to:

  1. Navigate to that directory, e.g. crates/djc-safe-eval/submodules/ruff
  2. Use regular git commands to change the current head, e.g. git checkout 0.15.0
  3. And then navigate back and commit the change:
    cd ../../..
    git add .gitmodules crates/djc-safe-eval/submodules/ruff
    git commit -m "Update Ruff submodule to 0.15.0"

What I find strange about this is that you have to use git to find out what commit/tag/branch the submodule is on.

That's why I adding this tag = 0.14.0 comment, to keep these git submodules "pinned".

I documented the entire process in djc-safe-eval's README.

Loading
Loading