Skip to content

Commit bd249f8

Browse files
committed
cleanup
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
1 parent d6578d5 commit bd249f8

6 files changed

Lines changed: 128 additions & 60 deletions

File tree

.github/workflows/commit.yaml

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
rust:
11-
name: Rust Build and Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
10+
go:
11+
name: Build and Unit Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
1212
runs-on: ${{ matrix.platform.os }}
1313
defaults:
1414
run:
15-
working-directory: ./rust
15+
working-directory: ./go
1616
strategy:
1717
fail-fast: false
1818
matrix:
@@ -28,6 +28,19 @@ jobs:
2828
- name: Checkout repository
2929
uses: actions/checkout@v4
3030

31+
- uses: actions/setup-go@v5
32+
with:
33+
cache: false
34+
go-version-file: go/go.mod
35+
36+
- uses: actions/cache@v4
37+
with:
38+
path: |
39+
~/.cache/go-build
40+
~/go/pkg/mod
41+
~/go/bin
42+
key: go-test-${{ hashFiles('**/go.mod', '**/go.sum') }}
43+
3144
- name: Cache Cargo registry
3245
uses: actions/cache@v4
3346
with:
@@ -51,55 +64,9 @@ jobs:
5164
override: true
5265
components: clippy, rustfmt
5366

54-
- name: Check formatting
55-
run: cargo fmt -- --check
56-
57-
- name: Run Clippy linter
58-
run: cargo clippy -- -D warnings
59-
60-
- name: Build project
61-
run: cargo build --verbose
62-
63-
- name: Run tests
64-
run: cargo test --verbose
65-
66-
go:
67-
name: Go Build and Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
68-
runs-on: ${{ matrix.platform.os }}
69-
defaults:
70-
run:
71-
working-directory: ./go
72-
strategy:
73-
fail-fast: false
74-
matrix:
75-
platform:
76-
- os: ubuntu-22.04
77-
arch: amd64
78-
- os: ubuntu-22.04-arm
79-
arch: arm64
80-
- os: macos-latest
81-
arch: arm64
82-
83-
steps:
84-
- name: Checkout repository
85-
uses: actions/checkout@v4
86-
87-
- uses: actions/setup-go@v5
88-
with:
89-
cache: false
90-
go-version-file: go/go.mod
91-
92-
- uses: actions/cache@v4
93-
with:
94-
path: |
95-
~/.cache/go-build
96-
~/go/pkg/mod
97-
~/go/bin
98-
key: go-test-${{ hashFiles('**/go.mod', '**/go.sum') }}
99-
100-
- run: CGO_ENABLED=0 go test ./... -v
101-
- run: go build -buildmode=c-shared -o main.so
102-
- run: go tool golangci-lint run
67+
- run: make check
68+
- run: make test
69+
- run: make build
10370

10471
docker_build_and_integration_test:
10572
name: Build and Run Integration Tests

