Skip to content

Commit

Permalink
feat: fix release workflow auto deployment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
h5law committed Jun 30, 2024
1 parent 941fe41 commit 3e86b50
Show file tree
Hide file tree
Showing 75 changed files with 31,539 additions and 484 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,22 @@ jobs:
- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install Bun
uses: oven-sh/setup-bun@v2

- name: Install ABIGen
run: |
go install github.com/ethereum/go-ethereum/cmd/[email protected]
- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Generate Bindings
run: |
bun install --frozen-lockfile
bun run build
bun run generate-bindings
- name: Check for Go Bindings Changes
- name: Check for Bindings Changes
run: |
if [ $(git status --porcelain | sed 's/^...//' | grep bindings/ | wc -l) -ne 0 ]; then
echo "Changes in Go Bindings"
echo "Changes in Generated 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
go install github.com/ethereum/go-ethereum/cmd/[email protected]
- name: Install Bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2

- name: Install Dependencies
run: |
Expand Down
46 changes: 36 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
tags:
- "v*.*.*"

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

jobs:
artifacts:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -35,7 +39,7 @@ jobs:
cp -r out/Moon.sol/Moon.json artifacts/
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: compiled-contracts
path: artifacts
Expand All @@ -44,12 +48,17 @@ jobs:
runs-on: ubuntu-latest
needs: artifacts
environment: release
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: compiled-contracts
path: ./artifacts
Expand All @@ -69,6 +78,12 @@ jobs:
needs: release
environment: release
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Get Latest Version
id: version
uses: pozetroninc/github-action-get-latest-release@master
Expand All @@ -80,20 +95,31 @@ jobs:
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/[email protected]
- uses: actions/setup-node@v4
with:
node-version: "22.3.0"
registry-url: "https://registry.npmjs.org"

- name: Install Bun
uses: oven-sh/setup-bun@v2

# Ensure /v2 is updated as the major version changes
- name: Update Go Registry
run: |
GOPROXY=proxy.golang.org go list \
-m github.com/open-ibc/vibc-core-smart-contracts/v2@${{ steps.version.outputs.release }}
- name: Update NPM Registry
run: |
npm ci
npm publish --provenance --access public
bun install --frozen-lockfile
bun run build
npm publish
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ src/contracts.template.ts
forge-cache/

node_modules
package-lock.json
.env
coverage
coverage.json
Expand Down
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# specific to npm package
deployments

# Auto generated code Go and TypeScript bindings
bindings/

node_modules
.env
coverage
Expand All @@ -24,6 +27,7 @@ src/contracts.template.ts
.direnv/
forge-cache/

bun.lockb
node_modules
.env
coverage
Expand Down
77 changes: 60 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
.SILENT:

CONTRACT_ABI_FILES = \
./out/Dispatcher.sol/Dispatcher.json \
./out/UniversalChannelHandler.sol/UniversalChannelHandler.json \
./out/Mars.sol/Mars.json \
./out/Earth.sol/Earth.json \
./out/Moon.sol/Moon.json
# Define the list of contract names
CONTRACT_NAMES = OptimisticProofVerifier \
ProofVerifier \
Ibc \
IbcUtils \
channel \
Dispatcher \
Mars \
Earth \
Moon \
UniversalChannelHandler \
DummyProofVerifier \
DummyLightClient \
ERC1967Proxy \
OptimisticLightClient

# Create the pattern for each contract
CONTRACT_PATTERNS := $(addsuffix .sol/*.json,$(addprefix ./out/,$(CONTRACT_NAMES)))

# Use wildcard to expand each pattern
CONTRACT_ABI_FILES = $(foreach pattern,$(CONTRACT_PATTERNS),$(wildcard $(pattern)))

TMP_ABI_DIR = .tmp_abi_vibc

.PHONY: build-contracts abigen clean extract_artifacts
TS_CONTRACT_DIR = ./src/evm/contracts/

.PHONY: build-contracts bindings-gen-go bindings-gen-ts clean extract_artifacts

build-contracts:
echo "Building contracts"; \
Expand All @@ -21,20 +38,46 @@ extract_artifacts: build-contracts
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); \
dir=$$(basename $$(dirname $$abi_file)); \
mkdir -p $(TMP_ABI_DIR)/$$dir; \
cat $$abi_file | jq .abi > $(TMP_ABI_DIR)/$$dir/$$(basename $$abi_file); \
done

abigen: extract_artifacts
# Libraries do not generate the correct ABI code (ChannelState enum causes errors)
# So the Ibc.sol abi generated code from abigen throws errors but is not needed.
# This is because the types exported are included in the ABIs of contracts and
# correctly interpreted (enums -> uint8 etc), the library methods are used inside
# of other contract methods and thus bindings for them do not need to be generated
# as they are not publicly exposed, but rather used within the contract itself.
#
# ABIGen issue ref: https://github.com/ethereum/solidity/issues/9278
bindings-gen-go: extract_artifacts
echo "Generating Go vIBC bindings..."; \
for abi_file in $(wildcard $(TMP_ABI_DIR)/*.json); do \
abi_base=$$(basename $$abi_file); \
type=$$(basename $$abi_file .json | tr "[:upper:]" "[:lower:]"); \
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
rm -rfd ./bindings/go/* ; \
for abi_file in $(wildcard $(TMP_ABI_DIR)/*/*.json); do \
abi_base=$$(basename $$(dirname $$abi_file)); \
if [ "$$abi_base" = "Ibc.sol" ]; then \
continue; \
fi; \
type=$$(basename $$abi_file .json); \
pkg=$$(basename $$abi_base .sol | tr "[:upper:]" "[:lower:]"); \
echo $$pkg; \
mkdir -p ./bindings/go/$$pkg; \
abigen --abi $$abi_file --pkg $$pkg --type $$type --out ./bindings/go/$$pkg/$$type.go; \
done; \
echo "Done."

# Typechain is able to correctly generate typescript bindings for libraries.
# So Ibc.sol doesn't need to be skipped, even using the same ABI.
bindings-gen-ts: build-contracts
echo "Generating TypeScript vIBC bindings..."; \
rm -rfd ./bindings/ts/* $(TS_CONTRACT_DIR) ; \
mkdir -p ./bindings/ts $(TS_CONTRACT_DIR); \
typechain --target ethers-v6 --out-dir ./bindings/ts $(CONTRACT_ABI_FILES); \
cp -r ./bindings/ts/* $(TS_CONTRACT_DIR); \
echo "Done."

clean:
echo "Cleaning up all artifacts..."; \
rm -rf $(TMP_ABI_DIR); \
rm -rfd $(TMP_ABI_DIR); \
forge clean
Loading

0 comments on commit 3e86b50

Please sign in to comment.