Skip to content

Commit ca00896

Browse files
lumtisskosito
andauthored
chore: add Go code generation for IDL (#52)
* initialize go idl * fix generation * first version * add ci generation check * add constant instruction name generation * fix module name and regenerate latest gateway bindings * use same go version as node pkg * gen latest * fix script * Revert "fix script" This reverts commit c5e0c96. * tmp just use gateway generate --------- Co-authored-by: skosito <[email protected]>
1 parent 0d24a71 commit ca00896

File tree

10 files changed

+940
-1
lines changed

10 files changed

+940
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Generated Files are Updated
2+
on:
3+
merge_group:
4+
pull_request:
5+
branches:
6+
- "*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Generate Go code, docs and specs
16+
env:
17+
TEST_ENV: ${{ github.workspace }}
18+
run: make generate
19+
20+
- name: Check for changes
21+
run: |
22+
if git diff --exit-code --ignore-space-change --ignore-all-space --ignore-cr-at-eol; then
23+
echo "Generated Go files are up-to-date."
24+
else
25+
echo "::error::Generated files are not up-to-date. Please run 'make generate' locally and commit any changes."
26+
exit 1
27+
fi

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea/
33
/target
44
**/.DS_Store
5-
node_modules
5+
.idea/
6+
node_modules/

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# directories for Go code generation
2+
IDL_DIR := ./target/idl
3+
GENERATED_DIR := ./generated
4+
5+
# generate Go code from IDL files
6+
.PHONY: generate
7+
generate:
8+
rm -rf $(GENERATED_DIR)/*.go
9+
@for file in $(wildcard $(IDL_DIR)/*.json); do \
10+
base_name=$$(basename $$file .json); \
11+
input_file="../$$file"; \
12+
output_file="$(GENERATED_DIR)/$$base_name.go"; \
13+
echo "Generating $$output_file from $$file"; \
14+
(cd go-idl && go run ./generator "$$input_file" "$$output_file"); \
15+
(cd go-idl && go fmt $$output_file); \
16+
done

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ To run the tests
5555
$ anchor test
5656
```
5757

58+
To generate Go code for program's IDL
59+
```bash
60+
$ make generate
61+
```
62+
5863
# Authentication and Authorization
5964

6065
Anyone can deposit and remote invoke ZetaChain contracts.

0 commit comments

Comments
 (0)