-
Notifications
You must be signed in to change notification settings - Fork 557
feat(ci): add changeset validation to solidity analysis workflows #7801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7a2fc38
feat(ci): add changeset validation to solidity analysis workflows
yorhodes 550e8df
fix: use spaces instead of tabs in shell scripts
yorhodes 6857933
fix: detect new/removed files in diff classification
yorhodes 84f8fbc
fix: treat new contracts as interface additions
yorhodes 65dcc94
Merge main into feat/solidity-changeset-validation
yorhodes fe1cf5e
fix: add directory existence check and handle unexpected exit codes
yorhodes 88088f8
fix: update interface tests for new exit code semantics
yorhodes 1c141df
refactor: simplify changeset validation using changeset status JSON o…
yorhodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||
| #!/bin/bash | ||
| # Analyzes a diff between two directories and validates changeset requirements | ||
| # Usage: check-diff-changeset.sh <analysis-type> <base-dir> <head-dir> | ||
| # analysis-type: bytecode | storage | ||
| # | ||
| # For bytecode: any change requires patch+ | ||
| # For storage: additions require minor+, removals require major | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ANALYSIS_TYPE=${1:-} | ||
| BASE_DIR=${2:-} | ||
| HEAD_DIR=${3:-} | ||
|
|
||
| if [ -z "$ANALYSIS_TYPE" ] || [ -z "$BASE_DIR" ] || [ -z "$HEAD_DIR" ]; then | ||
| echo "Usage: check-diff-changeset.sh <bytecode|storage> <base-dir> <head-dir>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify directories exist | ||
| if [ ! -d "$BASE_DIR" ]; then | ||
| echo "ERROR: Base directory does not exist: $BASE_DIR" | ||
| exit 1 | ||
| fi | ||
| if [ ! -d "$HEAD_DIR" ]; then | ||
| echo "ERROR: Head directory does not exist: $HEAD_DIR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| # Generate diff | ||
| DIFF_OUTPUT=$(diff --unified --recursive "$BASE_DIR" "$HEAD_DIR" || true) | ||
|
|
||
| if [ -z "$DIFF_OUTPUT" ]; then | ||
| echo "No $ANALYSIS_TYPE changes detected." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Detected $ANALYSIS_TYPE changes:" | ||
| echo "$DIFF_OUTPUT" | ||
| echo "" | ||
|
|
||
| # Classify changes | ||
| HAS_REMOVALS=false | ||
| HAS_ADDITIONS=false | ||
|
|
||
| # Check for removed lines in diff (lines starting with '-' but not '---') | ||
| if echo "$DIFF_OUTPUT" | grep -E '^-[^-]' >/dev/null; then | ||
| HAS_REMOVALS=true | ||
| fi | ||
| # Check for added lines in diff (lines starting with '+' but not '+++') | ||
| if echo "$DIFF_OUTPUT" | grep -E '^\+[^+]' >/dev/null; then | ||
| HAS_ADDITIONS=true | ||
| fi | ||
yorhodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Check for files only in base (removed files) - "Only in <base-dir>" | ||
| if echo "$DIFF_OUTPUT" | grep -E "^Only in ${BASE_DIR}" >/dev/null; then | ||
| HAS_REMOVALS=true | ||
| fi | ||
| # Check for files only in head (added files) - "Only in <head-dir>" | ||
| if echo "$DIFF_OUTPUT" | grep -E "^Only in ${HEAD_DIR}" >/dev/null; then | ||
| HAS_ADDITIONS=true | ||
| fi | ||
|
|
||
| # Determine required level based on analysis type and change classification | ||
| case "$ANALYSIS_TYPE" in | ||
| bytecode) | ||
| # Any bytecode change requires patch | ||
| REQUIRED_LEVEL="patch" | ||
| CHANGE_DESC="Bytecode changes" | ||
| ;; | ||
| storage) | ||
| if [ "$HAS_REMOVALS" = true ]; then | ||
| REQUIRED_LEVEL="major" | ||
| CHANGE_DESC="Storage layout removals (breaking change)" | ||
| elif [ "$HAS_ADDITIONS" = true ]; then | ||
| REQUIRED_LEVEL="minor" | ||
| CHANGE_DESC="Storage layout additions" | ||
| else | ||
| echo "No significant storage changes detected." | ||
| exit 0 | ||
| fi | ||
| ;; | ||
| *) | ||
| echo "Unknown analysis type: $ANALYSIS_TYPE" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| echo "$CHANGE_DESC detected." | ||
| echo "" | ||
|
|
||
| # Check for adequate changeset | ||
| if "$SCRIPT_DIR/check-solidity-changeset.sh" "$REQUIRED_LEVEL"; then | ||
| echo "" | ||
| echo "$CHANGE_DESC are permitted with the existing changeset." | ||
| exit 0 | ||
| else | ||
| echo "" | ||
| echo "ERROR: $CHANGE_DESC require a changeset for @hyperlane-xyz/core with at least a '$REQUIRED_LEVEL' bump." | ||
| exit 1 | ||
| fi | ||
This file contains hidden or 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,44 @@ | ||
| #!/bin/bash | ||
| # Checks if @hyperlane-xyz/core has a changeset at or above the required level | ||
| # Usage: check-solidity-changeset.sh <required-level> | ||
| # Levels: patch < minor < major | ||
| # Exit 0 if adequate changeset exists, exit 1 otherwise | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REQUIRED_LEVEL=${1:-} | ||
| PACKAGE="@hyperlane-xyz/core" | ||
|
|
||
| if [ -z "$REQUIRED_LEVEL" ]; then | ||
| echo "Usage: check-solidity-changeset.sh <patch|minor|major>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Get changeset status as JSON | ||
| # Note: changeset status --output requires a path relative to repo root | ||
| STATUS_FILE=".changeset-status-$$.json" | ||
| trap "rm -f $STATUS_FILE" EXIT | ||
| # changeset status exits non-zero when there are pending changesets, so ignore exit code | ||
| pnpm changeset status --output "$STATUS_FILE" 2>/dev/null || true | ||
|
|
||
| # Extract bump type for the package (only if it has explicit changesets, not transitive) | ||
| FOUND_LEVEL=$(jq -r --arg pkg "$PACKAGE" '.releases[] | select(.name == $pkg and (.changesets | length > 0)) | .type' "$STATUS_FILE") | ||
|
|
||
| # Map levels to numbers | ||
| level_to_num() { | ||
| case "$1" in | ||
| patch) echo 1 ;; minor) echo 2 ;; major) echo 3 ;; *) echo 0 ;; | ||
| esac | ||
| } | ||
|
|
||
| REQUIRED_NUM=$(level_to_num "$REQUIRED_LEVEL") | ||
| FOUND_NUM=$(level_to_num "$FOUND_LEVEL") | ||
|
|
||
| if [ "$FOUND_NUM" -ge "$REQUIRED_NUM" ]; then | ||
| echo "Found $PACKAGE changeset with '$FOUND_LEVEL' bump (required: $REQUIRED_LEVEL or higher)" | ||
| exit 0 | ||
| else | ||
| echo "No adequate changeset for $PACKAGE (found: ${FOUND_LEVEL:-none}, required: $REQUIRED_LEVEL or higher)" | ||
| echo "Run 'pnpm changeset' and select '$PACKAGE' with a '$REQUIRED_LEVEL' (or higher) bump." | ||
| exit 1 | ||
| fi |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.