Skip to content

fix(contracts): prevent unnecessary build script triggers - #281

Merged
kariy merged 3 commits into
mainfrom
contracts-build-script
Sep 23, 2025
Merged

kariy merged 3 commits into
mainfrom
contracts-build-script

Conversation

@kariy

@kariy kariy commented Sep 22, 2025 •

Copy link
Copy Markdown
Member

Fixes build script triggering on every cargo build even when contract files haven't changed

Problem

The katana-contracts build script was being triggered unnecessarily on every cargo build command, even when no files in the crates/contracts/contracts directory had changed.

Root Causes

  • The build script was watching the entire contracts/ directory with cargo:rerun-if-changed=contracts/, which is unreliable in Cargo
  • scarb build updates Scarb.lock file timestamp even when content doesn't change

Solution

Instead of watching the entire contracts/ directory, the script watches the nested directories instead to avoid including Scarb.lock file in the watch list.

🤖 Generated with Claude Code

The build script was triggering on every cargo build even when contract
files hadn't changed. This was due to:
- Watching entire contracts/ directory instead of specific paths
- Scarb.lock being updated by scarb build, causing rebuild cycles
- No timestamp checking to skip builds when artifacts are up-to-date

Changes:
- Add explicit build script configuration in Cargo.toml
- Track specific source directories instead of entire contracts folder
- Add timestamp comparison to skip scarb build when sources unchanged
- Exclude Scarb.lock from tracked files since scarb updates it
- Add informative warnings showing when builds are skipped

This significantly speeds up the development workflow by only rebuilding
contracts when their source files actually change.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kariy
kariy marked this pull request as draft September 22, 2025 20:31
@blacksmith-sh blacksmith-sh Bot deleted a comment from kariy Sep 22, 2025
@kariy
kariy marked this pull request as ready for review September 22, 2025 21:14

kariy commented Sep 22, 2025 •

Copy link
Copy Markdown
Member Author

1 Job Failed:

test / dojo-integration-test failed on "Build and migrate `spawn-and-move` project"
[...]
                                   
🥷  Initializing 5 contracts...
                                 
🗡️  Initializing 5 contracts...
                                    
⛩️  Initializing 5 contracts...
                                   
🥷  Initializing 5 contracts...
                                 
🗡️  Initializing 5 contracts...
                                    


⛩️  Uploading metadata...error: Metadata upload failed.

Caused by:
    0: Failed to upload metadata
    1: Failed to upload to IPFS: ipfs client error `api returned an unknown error `internal service failure
       ``
Error: Process completed with exit code 1.

Summary: 1 failed workflow
  • ❌ test (7 jobs succeeded, 1 job failed)

Last updated: 2025-09-22 22:02:31 UTC

@codecov

codecov Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.85%. Comparing base (9bde0ae) to head (f32333a).
⚠️ Report is 118 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #281      +/-   ##
==========================================
+ Coverage   73.32%   75.85%   +2.52%     
==========================================
  Files         209      229      +20     
  Lines       23132    27062    +3930     
==========================================
+ Hits        16961    20527    +3566     
- Misses       6171     6535     +364     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kariy
kariy merged commit 291c572 into main Sep 23, 2025
17 of 18 checks passed
@kariy
kariy deleted the contracts-build-script branch September 23, 2025 13:41
kariy added a commit that referenced this pull request Sep 25, 2025
Fixes build script triggering on every `cargo build` even when contract files haven't changed

## Problem

The `katana-contracts` build script was being triggered unnecessarily on every `cargo build` command, even when no files in the `crates/contracts/contracts` directory had changed.

## Root Causes

* The build script was watching the entire `contracts/` directory with `cargo:rerun-if-changed=contracts/`, which is unreliable in Cargo
* `scarb build` updates `Scarb.lock` file timestamp even when content doesn't change

## Solution

Instead of watching the entire `contracts/` directory, the script watches the nested directories instead to avoid including `Scarb.lock` file in the watch list.

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
kariy added a commit that referenced this pull request Sep 25, 2025
Fixes build script triggering on every `cargo build` even when contract files haven't changed

## Problem

The `katana-contracts` build script was being triggered unnecessarily on every `cargo build` command, even when no files in the `crates/contracts/contracts` directory had changed.

## Root Causes

* The build script was watching the entire `contracts/` directory with `cargo:rerun-if-changed=contracts/`, which is unreliable in Cargo
* `scarb build` updates `Scarb.lock` file timestamp even when content doesn't change

## Solution

Instead of watching the entire `contracts/` directory, the script watches the nested directories instead to avoid including `Scarb.lock` file in the watch list.

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
github-merge-queue Bot pushed a commit that referenced this pull request Mar 10, 2026
The contracts build script tracked entire directories with
`cargo:rerun-if-changed`, which caused it to re-run on every `cargo
build` because `scarb build` modifies `Scarb.lock` and `target/` within
those directories. This replaces directory-level tracking with recursive
file-level tracking that excludes `Scarb.lock` files and `target/`
directories.

A similar PR ( #281 ) was made
to address the same issue. It worked but the fix was done under the
assumption that the `/contracts` directory is a single `Scarb`
workspace. But since #399, that is no longer the case as now it may
include git submodules which are independent `Scarb` workspace by
themselves.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant