Skip to content

Commit

Permalink
chore: update abigen build script and go version src in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
RayXpub committed Feb 17, 2025
1 parent 6272fc5 commit 7d1b99c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 43 deletions.
14 changes: 1 addition & 13 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,10 @@ inputs:
runs:
using: composite
steps:
- name: Get Go Version
shell: bash
id: go-version
run: |
version=$(sed -ne '/^toolchain /s/^toolchain go//p' ${{ inputs.go-version-file }})
if [ -z "$version" ]; then
version=$(sed -ne '/^go /s/^go //p' ${{ inputs.go-version-file }})
echo "Toolchain version not found in ${{ inputs.go-version-file }}, using go directive instead."
fi
echo "Go Version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ steps.go-version.outputs.version }}
go-version-file: ${{ inputs.go-version-file }}
cache: false
check-latest: true

Expand Down
6 changes: 2 additions & 4 deletions core/gethwrappers/abigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"go/token"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -40,8 +39,7 @@ type AbigenArgs struct {
// Check whether native abigen is installed, and has correct version
func Abigen(a AbigenArgs) {
var versionResponse bytes.Buffer
abigenExecutablePath := filepath.Join(GetProjectRoot(), "tools/bin/abigen")
abigenVersionCheck := exec.Command(abigenExecutablePath, "--version")
abigenVersionCheck := exec.Command("abigen", "--version")
abigenVersionCheck.Stdout = &versionResponse
if err := abigenVersionCheck.Run(); err != nil {
Exit("no native abigen; you must install it (`make abigen` in the "+
Expand All @@ -64,7 +62,7 @@ func Abigen(a AbigenArgs) {
if a.Bin != "-" {
args = append(args, "-bin", a.Bin)
}
buildCommand := exec.Command(abigenExecutablePath, args...)
buildCommand := exec.Command("abigen", args...)
var buildResponse bytes.Buffer
buildCommand.Stderr = &buildResponse
if err := buildCommand.Run(); err != nil {
Expand Down
31 changes: 5 additions & 26 deletions tools/bin/build_abigen
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,19 @@
# Checks that the correct abigen is installed in this directory, and installs it
# if not.

set -e
set -euo pipefail

# Version of abigen to install. Must be run within chainlink project
GETH_VERSION=$(go list -json -m github.com/ethereum/go-ethereum | jq -r .Version)
GETH_REPO_URL="https://github.com/ethereum/go-ethereum"

function realpath { echo $(cd $(dirname $1); pwd)/$(basename $1); }
THIS_DIR="$(realpath "$(dirname $0)")"

NATIVE_ABIGEN_VERSION=v"$(
"$THIS_DIR/abigen" --version 2> /dev/null | \
grep -E -o '([0-9]+\.[0-9]+\.[0-9]+)'
abigen --version 2>/dev/null |
grep -E -o '([0-9]+\.[0-9]+\.[0-9]+)'
)" || true

if [ "$NATIVE_ABIGEN_VERSION" == "$GETH_VERSION" ]; then
if [ "$NATIVE_ABIGEN_VERSION" = "$GETH_VERSION" ]; then
echo "Correct abigen version already installed."
exit 0
fi

function cleanup() {
rm -rf "$TMPDIR"
}

trap cleanup EXIT

TMPDIR="$(mktemp -d)"

pushd "$TMPDIR"

git clone --depth=1 --single-branch --branch "$GETH_VERSION" "$GETH_REPO_URL"
cd go-ethereum/cmd/abigen
go build
rm -f "$THIS_DIR/abigen" # necessary on MacOS for code signing
cp ./abigen "$THIS_DIR"

popd

go install github.com/ethereum/go-ethereum/cmd/abigen@$GETH_VERSION

0 comments on commit 7d1b99c

Please sign in to comment.