Commit 06e048c0 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #7874 from ethereum-optimism/tushar/client-pod-issue-131/initializer-ci-check

Issue 131: Verify Initializer Values in Contract & Genesis Match
parents 1bc3691b 72ac2547
......@@ -1231,6 +1231,28 @@ jobs:
name: check-generated-mocks
command: make generate-mocks-op-service && git diff --exit-code
check-values-match:
parameters:
pattern_file1:
type: string
default: ""
pattern_file2:
type: string
default: ""
file1_path:
type: string
default: ""
file2_path:
type: string
default: ""
docker:
- image: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:latest
steps:
- checkout
- run:
name: Verify Values Match
command: |
./ops/scripts/ci-match-values-between-files.sh "<< parameters.file1_path >>" "<< parameters.pattern_file1 >>" "<< parameters.file2_path >>" "<< parameters.pattern_file2 >>"
workflows:
main:
when:
......@@ -1477,7 +1499,11 @@ workflows:
- check-generated-mocks-op-service
- cannon-go-lint-and-test
- cannon-build-test-vectors
- check-values-match:
pattern_file1: "uint8 internal constant INITIALIZER ="
pattern_file2: "const initializedValue ="
file1_path: "packages/contracts-bedrock/src/libraries/Constants.sol"
file2_path: "op-chain-ops/genesis/config.go"
release:
when:
not:
......
#!/usr/bin/env bash
set -euo pipefail
FILE1=$1
PATTERN1=$2
FILE2=$3
PATTERN2=$4
# shellcheck disable=SC2016
SCRIPT='
BEGIN {
in_comment = 0;
matches = 0;
}
/^ *\/\*/ {
in_comment = 1;
}
in_comment && /\*\// {
in_comment = 0;
next;
}
!in_comment && !/^ *\/\// && $0 ~ PATTERN {
matches++;
matched_line = $0;
}
END {
if (matches == 1) {
print matched_line;
} else if (matches > 1) {
print "Multiple matches found. Exiting.";
exit 1;
} else {
print "No matches found. Exiting.";
exit 1;
}
}'
VALUE1_MATCH=$(echo "$SCRIPT" | awk -v PATTERN="$PATTERN1" -f- "$FILE1")
VALUE1=$(echo "$VALUE1_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value from File 1: $VALUE1"
VALUE2_MATCH=$(echo "$SCRIPT" | awk -v PATTERN="$PATTERN2" -f- "$FILE2")
VALUE2=$(echo "$VALUE2_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value from File 2: $VALUE2"
if [ "$VALUE1" != "$VALUE2" ]; then
echo "Error: Values from file1 ($VALUE1) and file2 ($VALUE2) don't match."
exit 1
fi
echo "Values match!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment