Skip to content

Commit 4c6e50e

Browse files
authored
chore: module-renaming workflow inverts between libevm and geth (#152)
## 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:"[email protected]" checkout main commit id:"[email protected]" 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:"[email protected]" ``` [^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 bc8e501 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 f2cecaf). 1. Run on `main` @ d32c7e0 changes from `libevm` to `go-ethereum`: a. [Run](https://github.com/ava-labs/libevm/actions/runs/13432588947/job/37527588744) b. [Commit](6288df9) 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](6f4f94e) c. [Auto-generated branch is identical to `main` at the time of running](d32c7e0...6f4f94e)
1 parent 739ba84 commit 4c6e50e

File tree

1 file changed

+66
-36
lines changed

1 file changed

+66
-36
lines changed

.github/workflows/rename-module.yml

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ name: Rename Go module
33
on:
44
workflow_dispatch:
55
inputs:
6-
source_commit:
7-
description: "Upstream commit on which to base module renaming"
6+
source:
7+
description: "Reference or commit on which to base module renaming"
88
required: true
99
type: string
10-
default: "2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1"
10+
default: "main"
11+
branch:
12+
description: "Branch to which a commit of the changes is pushed; leave blank for auto-naming. If non-existent, the branch is created."
13+
type: string
14+
default: ""
1115

1216
jobs:
1317
rename-module:
@@ -17,71 +21,97 @@ jobs:
1721
with:
1822
fetch-depth: 0 # everything
1923

24+
- run: git fetch --tags https://github.com/ethereum/go-ethereum.git
25+
26+
- run: git checkout ${{ inputs.source }}
27+
28+
- name: References pointing to source
29+
# NOTE: This step assumes that the source has been checked out, which
30+
# might not hold if reordered.
31+
run: |
32+
git branch --points-at HEAD;
33+
git tag --points-at HEAD;
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version-file: "go.mod"
39+
40+
- name: Detect Go module
41+
id: go
42+
run: |
43+
echo "MODULE=$(go list -m)" >> "$GITHUB_OUTPUT";
44+
echo "MODULE_SUFFIX=$(go list -m | cut -b 12-)" >> "$GITHUB_OUTPUT"; # Strip github.com/
45+
46+
- name: Validate Go module
47+
if: ${{ steps.go.outputs.MODULE != 'github.com/ava-labs/libevm' && steps.go.outputs.MODULE != 'github.com/ethereum/go-ethereum' }}
48+
run: echo "Unexpected Go module ${{ steps.go.outputs.MODULE }}" && exit 1;
49+
2050
- name: Set variables
2151
id: vars
22-
# Including hashes of both the source commit and the workflow file makes
23-
# this idempotent.
2452
env:
25-
WORKFLOW_HASH: ${{ hashFiles('.github/workflows/rename-module.yml') }}
53+
# `cond && ifTrue || ifFalse` is effectively a ternary operator, based on short-circuiting Boolean logic (assumes `ifTrue` is truthy)
54+
RENAME_TO: ${{ steps.go.outputs.MODULE_SUFFIX == 'ava-labs/libevm' && 'ethereum/go-ethereum' || 'ava-labs/libevm' }}
2655
run: |
56+
echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
57+
echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
2758
echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT";
28-
echo "DEST_BRANCH=auto-rename-module_source-${{ inputs.source_commit }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \
59+
echo "SOURCE_COMMIT=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT";
60+
echo "AUTO_BRANCH_NAME=auto/rename-module/to=${RENAME_TO}/src=$(git rev-parse HEAD)/workflow_sha=${{ github.workflow_sha }}/run=${{ github.run_id }}" \
2961
>> "$GITHUB_OUTPUT";
3062
31-
- name: Fetch tags from ethereum/go-ethereum
32-
run: git fetch --tags https://github.com/ethereum/go-ethereum.git
33-
34-
- name: Tags pointing to source commit
35-
run: git tag --points-at ${{ inputs.source_commit }}
36-
37-
- name: Check out source commit
38-
run: git checkout ${{ inputs.source_commit }}
39-
40-
- name: Globally update module name
63+
- name: Globally rename module from ${{ steps.vars.outputs.RENAME_FROM }} to ${{ steps.vars.outputs.RENAME_TO }}
4164
run: |
42-
go mod edit -module github.com/ava-labs/libevm;
65+
go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }};
4366
find . \
4467
-iname '*.go' \
4568
-o -iname '*.txt' \
4669
-o -iname '*.go.tpl' \
47-
-o -iname '*.proto' | xargs \
48-
sed -i -E 's|(["`]github\.com/)ethereum/go-ethereum|\1ava-labs/libevm|g';
70+
-o -iname '*.proto' \
71+
-not -wholename '*/libevm/tooling/*' | xargs \
72+
sed -i -E 's|(["`]github\.com/)${{ steps.vars.outputs.RENAME_FROM }}|\1${{ steps.vars.outputs.RENAME_TO }}|g';
4973
5074
- name: Remnant references
5175
run: |
5276
find . -type f | \
53-
xargs grep -In github.com/ethereum/go-ethereum | \
54-
grep -v "https://github.com/ethereum/go-ethereum"
55-
56-
- name: Set up Go
57-
uses: actions/setup-go@v5
58-
with:
59-
go-version-file: "go.mod"
77+
xargs grep -In github.com/${{ steps.vars.outputs.RENAME_FROM }} | \
78+
grep -v "https://github.com/${{ steps.vars.outputs.RENAME_FROM }}"
6079
6180
- name: Smoke tests
62-
# `go list` shows us the module name and grep will non-zero exit on mismatch
81+
# `go list -m` shows us the module name and grep will non-zero exit on mismatch
6382
# `go build` is a rudimentary but broad test of correctness
6483
# The explicitly tested packages are edge cases:
6584
# - bind generates tests and a go.mod on the fly
6685
# - rlpgen has testdata with imports that need updating
6786
run: |
68-
go list . | grep ava-labs/libevm;
87+
go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }};
6988
go build ./...;
7089
go test ./accounts/abi/bind ./rlp/rlpgen
7190
72-
- name: Create new branch
91+
- name: Set branch name
92+
id: branch
7393
env:
74-
BRANCH: ${{ steps.vars.outputs.DEST_BRANCH }}
94+
BRANCH: ${{ inputs.branch || steps.vars.outputs.AUTO_BRANCH_NAME }}
95+
run: echo "NAME=${BRANCH}" >> "$GITHUB_OUTPUT";
96+
97+
- name: Check out branch (create if non-existent)
98+
env:
99+
BRANCH: ${{ steps.branch.outputs.NAME }}
75100
run: |
76-
git checkout -b "${BRANCH}";
77-
git push origin "${BRANCH}";
101+
git checkout "${BRANCH}" 2>/dev/null || \
102+
(git checkout -b "${BRANCH}" && git push origin "${BRANCH}");
78103
79-
- name: Commit to new branch
104+
- name: Commit to branch
80105
uses: planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
81106
env:
82107
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
83108
with:
84109
# WARNING: mirror any change to the commit_message value below in libevm-delta.yml
85-
commit_message: "[AUTO] rename Go module + update internal import paths\n\nWorkflow: ${{ steps.vars.outputs.WORKFLOW_HASH }} on branch ${{ github.ref_name }}"
110+
commit_message: |
111+
[AUTO] rename Go module to ${{ steps.vars.outputs.RENAME_TO }}
112+
113+
Source: ${{ steps.vars.outputs.SOURCE_COMMIT }} (${{ inputs.source }})
114+
Workflow: ${{ github.workflow_sha }} (${{ github.workflow_ref }})
115+
Run ID: ${{ github.run_id }}
86116
repo: ${{ github.repository }}
87-
branch: ${{ steps.vars.outputs.DEST_BRANCH }}
117+
branch: ${{ steps.branch.outputs.NAME }}

0 commit comments

Comments
 (0)