Skip to content

Commit a8cc7bd

Browse files
authored
feat: GitHub action to rename module (#51)
## Why this should be merged Automate renaming of the Go module from `github.com/ethereum/go-ethereum` to `github.com/ava-labs/libevm`. ## How this works Before starting this PR, I branched the `renamed-go-module` branch off `master` (the upstream geth branch; our default is called `main`). It has been protected to require PRs, which are automatically generated by the workflow introduced in this PR. The new workflow is designed to be manually dispatched with an input string of the commit hash to use as a source for renaming. On dispatch, it: 1. Checks out the source commit; 2. Renames the module; 3. Makes all necessary internal changes (e.g. import renaming); 4. Runs [smoke tests](https://en.wikipedia.org/wiki/Smoke_testing_(software)); 5. Commits the changes to a new branch; and 6. Opens a PR to merge the new branch into `renamed-go-module`. ### Intended usage When performing an upstream sync to pull in new geth code, this workflow will first be run against the geth commit we intend to merge. After the generated PR is merged, the `renamed-go-module` branch will be the one incorporated into `main`. Note that the `renamed-go-module` branch requires _two_ reviewers to approve. The user who dispatches the workflow SHOULD be one, with any other valid reviewer as the other. This is because a single-reviewer workflow would allow any user to update the `renamed-go-module` branch because the PR author is `github-actions`. ## How this was tested Inspection of the generated PR #57 as well as the [workflow run that generated it](https://github.com/ava-labs/libevm/actions/runs/11298471240/job/31427495426).
1 parent 88c00c6 commit a8cc7bd

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Rename Go module
2+
3+
on:
4+
# During development, the next two lines MAY be enabled to have the PR
5+
# automatically run this workflow for inspection of the resulting branch.
6+
# However, they MUST be disabled again before merging otherwise *all* PRs will
7+
# run this.
8+
#
9+
# pull_request:
10+
# branches: [ main ]
11+
workflow_dispatch:
12+
inputs:
13+
source_commit:
14+
description: 'Upstream commit on which to base module renaming'
15+
required: true
16+
type: string
17+
default: '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1'
18+
19+
jobs:
20+
rename-module:
21+
runs-on: ubuntu-latest
22+
env:
23+
source_commit: "${{ inputs.source_commit || '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1' }}"
24+
# env variables cannot reference others so we have to duplicate the ||
25+
output_branch: "${{ github.ref_name }}_auto-rename-module-${{ inputs.source_commit || '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1' }}"
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # everything
30+
fetch-tags: true
31+
32+
- name: Check out source commit
33+
run: git checkout ${{ env.source_commit }}
34+
35+
- name: Globally update module name
36+
run: |
37+
go mod edit -module github.com/ava-labs/libevm;
38+
find . -iname '*.go' -o -iname '*.txt' | xargs sed -i -E \
39+
's|(["`]github\.com/)ethereum/go-ethereum|\1ava-labs/libevm|g';
40+
41+
- name: Remnant references
42+
run: |
43+
find . -type f | \
44+
xargs grep -In github.com/ethereum/go-ethereum | \
45+
grep -v "https://github.com/ethereum/go-ethereum"
46+
47+
- name: Set up Go
48+
uses: actions/setup-go@v5
49+
with:
50+
go-version: 1.21.4
51+
52+
- name: Smoke tests
53+
# `go list` shows us the module name and grep will non-zero exit on mismatch
54+
# `go build` is a rudimentary but broad test of correctness
55+
# The explicitly tested packages are edge cases:
56+
# - bind generates tests and a go.mod on the fly
57+
# - rlpgen has testdata with imports that need updating
58+
run: |
59+
go list . | grep ava-labs/libevm;
60+
go build ./...;
61+
go test ./accounts/abi/bind ./rlp/rlpgen
62+
63+
- name: Commit to new branch
64+
uses: devops-infra/action-commit-push@8bc2ff9f9de7aa2a7581fc7e5b6401c04cab54c7
65+
with:
66+
github_token: ${{ secrets.GITHUB_TOKEN }}
67+
target_branch: ${{ env.output_branch }}
68+
force: true
69+
commit_prefix: "[AUTO] rename Go module + update internal import paths"
70+
71+
- name: Open PR to "renamed-go-module" iff workflow dispatched on "main"
72+
# If we are changing the way in which we manage module renaming then it
73+
# MUST go through PR review to main; only then can it open PRs.
74+
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
75+
uses: devops-infra/action-pull-request@v0.5.5
76+
with:
77+
github_token: ${{ secrets.GITHUB_TOKEN }}
78+
source_branch: ${{ env.output_branch }}
79+
target_branch: renamed-go-module
80+
title: "[AUTO] Rename upstream Go module at `${{ env.source_commit }}`"
81+
body: "_PR generated by GitHub Action_"

0 commit comments

Comments
 (0)