Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Go code generation for IDL #52

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/generate-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Generated Files are Updated
on:
merge_group:
pull_request:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Generate Go code, docs and specs
env:
TEST_ENV: ${{ github.workspace }}
run: make generate

- name: Check for changes
run: |
if git diff --exit-code --ignore-space-change --ignore-all-space --ignore-cr-at-eol; then
echo "Generated Go files are up-to-date."
else
echo "::error::Generated files are not up-to-date. Please run 'make generate' locally and commit any changes."
exit 1
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.anchor/
/target
**/.DS_Store
node_modules
.idea/
node_modules/
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,22 @@ C_END=\033[0m
.PHONY: fmt
fmt:
@echo "$(C_GREEN)# Formatting rust code$(C_END)"
@./scripts/fmt.sh
@./scripts/fmt.sh


# directories for Go code generation
IDL_DIR := ./target/idl
GENERATED_DIR := ./generated

# generate Go code from IDL files
.PHONY: generate
generate:
rm -rf $(GENERATED_DIR)/*.go
@for file in $(wildcard $(IDL_DIR)/*.json); do \
base_name=$$(basename $$file .json); \
input_file="../$$file"; \
output_file="$(GENERATED_DIR)/$$base_name.go"; \
echo "Generating $$output_file from $$file"; \
(cd go-idl && go run ./generator "$$input_file" "$$output_file"); \
(cd go-idl && go fmt $$output_file); \
done
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ To run the tests
$ anchor test
```

To generate Go code for program's IDL
```bash
$ make generate
```

# Authentication and Authorization

Anyone can deposit and remote invoke ZetaChain contracts.
Expand Down
Loading
Loading