Skip to content

Commit a785443

Browse files
committed
ci: build and vet _samples in CI
The _samples directory is excluded from go build ./... (Go ignores _-prefixed paths), so a sample that fails to compile merges green. Add a build-samples Makefile target and a CI job that compiles and vets each _samples/*.go program." Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent 9999a1a commit a785443

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

.github/workflows/test-unit.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ jobs:
3838
with: { go-version-file: 'go.mod' }
3939
- run: go version
4040
- run: make test-bench
41+
42+
samples:
43+
name: Build samples
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
47+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
48+
with: { go-version-file: 'go.mod' }
49+
- run: go version
50+
- run: make build-samples
51+

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

77
### Added
88

9+
- Add a `build-samples` Makefile target and a CI job that compiles and vets every `_samples/*.go` program, so example breakage is caught (the `_samples` directory is excluded from `go build ./...` because Go ignores `_`-prefixed paths)
910
- Group document operations under a `client.Doc` sub-client and point-in-time operations under `client.PIT` (`Create`/`Delete`/`GetAll`/`DeleteAll`); `client.Document` and `client.PointInTime` remain as field aliases. The indices sub-client's canonical field is `client.Index`, with `client.Indices` and `client.Indexes` as aliases. `cmd/osgen` gains `--emit-v4-compat` (default true) to emit backward-compatibility forwarders so top-level `client.Bulk`/`MGet`/`Update`, `client.Document.Source`, and `client.PointInTime.Get` keep working (`client.Index` is not forwarded -- it is the indices sub-client field; use `client.Doc.Index`), and `--emit-v4-deprecation` (default false) to mark those forwarders deprecated
1011
- Add `cmd/osgen` code generator for typed path builders and API consumer files from the OpenAPI spec
1112
- `opensearchapi`: `NewClient` and `NewDefaultClient` inject `opensearchtransport.NewDefaultRouter` when `config.Client.Router` is nil, opting every client into intelligent request routing by default. The `OPENSEARCH_GO_ROUTER` env var controls the behavior: `=false`/`=0` suppresses both Router injection and auto-discovery; unset or any other value injects the Router and enables on-start discovery. ([#816](https://github.com/opensearch-project/opensearch-go/issues/816))

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ test-bench: ## Run benchmarks
132132
@printf "\033[2m-> Running benchmarks...\033[0m\n"
133133
go test -run=none -bench=. -benchmem -benchtime=200ms ./...
134134

135+
build-samples: ## Compile and vet each _samples/*.go program
136+
@printf "\033[2m-> Building _samples...\033[0m\n"
137+
@failed=0; \
138+
for f in _samples/*.go; do \
139+
printf " %s\n" "$$f"; \
140+
go build -o /dev/null "$$f" || failed=1; \
141+
go vet "$$f" || failed=1; \
142+
done; \
143+
if [ $$failed -ne 0 ]; then \
144+
printf "\033[31m-> _samples build/vet failed\033[0m\n"; \
145+
exit 1; \
146+
fi
147+
135148
coverage: ## Print test coverage report
136149
@$(MAKE) gen-coverage
137150
@go tool cover -func=$(PWD)/tmp/total.cov
@@ -888,5 +901,5 @@ help: ## Display help
888901
#------------- <https://suva.sh/posts/well-documented-makefiles> --------------
889902

890903
.DEFAULT_GOAL := help
891-
.PHONY: help backport cluster.runtime cluster.sysctl cluster.build cluster.start cluster.stop cluster.docker-build cluster.docker-up cluster.clean cluster.heterogeneous.cpu.1 cluster.heterogeneous.cpu.2 cluster.heterogeneous.roles cluster.homogeneous cluster.latency.asymmetric cluster.latency.symmetric cluster.latency.bimodal cluster.latency.graduated cluster.latency.clear cluster.latency.show gh.checks gh.checks.failed gh.fail gh.fail.full gh.fail.context gh.fail.summary coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install
904+
.PHONY: help backport cluster.runtime cluster.sysctl cluster.build cluster.start cluster.stop cluster.docker-build cluster.docker-up cluster.clean cluster.heterogeneous.cpu.1 cluster.heterogeneous.cpu.2 cluster.heterogeneous.roles cluster.homogeneous cluster.latency.asymmetric cluster.latency.symmetric cluster.latency.bimodal cluster.latency.graduated cluster.latency.clear cluster.latency.show gh.checks gh.checks.failed gh.fail gh.fail.full gh.fail.context gh.fail.summary coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install build-samples
892905
.SILENT: lint.markdown

0 commit comments

Comments
 (0)