Skip to content

Rename Go module

Rename Go module #59

Workflow file for this run

name: Rename Go module
on:
workflow_dispatch:
inputs:
source:
description: "Reference or commit on which to base module renaming"
required: true
type: string
default: "main"
branch:
description: "Branch to which a commit of the changes is pushed; leave blank for auto-naming. If non-existent, the branch is created."
type: string
default: ""
jobs:
rename-module:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # everything
- run: git fetch --tags https://github.com/ethereum/go-ethereum.git
- run: git checkout ${{ inputs.source }}
- name: References pointing to source
# NOTE: This step assumes that the source has been checked out, which
# might not hold if reordered.
run: |
git branch --points-at HEAD;
git tag --points-at HEAD;
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Detect Go module
id: go
run: |
echo "MODULE=$(go list -m)" >> "$GITHUB_OUTPUT";
echo "MODULE_SUFFIX=$(go list -m | cut -b 12-)" >> "$GITHUB_OUTPUT"; # Strip github.com/
- name: Validate Go module
if: ${{ steps.go.outputs.MODULE != 'github.com/ava-labs/libevm' && steps.go.outputs.MODULE != 'github.com/ethereum/go-ethereum' }}
run: echo "Unexpected Go module ${{ steps.go.outputs.MODULE }}" && exit 1;
- name: Set variables
id: vars
# Including hashes of both the source and the workflow file makes this
# idempotent.
env:
RENAME_TO: ${{ steps.go.outputs.MODULE_SUFFIX == 'ava-labs/libevm' && 'ethereum/go-ethereum' || 'ava-labs/libevm' }}
run: |
echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT";
echo "SOURCE_COMMIT=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT";
echo "AUTO_BRANCH_NAME=auto/rename-module/to=${RENAME_TO}/src=$(git rev-parse HEAD)/workflow_sha=${{ github.workflow_sha }}" \
>> "$GITHUB_OUTPUT";
- name: Globally rename module from ${{ steps.vars.outputs.RENAME_FROM }} to ${{ steps.vars.outputs.RENAME_TO }}
run: |
go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }};
find . \
-iname '*.go' \
-o -iname '*.txt' \
-o -iname '*.go.tpl' \
-o -iname '*.proto' \
-not -wholename '*/libevm/tooling/*' | xargs \
sed -i -E 's|(["`]github\.com/)${{ steps.vars.outputs.RENAME_FROM }}|\1${{ steps.vars.outputs.RENAME_TO }}|g';
- name: Remnant references
run: |
find . -type f | \
xargs grep -In github.com/${{ steps.vars.outputs.RENAME_FROM }} | \
grep -v "https://github.com/${{ steps.vars.outputs.RENAME_FROM }}"
- name: Smoke tests
# `go list -m` 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 -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }};
go build ./...;
go test ./accounts/abi/bind ./rlp/rlpgen
- name: Set branch name
id: branch
env:
BRANCH: ${{ inputs.branch || steps.vars.outputs.AUTO_BRANCH_NAME }}
run: echo "NAME=${BRANCH}" >> "$GITHUB_OUTPUT";
- name: Check out branch (create if non-existent)
env:
BRANCH: ${{ steps.branch.outputs.NAME }}
run: |
git checkout "${BRANCH}" 2>/dev/null || \
(git checkout -b "${BRANCH}" && git push origin "${BRANCH}");
- name: Commit to branch
uses: planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
# WARNING: mirror any change to the commit_message value below in libevm-delta.yml
commit_message: |
[AUTO] rename Go module to ${{ steps.vars.outputs.RENAME_TO }}
Source: ${{ steps.vars.outputs.SOURCE_COMMIT }} (${{ inputs.source }})
Workflow: ${{ github.workflow_sha }} (${{ github.workflow_ref }})
repo: ${{ github.repository }}
branch: ${{ steps.branch.outputs.NAME }}