@@ -3,11 +3,15 @@ name: Rename Go module
33on :
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
1216jobs :
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.
52+ # Including hashes of both the source and the workflow file makes this
53+ # idempotent.
2454 env :
25- WORKFLOW_HASH : ${{ hashFiles('.github/workflows/rename-module.yml') }}
55+ RENAME_TO : ${{ steps.go.outputs.MODULE_SUFFIX == 'ava-labs/libevm' && 'ethereum/go-ethereum' || 'ava-labs/libevm' }}
2656 run : |
57+ echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
58+ echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
2759 echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT";
28- echo "DEST_BRANCH=auto-rename-module_source-${{ inputs.source_commit }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \
60+ echo "SOURCE_COMMIT=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT";
61+ echo "AUTO_BRANCH_NAME=auto/rename-module/to=${RENAME_TO}/src=$(git rev-parse HEAD)/workflow_sha=${{ github.workflow_sha }}" \
2962 >> "$GITHUB_OUTPUT";
3063
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
64+ - name : Globally rename module from ${{ steps.vars.outputs.RENAME_FROM }} to ${{ steps.vars.outputs.RENAME_TO }}
4165 run : |
42- go mod edit -module github.com/ava-labs/libevm ;
66+ go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }} ;
4367 find . \
4468 -iname '*.go' \
4569 -o -iname '*.txt' \
4670 -o -iname '*.go.tpl' \
47- -o -iname '*.proto' | xargs \
48- sed -i -E 's|(["`]github\.com/)ethereum/go-ethereum|\1ava-labs/libevm|g';
71+ -o -iname '*.proto' \
72+ -not -wholename '*/libevm/tooling/*' | xargs \
73+ sed -i -E 's|(["`]github\.com/)${{ steps.vars.outputs.RENAME_FROM }}|\1${{ steps.vars.outputs.RENAME_TO }}|g';
4974
5075 - name : Remnant references
5176 run : |
5277 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"
78+ xargs grep -In github.com/${{ steps.vars.outputs.RENAME_FROM }} | \
79+ grep -v "https://github.com/${{ steps.vars.outputs.RENAME_FROM }}"
6080
6181 - name : Smoke tests
62- # `go list` shows us the module name and grep will non-zero exit on mismatch
82+ # `go list -m ` shows us the module name and grep will non-zero exit on mismatch
6383 # `go build` is a rudimentary but broad test of correctness
6484 # The explicitly tested packages are edge cases:
6585 # - bind generates tests and a go.mod on the fly
6686 # - rlpgen has testdata with imports that need updating
6787 run : |
68- go list . | grep ava-labs/libevm ;
88+ go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }} ;
6989 go build ./...;
7090 go test ./accounts/abi/bind ./rlp/rlpgen
7191
72- - name : Create new branch
92+ - name : Set branch name
93+ id : branch
94+ env :
95+ BRANCH : ${{ inputs.branch || steps.vars.outputs.AUTO_BRANCH_NAME }}
96+ run : echo "NAME=${BRANCH}" >> "$GITHUB_OUTPUT";
97+
98+ - name : Check out branch (create if non-existent)
7399 env :
74- BRANCH : ${{ steps.vars .outputs.DEST_BRANCH }}
100+ BRANCH : ${{ steps.branch .outputs.NAME }}
75101 run : |
76- git checkout -b "${BRANCH}";
77- git push origin "${BRANCH}";
102+ git checkout "${BRANCH}" 2>/dev/null || \
103+ ( git checkout -b "${BRANCH}" && git push origin "${BRANCH}") ;
78104
79- - name : Commit to new branch
105+ - name : Commit to branch
80106 uses : planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
81107 env :
82108 GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
83109 with :
84110 # 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\n Workflow: ${{ steps.vars.outputs.WORKFLOW_HASH }} on branch ${{ github.ref_name }}"
111+ commit_message : |
112+ [AUTO] rename Go module to ${{ steps.vars.outputs.RENAME_TO }}
113+
114+ Source: ${{ steps.vars.outputs.SOURCE_COMMIT }} (${{ inputs.source }})
115+ Workflow: ${{ github.workflow_sha }} (${{ github.workflow_ref }})
86116 repo : ${{ github.repository }}
87- branch : ${{ steps.vars .outputs.DEST_BRANCH }}
117+ branch : ${{ steps.branch .outputs.NAME }}
0 commit comments