Makefile

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
CYAN := \033[36m
2+
GREEN := \033[32m
3+
YELLOW := \033[33m
4+
RESET := \033[0m
5+
BOLD := \033[1m
6+
7+
define print_task
8+
printf "$(BOLD)$(CYAN)[TASK]$(RESET) $(BOLD)%s$(RESET)\n" "$(1)"
9+
endef
10+
define print_subtask
11+
printf " $(YELLOW)$(RESET) %s\n" "$(1)"
12+
endef
13+
define print_success
14+
printf " $(GREEN)$(RESET) %s\n" "$(1)"
15+
endef
16+
17+
## help: Show this help info.
18+
.PHONY: help
19+
help:
20+
@echo "Envoy Dynamic Modules.\n"
21+
@echo "Usage:\n make \033[36m<Target>\033[0m \n\nTargets:"
22+
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
23+
24+
# This runs all necessary steps to prepare for a commit.
25+
.PHONY: precommit
26+
precommit: ## Run all necessary steps to prepare for a commit.
27+
precommit: precommit-go precommit-rust
28+
29+
.PHONY: precommit-go
30+
precommit-go: ## This runs the linter, formatter, and tidy on the Go codebase.
31+
@$(call print_task,Running linter)
32+
@$(call print_subtask,Checking ./...)
33+
@cd go && go tool golangci-lint run --build-tags==cgo ./...
34+
@$(call print_success,Linting completed)
35+
@$(call print_task,Formatting code)
36+
@$(call print_subtask,Running gofmt)
37+
@cd go && find . -type f -name '*.go' | xargs gofmt -s -w
38+
@$(call print_subtask,Running gofumpt)
39+
@cd go && find . -type f -name '*.go' | xargs go tool gofumpt -l -w
40+
@$(call print_subtask,Running gci)
41+
@cd go && go tool gci write -s standard -s default -s "prefix(github.com/envoyproxy/dynamic-modules-examples)" `find . -name '*.go'`
42+
@$(call print_success,Formatting completed)
43+
@$(call print_task,Tidying Go modules)
44+
@find . -name "go.mod" \
45+
| grep go.mod \
46+
| xargs -I {} bash -c 'dirname {}' \
47+
| xargs -I {} bash -c 'cd {} && $(call print_subtask,Tidying {}) && go mod tidy -v;'
48+
@$(call print_success,Tidying completed)
49+
50+
.PHONY: precommt-rust
51+
precommit-rust: ## This runs the linter, formatter, and tidy on the Rust codebase.
52+
@$(call print_task,Running Rust precommit steps)
53+
@$(call print_subtask,Running cargo fmt)
54+
@cd rust && cargo fmt --all -- --check
55+
@$(call print_subtask,Running cargo clippy)
56+
@cd rust && cargo clippy -- -D warnings
57+
@$(call print_success,Rust precommit steps completed)
58+
59+
# This runs precommit and checks for any differences in the codebase, failing if there are any.
60+
.PHONY: check
61+
check: precommit ## Run all necessary steps to prepare for a commit and check for any differences in the codebase.
62+
@$(call print_task,Checking for uncommitted changes)
63+
@if [ ! -z "`git status -s`" ]; then \
64+
echo "$(BOLD)$(YELLOW)The following differences will fail CI until committed:$(RESET)"; \
65+
git diff --exit-code; \
66+
echo "$(BOLD)$(YELLOW)Please ensure you have run 'make precommit' and committed the changes.$(RESET)"; \
67+
exit 1; \
68+
fi
69+
@$(call print_success,No uncommitted changes found)
70+
71+
.PHONY: test
72+
test: test-rust test-rust ## Run all tests for the codebase.
73+
.PHONY: test-go
74+
test-go:## Run the unit tests for the Go codebase. This doesn't run the integration tests like test-* targets.
75+
@$(call print_task,Building and Running Go)
76+
@cd go && go test -v ./...
77+
@$(call print_success,Go unit tests completed)
78+
.PHONY: test-rust
79+
test-rust: ## Run the unit tests for the Rust codebase.
80+
@$(call print_task,Building and Running Rust)
81+
@cd rust && cargo test
82+
@$(call print_success,Rust unit tests completed)
83+
84+
.PHONY: build
85+
build: build-go build-rust ## Build all dynamic modules.
86+
87+
.PHONY: build-go
88+
build-go: ## Build the Go dynamic module.
89+
@$(call print_task,Building Go dynamic module)
90+
@cd go && go build -buildmode=c-shared -o libgo_module.so .
91+
@$(call print_success,Go dynamic module built at go/libgo_module.so)
92+
93+
.PHONY: build-rust
94+
build-rust: ## Build the Rust dynamic module.
95+
@$(call print_task,Building Rust dynamic module)
96+
@cd rust && cargo build
97+
@$(call print_success,Rust dynamic module built at rust/target/debug/librust_module.so)

go/go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ module github.com/envoyproxy/dynamic-modules-examples/go
33
go 1.24.2
44

55
tool (
6+
github.com/daixiang0/gci
67
github.com/golangci/golangci-lint/cmd/golangci-lint
78
mvdan.cc/gofumpt
89
)
910

11+
require (
12+
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994
13+
github.com/stretchr/testify v1.10.0
14+
)
15+
1016
require (
1117
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
1218
4d63.com/gochecknoglobals v0.2.2 // indirect
@@ -43,11 +49,10 @@ require (
4349
github.com/chavacava/garif v0.1.0 // indirect
4450
github.com/ckaznocha/intrange v0.3.0 // indirect
4551
github.com/curioswitch/go-reassign v0.3.0 // indirect
46-
github.com/daixiang0/gci v0.13.5 // indirect
52+
github.com/daixiang0/gci v0.13.7 // indirect
4753
github.com/davecgh/go-spew v1.1.1 // indirect
4854
github.com/denis-tingaikin/go-header v0.5.0 // indirect
4955
github.com/dlclark/regexp2 v1.11.4 // indirect
50-
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994 // indirect
5156
github.com/ettle/strcase v0.2.0 // indirect
5257
github.com/fatih/color v1.18.0 // indirect
5358
github.com/fatih/structtag v1.2.0 // indirect
@@ -161,7 +166,6 @@ require (
161166
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
162167
github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect
163168
github.com/stretchr/objx v0.5.2 // indirect
164-
github.com/stretchr/testify v1.10.0 // indirect
165169
github.com/subosito/gotenv v1.4.1 // indirect
166170
github.com/tdakkota/asciicheck v0.4.1 // indirect
167171
github.com/tetafro/godot v1.5.0 // indirect

go/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
125125
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
126126
github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs=
127127
github.com/curioswitch/go-reassign v0.3.0/go.mod h1:nApPCCTtqLJN/s8HfItCcKV0jIPwluBOvZP+dsJGA88=
128-
github.com/daixiang0/gci v0.13.5 h1:kThgmH1yBmZSBCh1EJVxQ7JsHpm5Oms0AMed/0LaH4c=
129-
github.com/daixiang0/gci v0.13.5/go.mod h1:12etP2OniiIdP4q+kjUGrC/rUagga7ODbqsom5Eo5Yk=
128+
github.com/daixiang0/gci v0.13.7 h1:+0bG5eK9vlI08J+J/NWGbWPTNiXPG4WhNLJOkSxWITQ=
129+
github.com/daixiang0/gci v0.13.7/go.mod h1:812WVN6JLFY9S6Tv76twqmNqevN0pa3SX3nih0brVzQ=
130130
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
131131
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
132132
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
133133
github.com/denis-tingaikin/go-header v0.5.0 h1:SRdnP5ZKvcO9KKRP1KJrhFR3RrlGuD+42t4429eC9k8=
134134
github.com/denis-tingaikin/go-header v0.5.0/go.mod h1:mMenU5bWrok6Wl2UsZjy+1okegmwQ3UgWl4V1D8gjlY=
135-
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
136-
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
137135
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
138136
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
139137
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994 h1:aQYWswi+hRL2zJqGacdCZx32XjKYV8ApXFGntw79XAM=

go/javascript.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010

1111
"github.com/dop251/goja"
12+
1213
"github.com/envoyproxy/dynamic-modules-examples/go/gosdk"
1314
)
1415

go/javascript_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"bytes"
55
"testing"
66

7-
"github.com/envoyproxy/dynamic-modules-examples/go/gosdk"
87
"github.com/stretchr/testify/require"
8+
9+
"github.com/envoyproxy/dynamic-modules-examples/go/gosdk"
910
)
1011

1112
func Test_newJavaScriptFilterConfig(t *testing.T) {

0 commit comments

Comments
 (0)