Skip to content

Commit

Permalink
feat: GitHub action to rename module (#51)
Browse files Browse the repository at this point in the history
## 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).
  • Loading branch information
ARR4N authored Oct 11, 2024
1 parent 88c00c6 commit a8cc7bd
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/rename-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Rename Go module

on:
# During development, the next two lines MAY be enabled to have the PR
# automatically run this workflow for inspection of the resulting branch.
# However, they MUST be disabled again before merging otherwise *all* PRs will
# run this.
#
# pull_request:
# branches: [ main ]
workflow_dispatch:
inputs:
source_commit:
description: 'Upstream commit on which to base module renaming'
required: true
type: string
default: '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1'

jobs:
rename-module:
runs-on: ubuntu-latest
env:
source_commit: "${{ inputs.source_commit || '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1' }}"
# env variables cannot reference others so we have to duplicate the ||
output_branch: "${{ github.ref_name }}_auto-rename-module-${{ inputs.source_commit || '2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1' }}"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # everything
fetch-tags: true

- name: Check out source commit
run: git checkout ${{ env.source_commit }}

- name: Globally update module name
run: |
go mod edit -module github.com/ava-labs/libevm;
find . -iname '*.go' -o -iname '*.txt' | xargs sed -i -E \
's|(["`]github\.com/)ethereum/go-ethereum|\1ava-labs/libevm|g';
- name: Remnant references
run: |
find . -type f | \
xargs grep -In github.com/ethereum/go-ethereum | \
grep -v "https://github.com/ethereum/go-ethereum"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21.4

- name: Smoke tests
# `go list` shows us the module name and grep will non-zero exit on mismatch
# `go build` is a rudimentary but broad test of correctness
# The explicitly tested packages are edge cases:
# - bind generates tests and a go.mod on the fly
# - rlpgen has testdata with imports that need updating
run: |
go list . | grep ava-labs/libevm;
go build ./...;
go test ./accounts/abi/bind ./rlp/rlpgen
- name: Commit to new branch
uses: devops-infra/action-commit-push@8bc2ff9f9de7aa2a7581fc7e5b6401c04cab54c7
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_branch: ${{ env.output_branch }}
force: true
commit_prefix: "[AUTO] rename Go module + update internal import paths"

- name: Open PR to "renamed-go-module" iff workflow dispatched on "main"
# If we are changing the way in which we manage module renaming then it
# MUST go through PR review to main; only then can it open PRs.
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{ env.output_branch }}
target_branch: renamed-go-module
title: "[AUTO] Rename upstream Go module at `${{ env.source_commit }}`"
body: "_PR generated by GitHub Action_"

0 comments on commit a8cc7bd

Please sign in to comment.