@@ -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.
24
52
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' }}
26
55
run : |
56
+ echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
57
+ echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
27
58
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 }}" \
29
61
>> "$GITHUB_OUTPUT";
30
62
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 }}
41
64
run : |
42
- go mod edit -module github.com/ava-labs/libevm ;
65
+ go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }} ;
43
66
find . \
44
67
-iname '*.go' \
45
68
-o -iname '*.txt' \
46
69
-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';
49
73
50
74
- name : Remnant references
51
75
run : |
52
76
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 }}"
60
79
61
80
- 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
63
82
# `go build` is a rudimentary but broad test of correctness
64
83
# The explicitly tested packages are edge cases:
65
84
# - bind generates tests and a go.mod on the fly
66
85
# - rlpgen has testdata with imports that need updating
67
86
run : |
68
- go list . | grep ava-labs/libevm ;
87
+ go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }} ;
69
88
go build ./...;
70
89
go test ./accounts/abi/bind ./rlp/rlpgen
71
90
72
- - name : Create new branch
91
+ - name : Set branch name
92
+ id : branch
73
93
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 }}
75
100
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}") ;
78
103
79
- - name : Commit to new branch
104
+ - name : Commit to branch
80
105
uses : planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
81
106
env :
82
107
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
83
108
with :
84
109
# 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 }}"
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 }}
86
116
repo : ${{ github.repository }}
87
- branch : ${{ steps.vars .outputs.DEST_BRANCH }}
117
+ branch : ${{ steps.branch .outputs.NAME }}
0 commit comments