@@ -3,11 +3,15 @@ name: Rename Go module
3
3
on :
4
4
workflow_dispatch :
5
5
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"
8
8
required : true
9
9
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 : " "
11
15
12
16
jobs :
13
17
rename-module :
@@ -17,71 +21,97 @@ jobs:
17
21
with :
18
22
fetch-depth : 0 # everything
19
23
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
+
20
50
- name : Set variables
21
51
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.
24
54
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' }}
26
56
run : |
57
+ echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
58
+ echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
27
59
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 }}" \
29
62
>> "$GITHUB_OUTPUT";
30
63
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 }}
41
65
run : |
42
- go mod edit -module github.com/ava-labs/libevm ;
66
+ go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }} ;
43
67
find . \
44
68
-iname '*.go' \
45
69
-o -iname '*.txt' \
46
70
-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';
49
74
50
75
- name : Remnant references
51
76
run : |
52
77
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 }}"
60
80
61
81
- 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
63
83
# `go build` is a rudimentary but broad test of correctness
64
84
# The explicitly tested packages are edge cases:
65
85
# - bind generates tests and a go.mod on the fly
66
86
# - rlpgen has testdata with imports that need updating
67
87
run : |
68
- go list . | grep ava-labs/libevm ;
88
+ go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }} ;
69
89
go build ./...;
70
90
go test ./accounts/abi/bind ./rlp/rlpgen
71
91
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)
73
99
env :
74
- BRANCH : ${{ steps.vars .outputs.DEST_BRANCH }}
100
+ BRANCH : ${{ steps.branch .outputs.NAME }}
75
101
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}") ;
78
104
79
- - name : Commit to new branch
105
+ - name : Commit to branch
80
106
uses : planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
81
107
env :
82
108
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
83
109
with :
84
110
# 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 }})
86
116
repo : ${{ github.repository }}
87
- branch : ${{ steps.vars .outputs.DEST_BRANCH }}
117
+ branch : ${{ steps.branch .outputs.NAME }}
0 commit comments