|
| 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