From 0fff08c4fde939007df3a80591218bc2d211b75a Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Thu, 9 Jan 2025 13:30:45 +0100 Subject: [PATCH 1/5] chore(ci): automate finding base commit --- .github/workflows/libevm-delta.yml | 15 +++++----- .github/workflows/scripts/base-commit.sh | 35 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100755 .github/workflows/scripts/base-commit.sh diff --git a/.github/workflows/libevm-delta.yml b/.github/workflows/libevm-delta.yml index 791d1ee4a60..2b6a1a06dde 100644 --- a/.github/workflows/libevm-delta.yml +++ b/.github/workflows/libevm-delta.yml @@ -9,9 +9,6 @@ on: jobs: diffs: - env: - # Last commit from rename-module workflow job to be included in `main` - LIBEVM_BASE: 0b56af5a01b8a0c6fc9d60247bb79ffd03d1bcfd runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -19,25 +16,29 @@ jobs: fetch-depth: 0 # everything fetch-tags: true + - name: Find base commit hash + id: base-commit + run: echo "LIBEVM_BASE=$(.github/workflows/scripts/base-commit.sh)" >> "$GITHUB_OUTPUT" + - name: Color-blindness a11y run: | # https://davidmathlogic.com/colorblind/#%23D81B60-%231E88E5-%23FFC107-%23004D40:~:text=8%20pairs%20of%20contrasting%20colors git config color.diff.old "#DC3220"; git config color.diff.new "#005AB5"; - - name: git diff {LIBEVM_BASE} + - name: git diff ${{ steps.base-commit.outputs.LIBEVM_BASE }} run: | git diff --diff-filter=a --word-diff --unified=0 --color=always \ - "${LIBEVM_BASE}" \ + ${{ steps.base-commit.outputs.LIBEVM_BASE }} \ ':(exclude).golangci.yml' \ ':(exclude).github/**' \ ':(exclude)README.md'; - - name: git diff {LIBEVM_BASE}..main + - name: git diff ${{ steps.base-commit.outputs.LIBEVM_BASE }}..main run: | git checkout main --; git diff --diff-filter=a --word-diff --unified=0 --color=always \ - "${LIBEVM_BASE}" \ + "${{ steps.base-commit.outputs.LIBEVM_BASE }}" \ ':(exclude).golangci.yml' \ ':(exclude).github/**' \ ':(exclude)README.md'; diff --git a/.github/workflows/scripts/base-commit.sh b/.github/workflows/scripts/base-commit.sh new file mode 100755 index 00000000000..3b475c815c9 --- /dev/null +++ b/.github/workflows/scripts/base-commit.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# This script finds the base commit libevm changes should be considered from, +# and returns it to the caller. +# This base commit is the first child commit with its message containing +# "rename Go module + update internal import paths" of the last +# go-ethereum (aka geth) tag present in the main branch of libevm. +# If an error occurs, this one is echo-ed and the script exits with code 1. + +git remote add geth https://github.com/ethereum/go-ethereum.git +git fetch geth 'refs/tags/*:refs/tags/*' + +geth_tags=$(git ls-remote --tags --sort=-version:refname geth "v[1-9]*" | awk '{print $2}' | sed 's/refs\/tags\///') + +base_geth_tag_hash= +for geth_tag in $geth_tags; do + geth_tag_hash="$(git rev-parse $geth_tag)" + if git merge-base --is-ancestor $geth_tag_hash "origin/main"; then + base_geth_tag_hash="$geth_tag_hash" + break + fi +done + +if [ -z "$base_geth_tag_hash" ]; then + echo "No geth tag found in libevm main branch." + exit 1 +fi + +base_commit_hash="$(git log --oneline --grep="rename Go module + update internal import paths" --after "$base_geth_tag_hash" -n 1 origin/main | head -n 1 | awk '{print $1}')" +if [ -z "$base_commit_hash" ]; then + echo "No child commit found after tag $base_geth_tag_hash on branch main." + exit 1 +fi + +echo $base_commit_hash | tr -d '\n' \ No newline at end of file From 65917f0d70d5aa45eea689948b428c6c3a48c787 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Sun, 12 Jan 2025 19:03:20 +0100 Subject: [PATCH 2/5] Automate input of rename go module workflow --- .github/workflows/rename-module.yml | 14 ++++++------- .github/workflows/scripts/base-commit.sh | 18 +--------------- .github/workflows/scripts/geth-commit.sh | 26 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 25 deletions(-) create mode 100755 .github/workflows/scripts/geth-commit.sh diff --git a/.github/workflows/rename-module.yml b/.github/workflows/rename-module.yml index cb8b9dccbcd..0dbd352f7de 100644 --- a/.github/workflows/rename-module.yml +++ b/.github/workflows/rename-module.yml @@ -2,12 +2,6 @@ name: Rename Go module on: workflow_dispatch: - inputs: - source_commit: - description: "Upstream commit on which to base module renaming" - required: true - type: string - default: "2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1" jobs: rename-module: @@ -17,6 +11,10 @@ jobs: with: fetch-depth: 0 # everything + - name: Find base geth commit hash + id: geth-commit + run: echo "hash=$(.github/workflows/scripts/geth-commit.sh)" >> "$GITHUB_OUTPUT" + - name: Set variables id: vars # Including hashes of both the source commit and the workflow file makes @@ -25,11 +23,11 @@ jobs: WORKFLOW_HASH: ${{ hashFiles('.github/workflows/rename-module.yml') }} run: | echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT"; - echo "DEST_BRANCH=auto-rename-module_source-${{ inputs.source_commit }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \ + echo "DEST_BRANCH=auto-rename-module_source-${{ steps.geth-commit.outputs.hash }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \ >> "$GITHUB_OUTPUT"; - name: Check out source commit - run: git checkout ${{ inputs.source_commit }} + run: git checkout ${{ steps.geth-commit.outputs.hash }} - name: Globally update module name run: | diff --git a/.github/workflows/scripts/base-commit.sh b/.github/workflows/scripts/base-commit.sh index 3b475c815c9..f45e68222ba 100755 --- a/.github/workflows/scripts/base-commit.sh +++ b/.github/workflows/scripts/base-commit.sh @@ -7,24 +7,8 @@ # go-ethereum (aka geth) tag present in the main branch of libevm. # If an error occurs, this one is echo-ed and the script exits with code 1. -git remote add geth https://github.com/ethereum/go-ethereum.git -git fetch geth 'refs/tags/*:refs/tags/*' -geth_tags=$(git ls-remote --tags --sort=-version:refname geth "v[1-9]*" | awk '{print $2}' | sed 's/refs\/tags\///') - -base_geth_tag_hash= -for geth_tag in $geth_tags; do - geth_tag_hash="$(git rev-parse $geth_tag)" - if git merge-base --is-ancestor $geth_tag_hash "origin/main"; then - base_geth_tag_hash="$geth_tag_hash" - break - fi -done - -if [ -z "$base_geth_tag_hash" ]; then - echo "No geth tag found in libevm main branch." - exit 1 -fi +base_geth_tag_hash="$($(dirname "$0")/geth-commit.sh)" base_commit_hash="$(git log --oneline --grep="rename Go module + update internal import paths" --after "$base_geth_tag_hash" -n 1 origin/main | head -n 1 | awk '{print $1}')" if [ -z "$base_commit_hash" ]; then diff --git a/.github/workflows/scripts/geth-commit.sh b/.github/workflows/scripts/geth-commit.sh new file mode 100755 index 00000000000..72dee092d17 --- /dev/null +++ b/.github/workflows/scripts/geth-commit.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# This script finds the base commit corresponding to a geth tag +# from which libevm was last based on, and returns it to the caller. +# If an error occurs, this one is echo-ed and the script exits with code 1. + +git remote add geth https://github.com/ethereum/go-ethereum.git +git fetch geth 'refs/tags/*:refs/tags/*' + +geth_tags=$(git ls-remote --tags --sort=-version:refname geth "v[1-9]*" | awk '{print $2}' | sed 's/refs\/tags\///') + +base_geth_tag_hash= +for geth_tag in $geth_tags; do + geth_tag_hash="$(git rev-parse --short $geth_tag)" + if git merge-base --is-ancestor $geth_tag_hash "origin/main"; then + base_geth_tag_hash="$geth_tag_hash" + break + fi +done + +if [ -z "$base_geth_tag_hash" ]; then + echo "No geth tag found in libevm main branch." + exit 1 +fi + +echo $base_geth_tag_hash | tr -d '\n' From 898dabbd76f8299c486757610107749dc0ac3f77 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Mon, 13 Jan 2025 13:21:12 +0100 Subject: [PATCH 3/5] Leave manual input for rename-module workflow --- .github/workflows/rename-module.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rename-module.yml b/.github/workflows/rename-module.yml index 0dbd352f7de..cb8b9dccbcd 100644 --- a/.github/workflows/rename-module.yml +++ b/.github/workflows/rename-module.yml @@ -2,6 +2,12 @@ name: Rename Go module on: workflow_dispatch: + inputs: + source_commit: + description: "Upstream commit on which to base module renaming" + required: true + type: string + default: "2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1" jobs: rename-module: @@ -11,10 +17,6 @@ jobs: with: fetch-depth: 0 # everything - - name: Find base geth commit hash - id: geth-commit - run: echo "hash=$(.github/workflows/scripts/geth-commit.sh)" >> "$GITHUB_OUTPUT" - - name: Set variables id: vars # Including hashes of both the source commit and the workflow file makes @@ -23,11 +25,11 @@ jobs: WORKFLOW_HASH: ${{ hashFiles('.github/workflows/rename-module.yml') }} run: | echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT"; - echo "DEST_BRANCH=auto-rename-module_source-${{ steps.geth-commit.outputs.hash }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \ + echo "DEST_BRANCH=auto-rename-module_source-${{ inputs.source_commit }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \ >> "$GITHUB_OUTPUT"; - name: Check out source commit - run: git checkout ${{ steps.geth-commit.outputs.hash }} + run: git checkout ${{ inputs.source_commit }} - name: Globally update module name run: | From 66e23577be15e5ebf6c1ee53374d9da0f0bf317c Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Mon, 13 Jan 2025 13:24:18 +0100 Subject: [PATCH 4/5] Use `git rev-list` directly to find base commit --- .github/workflows/libevm-delta.yml | 2 +- .github/workflows/rename-module.yml | 1 + .github/workflows/scripts/base-commit.sh | 19 ----------------- .github/workflows/scripts/geth-commit.sh | 26 ------------------------ 4 files changed, 2 insertions(+), 46 deletions(-) delete mode 100755 .github/workflows/scripts/base-commit.sh delete mode 100755 .github/workflows/scripts/geth-commit.sh diff --git a/.github/workflows/libevm-delta.yml b/.github/workflows/libevm-delta.yml index 2b6a1a06dde..da565b9aa1a 100644 --- a/.github/workflows/libevm-delta.yml +++ b/.github/workflows/libevm-delta.yml @@ -18,7 +18,7 @@ jobs: - name: Find base commit hash id: base-commit - run: echo "LIBEVM_BASE=$(.github/workflows/scripts/base-commit.sh)" >> "$GITHUB_OUTPUT" + run: echo "LIBEVM_BASE=$(git rev-list --author "github-actions\[bot\]" --grep "\[AUTO\] rename Go module + update internal import paths" -n 1 origin/main)" >> "$GITHUB_OUTPUT" - name: Color-blindness a11y run: diff --git a/.github/workflows/rename-module.yml b/.github/workflows/rename-module.yml index cb8b9dccbcd..2d74418cd61 100644 --- a/.github/workflows/rename-module.yml +++ b/.github/workflows/rename-module.yml @@ -71,6 +71,7 @@ jobs: env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: + # WARNING: mirror any change to the commit_message value below in libevm-delta.yml commit_message: "[AUTO] rename Go module + update internal import paths\n\nWorkflow: ${{ steps.vars.outputs.WORKFLOW_HASH }} on branch ${{ github.ref_name }}" repo: ${{ github.repository }} branch: ${{ steps.vars.outputs.DEST_BRANCH }} diff --git a/.github/workflows/scripts/base-commit.sh b/.github/workflows/scripts/base-commit.sh deleted file mode 100755 index f45e68222ba..00000000000 --- a/.github/workflows/scripts/base-commit.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# This script finds the base commit libevm changes should be considered from, -# and returns it to the caller. -# This base commit is the first child commit with its message containing -# "rename Go module + update internal import paths" of the last -# go-ethereum (aka geth) tag present in the main branch of libevm. -# If an error occurs, this one is echo-ed and the script exits with code 1. - - -base_geth_tag_hash="$($(dirname "$0")/geth-commit.sh)" - -base_commit_hash="$(git log --oneline --grep="rename Go module + update internal import paths" --after "$base_geth_tag_hash" -n 1 origin/main | head -n 1 | awk '{print $1}')" -if [ -z "$base_commit_hash" ]; then - echo "No child commit found after tag $base_geth_tag_hash on branch main." - exit 1 -fi - -echo $base_commit_hash | tr -d '\n' \ No newline at end of file diff --git a/.github/workflows/scripts/geth-commit.sh b/.github/workflows/scripts/geth-commit.sh deleted file mode 100755 index 72dee092d17..00000000000 --- a/.github/workflows/scripts/geth-commit.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# This script finds the base commit corresponding to a geth tag -# from which libevm was last based on, and returns it to the caller. -# If an error occurs, this one is echo-ed and the script exits with code 1. - -git remote add geth https://github.com/ethereum/go-ethereum.git -git fetch geth 'refs/tags/*:refs/tags/*' - -geth_tags=$(git ls-remote --tags --sort=-version:refname geth "v[1-9]*" | awk '{print $2}' | sed 's/refs\/tags\///') - -base_geth_tag_hash= -for geth_tag in $geth_tags; do - geth_tag_hash="$(git rev-parse --short $geth_tag)" - if git merge-base --is-ancestor $geth_tag_hash "origin/main"; then - base_geth_tag_hash="$geth_tag_hash" - break - fi -done - -if [ -z "$base_geth_tag_hash" ]; then - echo "No geth tag found in libevm main branch." - exit 1 -fi - -echo $base_geth_tag_hash | tr -d '\n' From 58c37681f5a34dd7649872980e0c76bd3e8a31f0 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Mon, 13 Jan 2025 17:37:06 +0100 Subject: [PATCH 5/5] Use shorter `rename Go module` for grep-ing commit message --- .github/workflows/libevm-delta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libevm-delta.yml b/.github/workflows/libevm-delta.yml index da565b9aa1a..cd146748178 100644 --- a/.github/workflows/libevm-delta.yml +++ b/.github/workflows/libevm-delta.yml @@ -18,7 +18,7 @@ jobs: - name: Find base commit hash id: base-commit - run: echo "LIBEVM_BASE=$(git rev-list --author "github-actions\[bot\]" --grep "\[AUTO\] rename Go module + update internal import paths" -n 1 origin/main)" >> "$GITHUB_OUTPUT" + run: echo "LIBEVM_BASE=$(git rev-list --author "github-actions\[bot\]" --grep "rename Go module" -n 1 origin/main)" >> "$GITHUB_OUTPUT" - name: Color-blindness a11y run: