Skip to content

Commit 044e600

Browse files
committed
ci: replace storage layout diff check with OZ upgrade safety validation for PRs to dev
1 parent 5a33376 commit 044e600

File tree

3 files changed

+120
-101
lines changed

3 files changed

+120
-101
lines changed

.github/workflows/storage-layout-check.yml renamed to .github/workflows/upgrade-safety-check.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Storage Layout Check
1+
name: Upgrade Safety Check
22

33
on:
44
pull_request:
55
branches:
66
- dev
77

88
jobs:
9-
storage-layout:
9+
upgrade-safety:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout repository
@@ -24,5 +24,5 @@ jobs:
2424
- name: Fetch dev branch
2525
run: git fetch origin dev:refs/remotes/origin/dev
2626

27-
- name: Check SavingCircles storage layout
28-
run: ./scripts/check_storage_layout.sh origin/dev HEAD src/contracts/SavingCircles.sol:SavingCircles
27+
- name: Check SavingCircles upgrade safety
28+
run: ./scripts/check_upgrade_safety.sh origin/dev HEAD src/contracts/SavingCircles.sol:SavingCircles

scripts/check_storage_layout.sh

Lines changed: 0 additions & 97 deletions
This file was deleted.

scripts/check_upgrade_safety.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
OLD_REF="${1:-origin/dev}"
5+
NEW_REF="${2:-HEAD}"
6+
CONTRACT_TARGET="${3:-src/contracts/SavingCircles.sol:SavingCircles}"
7+
8+
ROOT_DIR="$(git rev-parse --show-toplevel)"
9+
TMP_DIR="$(mktemp -d)"
10+
OLD_DIR="$TMP_DIR/old"
11+
NEW_DIR="$TMP_DIR/new"
12+
13+
cleanup() {
14+
git -C "$ROOT_DIR" worktree remove "$OLD_DIR" --force >/dev/null 2>&1 || true
15+
git -C "$ROOT_DIR" worktree remove "$NEW_DIR" --force >/dev/null 2>&1 || true
16+
rm -rf "$TMP_DIR"
17+
}
18+
trap cleanup EXIT
19+
20+
require_cmd() {
21+
local cmd="$1"
22+
if ! command -v "$cmd" >/dev/null 2>&1; then
23+
echo "Missing required command: $cmd"
24+
exit 1
25+
fi
26+
}
27+
28+
ensure_node_modules_link() {
29+
local target_dir="$1"
30+
if [[ -d "$ROOT_DIR/node_modules" && ! -e "$target_dir/node_modules" ]]; then
31+
ln -s "$ROOT_DIR/node_modules" "$target_dir/node_modules"
32+
fi
33+
}
34+
35+
prepare_worktree() {
36+
local ref="$1"
37+
local dir="$2"
38+
39+
git -C "$ROOT_DIR" worktree add --detach "$dir" "$ref" >/dev/null
40+
41+
if [[ -f "$dir/.gitmodules" ]]; then
42+
git -C "$dir" submodule sync --recursive >/dev/null
43+
git -C "$dir" submodule update --init --recursive >/dev/null
44+
fi
45+
46+
ensure_node_modules_link "$dir"
47+
}
48+
49+
build_info_dir_for() {
50+
local workdir="$1"
51+
local out_dir
52+
53+
out_dir="$(cd "$workdir" && forge config --json | jq -r '.out // "out"')"
54+
echo "$workdir/$out_dir/build-info"
55+
}
56+
57+
compile_for_validation() {
58+
local workdir="$1"
59+
local label="$2"
60+
61+
echo "Compiling $label at $workdir ..."
62+
(
63+
cd "$workdir"
64+
forge clean
65+
forge build --build-info --extra-output storageLayout
66+
) >/dev/null
67+
68+
local build_info_dir
69+
build_info_dir="$(build_info_dir_for "$workdir")"
70+
71+
if [[ ! -d "$build_info_dir" ]]; then
72+
echo "Build info directory not found for $label: $build_info_dir"
73+
echo "Make sure foundry.toml enables build_info."
74+
exit 1
75+
fi
76+
77+
if ! find "$build_info_dir" -type f -name '*.json' | grep -q .; then
78+
echo "No build info JSON files found for $label in $build_info_dir"
79+
exit 1
80+
fi
81+
}
82+
83+
echo "Running OpenZeppelin upgrade safety validation for $CONTRACT_TARGET"
84+
echo "Old ref: $OLD_REF"
85+
echo "New ref: $NEW_REF"
86+
87+
require_cmd git
88+
require_cmd jq
89+
require_cmd forge
90+
require_cmd npx
91+
92+
prepare_worktree "$OLD_REF" "$OLD_DIR"
93+
compile_for_validation "$OLD_DIR" "$OLD_REF"
94+
95+
if [[ "$NEW_REF" == "HEAD" ]]; then
96+
compile_for_validation "$ROOT_DIR" "$NEW_REF"
97+
NEW_BUILD_INFO_DIR="$(build_info_dir_for "$ROOT_DIR")"
98+
else
99+
prepare_worktree "$NEW_REF" "$NEW_DIR"
100+
compile_for_validation "$NEW_DIR" "$NEW_REF"
101+
NEW_BUILD_INFO_DIR="$(build_info_dir_for "$NEW_DIR")"
102+
fi
103+
104+
OLD_BUILD_INFO_DIR="$(build_info_dir_for "$OLD_DIR")"
105+
106+
OLD_REF_BUILD_INFO_LINK="$TMP_DIR/old-build-info"
107+
ln -s "$OLD_BUILD_INFO_DIR" "$OLD_REF_BUILD_INFO_LINK"
108+
109+
echo "Validating upgrade safety with @openzeppelin/upgrades-core ..."
110+
OZ_UPGRADES_SILENCE_WARNINGS=true npx --yes @openzeppelin/upgrades-core validate "$NEW_BUILD_INFO_DIR" \
111+
--contract "$CONTRACT_TARGET" \
112+
--reference "old-build-info:$CONTRACT_TARGET" \
113+
--referenceBuildInfoDirs "$OLD_REF_BUILD_INFO_LINK" \
114+
--requireReference
115+
116+
echo "Upgrade safety check passed for $CONTRACT_TARGET"

0 commit comments

Comments
 (0)