From 8320770ff6b30a47bf00e83c6041a51ee97770c0 Mon Sep 17 00:00:00 2001 From: pahor167 <47992132+pahor167@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:18:27 +0200 Subject: [PATCH] Compare git tags (#11096) --- packages/protocol/README.md | 22 ++++++++ packages/protocol/package.json | 3 +- .../protocol/scripts/bash/compare-git-tags.sh | 50 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 packages/protocol/scripts/bash/compare-git-tags.sh diff --git a/packages/protocol/README.md b/packages/protocol/README.md index f15bfd23679..ce103a070fb 100644 --- a/packages/protocol/README.md +++ b/packages/protocol/README.md @@ -286,3 +286,25 @@ How it works: 7. It calculates the size of the bytecode in kilobytes and appends the contract name, address, and size to the output file. Output: The output is a CSV file named `onchain_bytecode_sizes_.csv` in the `out` directory. Each line in the file contains a contract name, its implementation address, and its size in kilobytes. + + +# Compare releases and get PRs changing smart contracts + +To get the list of PRs that changed smart contracts between two releases, run: + +```sh +yarn compare-git-tags [git_tag/branch] [git_tag/branch] +``` + +Example: + +```sh +yarn compare-git-tags release/core-contracts/11 release/core-contracts/12 +``` + +Example output: + +PRs that made these changes: + +16442165a Deactivate BlochainParameters Contract on L2 (#11008) +198f6215a SortedLinkedList Foundry Migration (#10846) diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 584d5b2750b..95a534c0e53 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -54,7 +54,8 @@ "anvil-devchain:stop": "./scripts/foundry/stop_anvil.sh", "view-tags": "git for-each-ref 'refs/tags/core-contracts.*' --sort=-committerdate --format='%(color:magenta)%(committerdate:short) %(color:blue)%(tree) %(color:green)github.com/celo-org/celo-monorepo/releases/tag/%(color:yellow)%(refname:short)'", "generate-stabletoken-files": "yarn ts-node ./scripts/generate-stabletoken-files.ts", - "truffle-verify": "yarn truffle run verify" + "truffle-verify": "yarn truffle run verify", + "compare-git-tags": "./scripts/bash/compare-git-tags.sh" }, "dependencies": { "@0x/sol-compiler": "^4.8.3", diff --git a/packages/protocol/scripts/bash/compare-git-tags.sh b/packages/protocol/scripts/bash/compare-git-tags.sh new file mode 100755 index 00000000000..36aacb3b20d --- /dev/null +++ b/packages/protocol/scripts/bash/compare-git-tags.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Function to print usage +usage() { + echo "Usage: $0 " + exit 1 +} + +# Check if the correct number of arguments are provided +if [ "$#" -ne 2 ]; then + usage +fi + +# Assign input arguments to variables +BRANCH1=$1 +BRANCH2=$2 + +# Fetch the latest changes from the remote repository +git fetch + +# Get the list of changed Solidity files between the two branches/tags +# Exclude .t.sol files and files containing test/Test in the name +# Include only those in contracts or contracts-0.8 folders, regardless of their depth in the directory structure +CHANGED_FILES=$(git diff --name-only "$BRANCH1" "$BRANCH2" | grep -E '(.*/contracts/|.*/contracts-0.8/).*\.sol$' | grep -v '\.t\.sol$' | grep -v -i 'test') + +# Print the changed Solidity files +echo "Changed Solidity files between $BRANCH1 and $BRANCH2 (excluding *.t.sol and files containing 'test'/'Test' and including only contracts or contracts-0.8 folders):" + +CHANGED_FILES=$(echo "$CHANGED_FILES" | sed 's|^packages/protocol/||') +echo "$CHANGED_FILES" + +# Initialize an empty string for storing commits +COMMITS="" + +# Loop through each changed file and find the commits affecting those files between the two branches +for file in $CHANGED_FILES; do + FILE_COMMITS=$(git log --pretty=format:"%h %s" "$BRANCH1..$BRANCH2" -- "$file") + COMMITS+=$FILE_COMMITS + COMMITS+="\n" +done + +# Extract unique commits from the collected commit messages +UNIQUE_COMMITS=$(echo -e "$COMMITS" | sort | uniq) + +echo "" +echo "" +echo "********************************************" +echo "" +echo "PRs that made these changes:" +echo "$UNIQUE_COMMITS"