Skip to content

Commit

Permalink
feat: verify bindings and auto publish packages on tag release (#130)
Browse files Browse the repository at this point in the history
* feat: verify bindings instead of generating them

* chore: implement build-go-contract-bindings

* chore: add bun lockfile

* feat: add bindings go module

* chore: move go module

* chore: tidy go module generation

* feat: add ts bindings

* chore: update workflow

* chore: generate all go bindings

* feat: auto update registries on tag releases

* bug: fix event name

* bug: add release environment to regestries job

* bug: fix linter dependencies

* bug: remove package-lock

* bug: replace node with bun in linter ci
  • Loading branch information
h5law authored Jun 27, 2024
1 parent 58e72d6 commit 941fe41
Show file tree
Hide file tree
Showing 40 changed files with 4,256 additions and 3,404 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Validate Bindings

on:
pull_request:
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
verify-bindings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.21.3"

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install ABIGen
run: |
go install github.com/ethereum/go-ethereum/cmd/abigen@v1.13.5
- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Generate Bindings
run: |
bun install --frozen-lockfile
bun run build
- name: Check for Go Bindings Changes
run: |
if [ $(git status --porcelain | sed 's/^...//' | grep bindings/ | wc -l) -ne 0 ]; then
echo "Changes in Go Bindings"
echo $(git status --porcelain | sed 's/^...//' | grep bindings/)
exit 1
fi
- name: Check for TypeScript Bindings Changes
run: |
if [ $(git status --porcelain | sed 's/^...//' | grep src/evm/contracts/ | wc -l) -ne 0 ]; then
echo "Changes in TypeScript Bindings"
echo $(git status --porcelain | sed 's/^...//' | grep src/evm/contracts/)
exit 1
fi
69 changes: 0 additions & 69 deletions .github/workflows/go-bindings.yml

This file was deleted.

33 changes: 23 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
with:
node-version: "16"
- uses: bahmutov/npm-install@v1
fetch-depth: 0
submodules: "recursive"

- name: Setup Go
uses: actions/setup-go@v5
with:
install-command: npm install
- run: npm run lint
go-version: "1.21.3"

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install ABIGen
run: |
go install github.com/ethereum/go-ethereum/cmd/abigen@v1.13.5
- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Install Dependencies
run: |
bun install --frozen-lockfile
bun run lint
- name: Check formatting
run: forge fmt --check
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
artifacts:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Check contract sizes
run: forge build --sizes --deny-warnings

- name: Tests
run: forge test

- name: Save compiled contracts and ABIs
if: success()
run: |
mkdir -p artifacts
cp -r out/Dispatcher.sol/Dispatcher.json artifacts/
cp -r out/UniversalChannelHandler.sol/UniversalChannelHandler.json artifacts/
cp -r out/Mars.sol/Mars.json artifacts/
cp -r out/Earth.sol/Earth.json artifacts/
cp -r out/Moon.sol/Moon.json artifacts/
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: compiled-contracts
path: artifacts

release:
runs-on: ubuntu-latest
needs: artifacts
environment: release
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: compiled-contracts
path: ./artifacts

- name: Create Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: artifacts/**
generate_release_notes: true
draft: false
prerelease: false
token: ${{ secrets.RELEASE_TOKEN }}

registries:
runs-on: ubuntu-latest
needs: release
environment: release
steps:
- name: Get Latest Version
id: version
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.21.3"

- uses: actions/setup-node@v4
with:
node-version: "22.3.0"
registry-url: "https://registry.npmjs.org"

- name: Update NPM Registry
run: |
npm ci
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Update Go Registry
run: |
( cd ./bindings && \
GOPROXY=proxy.golang.org go list \
-m github.com/open-ibc/vibc-core-smart-contracts/bindings@${{ steps.version.outputs.release }} )
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ src/contracts.template.ts
forge-cache/

node_modules
package-lock.json
.env
coverage
coverage.json
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

CONTRACT_ABI_FILES = \
./out/Dispatcher.sol/Dispatcher.json \
./out/UniversalChannelHandler.sol/UniversalChannelHandler.json \
./out/Mars.sol/Mars.json \
./out/Earth.sol/Earth.json
./out/Earth.sol/Earth.json \
./out/Moon.sol/Moon.json

TMP_ABI_DIR = .tmp_abi_vibc

Expand All @@ -16,8 +18,8 @@ build-contracts:

extract_artifacts: build-contracts
echo "Extracting ABI artifacts..."; \
rm -rf $(TMP_ABI_DIR)
mkdir -p $(TMP_ABI_DIR)
rm -rf $(TMP_ABI_DIR); \
mkdir -p $(TMP_ABI_DIR); \
for abi_file in $(CONTRACT_ABI_FILES); do \
cat $$abi_file | jq .abi > $(TMP_ABI_DIR)/$$(basename $$abi_file); \
done
Expand All @@ -30,7 +32,7 @@ abigen: extract_artifacts
pkg=$$(basename $$abi_base .json | tr "[:upper:]" "[:lower:]"); \
mkdir -p ./bindings/$$pkg; \
abigen --abi $$abi_file --pkg $$pkg --type $$type --out ./bindings/$$pkg/$$type.go; \
done; \
done

clean:
echo "Cleaning up all artifacts..."; \
Expand Down
63 changes: 47 additions & 16 deletions bindings/dispatcher/dispatcher.go

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion bindings/earth/earth.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod → bindings/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/open-ibc/vib-core-smart-contracts
module github.com/open-ibc/vib-core-smart-contracts/bindings

go 1.21

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions bindings/godoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package bindings defines the go bindings for the vibc-core-smart-contracts
// EVM contract definitions. These allow for interaction in go with the contracts.
package bindings
Loading

0 comments on commit 941fe41

Please sign in to comment.