mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 14:14:30 +00:00
## Why this should be merged
Originally I'd planned on doing an upstream sync by running the rename
workflow on the incoming commit and then merging it to `main` however
this resulted in hundreds of merge commits that were solely due to Go
imports. Renaming the module from `ava-labs/libevm` to
`ethereum/go-ethereum` removed 90% of conflicts (H/T @darioush). The
module will then need to be named `ava-labs/libevm` again, so the commit
history will probably[^1] look like this after an update:
```mermaid
---
config:
gitGraph:
mainBranchName: main
parallelCommits: true
---
gitGraph TB:
branch geth order:2
commit id:"geth@v1.15.2"
checkout main
commit id:"libevm@v1.13.14"
branch sync/v1.15.2
commit id:"[AUTO] rename to ethereum/go-ethereum"
merge geth
commit id:"[AUTO] rename to ava-labs/libevm"
checkout main
merge sync/v1.15.2 id:"libevm@v1.15.2"
```
[^1]: Specifics of and rationale behind the merge strategy are beyond
the scope of this PR.
## How this works
The current module name is determined with `go list -m` and the rename
from/to patterns are no longer hard-coded.
## How this was tested
Inspection of runs and resulting branch. Although these were the
bc8e5015694707ff682c444afff52a3801b35a53 workflow, the only other commit
in this PR is cosmetic (as seen in [this
run](https://github.com/ava-labs/libevm/actions/runs/13433886428) to
create f2cecaff9c01c86053644aafc9b7196229a84cbc).
1. Run on `main` @ d32c7e0090 changes from
`libevm` to `go-ethereum`:
a.
[Run](https://github.com/ava-labs/libevm/actions/runs/13432588947/job/37527588744)
b.
[Commit](6288df93f7)
c. Created branch `arr4n/auto/test-invertible-rename`
2. Re-run on `arr4n/auto/test-invertible-rename` changes back to
`libevm`:
a. [Run](https://github.com/ava-labs/libevm/actions/runs/13432810657)
b.
[Commit](6f4f94edd9)
c. [Auto-generated branch is identical to `main` at the time of
running](d32c7e0090...6f4f94edd9)
117 lines
4.7 KiB
YAML
117 lines
4.7 KiB
YAML
name: Rename Go module
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
source:
|
|
description: "Reference or commit on which to base module renaming"
|
|
required: true
|
|
type: string
|
|
default: "main"
|
|
branch:
|
|
description: "Branch to which a commit of the changes is pushed; leave blank for auto-naming. If non-existent, the branch is created."
|
|
type: string
|
|
default: ""
|
|
|
|
jobs:
|
|
rename-module:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # everything
|
|
|
|
- run: git fetch --tags https://github.com/ethereum/go-ethereum.git
|
|
|
|
- run: git checkout ${{ inputs.source }}
|
|
|
|
- name: References pointing to source
|
|
# NOTE: This step assumes that the source has been checked out, which
|
|
# might not hold if reordered.
|
|
run: |
|
|
git branch --points-at HEAD;
|
|
git tag --points-at HEAD;
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: "go.mod"
|
|
|
|
- name: Detect Go module
|
|
id: go
|
|
run: |
|
|
echo "MODULE=$(go list -m)" >> "$GITHUB_OUTPUT";
|
|
echo "MODULE_SUFFIX=$(go list -m | cut -b 12-)" >> "$GITHUB_OUTPUT"; # Strip github.com/
|
|
|
|
- name: Validate Go module
|
|
if: ${{ steps.go.outputs.MODULE != 'github.com/ava-labs/libevm' && steps.go.outputs.MODULE != 'github.com/ethereum/go-ethereum' }}
|
|
run: echo "Unexpected Go module ${{ steps.go.outputs.MODULE }}" && exit 1;
|
|
|
|
- name: Set variables
|
|
id: vars
|
|
env:
|
|
# `cond && ifTrue || ifFalse` is effectively a ternary operator, based on short-circuiting Boolean logic (assumes `ifTrue` is truthy)
|
|
RENAME_TO: ${{ steps.go.outputs.MODULE_SUFFIX == 'ava-labs/libevm' && 'ethereum/go-ethereum' || 'ava-labs/libevm' }}
|
|
run: |
|
|
echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
|
|
echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
|
|
echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT";
|
|
echo "SOURCE_COMMIT=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT";
|
|
echo "AUTO_BRANCH_NAME=auto/rename-module/to=${RENAME_TO}/src=$(git rev-parse HEAD)/workflow_sha=${{ github.workflow_sha }}/run=${{ github.run_id }}" \
|
|
>> "$GITHUB_OUTPUT";
|
|
|
|
- name: Globally rename module from ${{ steps.vars.outputs.RENAME_FROM }} to ${{ steps.vars.outputs.RENAME_TO }}
|
|
run: |
|
|
go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }};
|
|
find . \
|
|
-iname '*.go' \
|
|
-o -iname '*.txt' \
|
|
-o -iname '*.go.tpl' \
|
|
-o -iname '*.proto' \
|
|
-not -wholename '*/libevm/tooling/*' | xargs \
|
|
sed -i -E 's|(["`]github\.com/)${{ steps.vars.outputs.RENAME_FROM }}|\1${{ steps.vars.outputs.RENAME_TO }}|g';
|
|
|
|
- name: Remnant references
|
|
run: |
|
|
find . -type f | \
|
|
xargs grep -In github.com/${{ steps.vars.outputs.RENAME_FROM }} | \
|
|
grep -v "https://github.com/${{ steps.vars.outputs.RENAME_FROM }}"
|
|
|
|
- name: Smoke tests
|
|
# `go list -m` shows us the module name and grep will non-zero exit on mismatch
|
|
# `go build` is a rudimentary but broad test of correctness
|
|
# The explicitly tested packages are edge cases:
|
|
# - bind generates tests and a go.mod on the fly
|
|
# - rlpgen has testdata with imports that need updating
|
|
run: |
|
|
go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }};
|
|
go build ./...;
|
|
go test ./accounts/abi/bind ./rlp/rlpgen
|
|
|
|
- name: Set branch name
|
|
id: branch
|
|
env:
|
|
BRANCH: ${{ inputs.branch || steps.vars.outputs.AUTO_BRANCH_NAME }}
|
|
run: echo "NAME=${BRANCH}" >> "$GITHUB_OUTPUT";
|
|
|
|
- name: Check out branch (create if non-existent)
|
|
env:
|
|
BRANCH: ${{ steps.branch.outputs.NAME }}
|
|
run: |
|
|
git checkout "${BRANCH}" 2>/dev/null || \
|
|
(git checkout -b "${BRANCH}" && git push origin "${BRANCH}");
|
|
|
|
- name: Commit to branch
|
|
uses: planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
|
|
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 to ${{ steps.vars.outputs.RENAME_TO }}
|
|
|
|
Source: ${{ steps.vars.outputs.SOURCE_COMMIT }} (${{ inputs.source }})
|
|
Workflow: ${{ github.workflow_sha }} (${{ github.workflow_ref }})
|
|
Run ID: ${{ github.run_id }}
|
|
repo: ${{ github.repository }}
|
|
branch: ${{ steps.branch.outputs.NAME }}
|