Skip to content

Commit

Permalink
ci: fix job that checks anvil state is up-to-date (#252)
Browse files Browse the repository at this point in the history
### Motivation
The previous CI job that checked whether the anvil state was up to date
was actually not performing any comparison at all (it was mistakenly
comparing empty files).

Checking that the anvil state is up to date by re-generating it and
comparing it with the existing one was not very practical since this
approach is very time-sensitive: any difference in the timestamps
generates a different state, which the CI wrongly takes as an outdated
state.

### What Changed?
This PR introduces the following changes in the CI:
* Removes the step that compares the anvil state in the tests CI job,
and simply checks that the script to generate the state works.
* Adds a new job that checks whether the anvil state is updated (it runs
only when the contracts change).


### Reviewer Checklist

- [ ] New features are tested and documented
- [ ] PR updates the changelog with a description of changes
- [ ] PR has one of the `changelog-X` labels (if applies)
- [ ] Code deprecates any old functionality before removing it

---------

Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
ricomateo and MegaRedHand committed Feb 4, 2025
1 parent 1fb4558 commit 8b211fd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/check-anvil-dump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Check anvil dump is up-to-date

on:
push:
branches: [main]

pull_request:
branches: [ '**' ]

jobs:
check:
name: Check anvil dump state is up to date
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

# This step is needed to know if the contracts were changed.
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
contracts:
- 'crates/contracts/lib/**'
- 'crates/contracts/script/**'
- 'crates/contracts/src/**'
# This step runs only if some contract changed.
# It checks the diff in the anvil state file.
# If the diff is null, that means the anvil state has not changed,
# i.e. the anvil state outdated and therefore this step will fail.
# Note: if the git diff fails to fetch the changes, then the step will also fail.
- name: Check the anvil dump has changed
if: steps.filter.outputs.contracts == 'true'
working-directory: crates/contracts/anvil/contracts_deployed_anvil_state.json
run: |
if [ -z "$(git diff origin/${{ github.event.pull_request.base.ref }} -- state.json)" ]; then
echo "The anvil dump is outdated";
exit 1
fi
23 changes: 4 additions & 19 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,12 @@ jobs:
name: coverage-summary
path: coverage.zip

check_anvil_dump:
generate_anvil_dump:
strategy:
fail-fast: true

name: Check anvil dump state is up to date
name: Generate anvil state
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./crates/contracts/anvil
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -116,18 +113,6 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- name: Backup existing anvil dump state
run: |
cd contracts_deployed_anvil_state.json
cp state.json previous_state.json

- name: Generate new anvil dump state
run: ./deploy-contracts-save-anvil-state.sh

- name: Check whether the anvil dump state has changed
run: |
cd contracts_deployed_anvil_state.json
jq --sort-keys . previous_state.json > previous_state.json
jq --sort-keys . state.json > state.json
diff previous_state.json state.json
- name: Generate anvil state
run: make deploy-contracts-to-anvil-and-save-state

0 comments on commit 8b211fd

Please sign in to comment.