-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(github): simplify contract-storage-diff workflow
- Loading branch information
1 parent
1e790a0
commit 4c02524
Showing
2 changed files
with
87 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
main() { | ||
# Get all changed files in the PR | ||
if ! CHANGED_FILES=$(git diff --name-only "$1" "$2" | grep "ensure_.*_storage_schema_is_unchanged.golden"); then | ||
echo "No storage schema changes detected" | ||
exit 0 | ||
fi | ||
|
||
echo "Found changed storage schema files:" | ||
echo "$CHANGED_FILES" | ||
|
||
# Check each changed storage schema file | ||
while IFS= read -r file; do | ||
[ -z "$file" ] && continue | ||
check_migration_file "$file" | ||
done <<< "$CHANGED_FILES" | ||
|
||
} | ||
|
||
check_migration_file() { | ||
local file="$1" | ||
|
||
local contract_dir | ||
contract_dir=$(contract_dir "$file") | ||
|
||
local migrate_file | ||
migrate_file=$(migrate_file "$contract_dir" "$file") | ||
|
||
local test_file | ||
test_file=$(test_file "$contract_dir" "$migrate_file") | ||
|
||
verify_legacy_storage_module "$migrate_file" | ||
|
||
echo "✓ Found valid migration file for $file" | ||
} | ||
|
||
contract_dir() { | ||
local file="$1" | ||
local contract_dir | ||
|
||
contract_dir=$(echo "$file" | grep -o 'contracts/stellar-[^/]*') | ||
[ -z "$contract_dir" ] && print_error "Could not determine contract directory for $file" | ||
|
||
echo "$contract_dir" | ||
} | ||
|
||
migrate_file() { | ||
local contract_dir="$1" | ||
local file="$2" | ||
local migrate_file | ||
|
||
migrate_file=$(find "$contract_dir/src" -name "migrate.rs" -not -path "*/test*" | head -n 1) | ||
[ -z "$migrate_file" ] && print_error "Storage schema change detected in $file but no migrate.rs found under $contract_dir/src/ | ||
Please create a migration file at $contract_dir/src/migrate.rs to handle the schema changes" | ||
|
||
echo "$migrate_file" | ||
} | ||
|
||
test_file() { | ||
local contract_dir="$1" | ||
local migrate_file="$2" | ||
local test_file | ||
|
||
test_file=$(find "$contract_dir" -path "*/test*/migrate.rs" -o -path "*/tests/migrate.rs" | head -n 1) | ||
[ -z "$test_file" ] && print_error "migrate.rs found at $migrate_file but no corresponding migrate.rs test file found | ||
Please create a test file at $contract_dir/tests/migrate.rs to test the schema migration" | ||
|
||
echo "$test_file" | ||
} | ||
|
||
verify_legacy_storage_module() { | ||
local migrate_file="$1" | ||
|
||
grep -q "mod legacy_storage" "$migrate_file" || print_error "migrate.rs found at $migrate_file but missing required 'legacy_storage' module declaration | ||
Please add a 'legacy_storage' module to handle the schema migration" | ||
} | ||
|
||
print_error() { | ||
echo "Error: $1" | ||
exit 1 | ||
} | ||
|
||
main "$@"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters