From 3ee94635524e4b629a61cf2164ab71e67d51a171 Mon Sep 17 00:00:00 2001 From: Sword Date: Sat, 20 Jul 2024 12:56:30 +0900 Subject: [PATCH] finish crawler example, and add test to ci (#73) * finish crawler example, and add test to ci * separate run-examples job --- .devcontainer/devcontainer.json | 1 + .github/workflows/ci.yaml | 19 +++++++++++++++---- Cargo.toml | 2 +- Makefile | 15 +++++++++++++++ examples/Makefile | 7 ++++++- src/lib.rs | 2 +- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 13ff780..4a68178 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,7 @@ "features": { "ghcr.io/devcontainers/features/git:1": "os-provided", "ghcr.io/devcontainers/features/rust:1": {}, + "ghcr.io/devcontainers/features/go:1": {}, "ghcr.io/devcontainers-contrib/features/protoc:1": {} } } diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7bc6f83..8c9ec5a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,7 @@ env: CARGO_TERM_COLOR: always jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,10 +21,21 @@ jobs: run: cargo clippy -- -D warnings - name: Build run: make build - - name: cargo test --locked + - name: unit test run: cargo test --locked --all-targets # https://github.com/rust-lang/cargo/issues/6669 - - name: cargo test --doc + - name: doc test run: cargo test --locked --all-features --doc - - name: Run e2e + - name: e2e test run: make e2e + run-examples: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: examples test + run: make test-examples diff --git a/Cargo.toml b/Cargo.toml index c1e20bd..5f25eed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ debug = [] [[example]] name = "crawler" path = "examples/crawler.rs" -required-features = ["full"] +required-features = ["util"] [[test]] name = "lib" diff --git a/Makefile b/Makefile index 48f3536..fcaccfb 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ ifeq ($(ENABLE_TOKIO_CONSOLE), 1) FEATURES += "debug" endif +EXAMPLES = \ + crawler + .PHONY: build build: RUSTFLAGS=$(RUSTFLAGS) cargo build $(if $(FEATURES),--features $(FEATURES)) @@ -57,6 +60,18 @@ check-version: build-examples: DOCKER_BUILDKIT=1 docker build -t crawler:$(IMAGE_VERSION) -f go.Dockerfile . +.PHONY: test-examples +test-examples: build-examples build-docker + $(MAKE) -C examples stop + $(MAKE) -C examples start + $(MAKE) run-examples + +.PHONY: run-examples +run-examples: + for example in $(EXAMPLES); do \ + $(MAKE) -C examples run-example EXAMPLE=$$example; \ + done + .PHONY: clean clean: rm -rf target diff --git a/examples/Makefile b/examples/Makefile index 4fc9c80..2d1f5a4 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -52,6 +52,11 @@ apply: stop: $(KIND) $(KIND) delete cluster --name $(KIND_CLUSTER) +EXAMPLE ?= crawler +.PHONY: run-example +run-example: + KUBECTL_BIN=$(KUBECTL) cargo run --package castled --example $(EXAMPLE) --features="full" + $(KIND): mkdir -p $(BIN_DIR) curl -sSLf -o $@ https://github.com/kubernetes-sigs/kind/releases/download/$(KIND_VERSION)/kind-$(DL_OS)-$(DL_ARCH) @@ -65,4 +70,4 @@ $(KUBECTL): $(ISTIOCTL): mkdir -p $(BIN_DIR) curl -sSLf https://github.com/istio/istio/releases/download/$(ISTIO_VERSION)/istioctl-$(ISTIO_VERSION)-$(DL_OSALT)-$(DL_ARCH).tar.gz \ - | tar -C $(BIN_DIR) -xzf - \ No newline at end of file + | tar -C $(BIN_DIR) -xzf - diff --git a/src/lib.rs b/src/lib.rs index 14b8075..e2c6bb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,5 +8,5 @@ pub mod client; pub mod debug; pub mod server; -#[cfg(not(feature = "util"))] +#[cfg(feature = "util")] pub mod util;