Skip to content

Commit 5b040f0

Browse files
authored
Update DEVELOPER_GUID, Add Coverage + go ling to Makefile, Run CI tests on all branches (#392)
* .github: run test workflows for all branches, test against 2.9,2.10 Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com> * Makefile: use docker golangci-lint, run integration test on `.` folder, change coverage generation Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com> * Update DEVELOPER_GUIDE Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com> --------- Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
1 parent 461f992 commit 5b040f0

8 files changed

+75
-44
lines changed

.github/workflows/links.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: Link Checker
2-
on:
3-
push:
4-
branches:
5-
- "*"
6-
pull_request:
7-
branches:
8-
- "*"
2+
3+
on: [push, pull_request]
94

105
jobs:
116
linkchecker:

.github/workflows/lint.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Lint check
22

3-
on:
4-
push:
5-
branches:
6-
- "*"
7-
pull_request:
8-
branches:
9-
- "*"
3+
on: [push, pull_request]
104

115
env:
126
GITHUB_ACTIONS: true

.github/workflows/test-compatibility.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Integration for Compatibility
33
on: [push, pull_request]
44

55
jobs:
6-
integration-test-compatibility:
6+
integ-test-compat:
77
runs-on: ubuntu-latest
88
strategy:
99
fail-fast: false
@@ -22,6 +22,8 @@ jobs:
2222
- { opensearch_version: 2.6.0 }
2323
- { opensearch_version: 2.7.0 }
2424
- { opensearch_version: 2.8.0 }
25+
- { opensearch_version: 2.9.0 }
26+
- { opensearch_version: 2.10.0 }
2527
steps:
2628
- uses: actions/checkout@v3
2729
with: { fetch-depth: 1 }

.github/workflows/test-integration.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Integration
22

3-
on:
4-
push:
5-
branches:
6-
- "*"
7-
pull_request:
8-
branches:
9-
- "*"
3+
on: [push, pull_request]
104

115
env:
126
GITHUB_ACTIONS: true
@@ -30,6 +24,9 @@ jobs:
3024
- name: Launch OpenSearch cluster
3125
run: |
3226
make cluster.clean cluster.build cluster.start
27+
for attempt in `seq 25`; do sleep 5; \
28+
if curl -s localhost:9200; \
29+
then echo '=====> ready'; break; fi; if [ $attempt == 25 ]; then exit 1; fi; echo '=====> waiting...'; done
3330
- run: make test-integ race=true
3431
- uses: codecov/codecov-action@v1
3532
with:
@@ -57,4 +54,7 @@ jobs:
5754
- name: Launch OpenSearch cluster
5855
run: |
5956
make cluster.clean cluster.build cluster.start
60-
- run: make test-integ-secure
57+
for attempt in `seq 25`; do sleep 5; \
58+
if curl -s -ku admin:admin https://localhost:9200; \
59+
then echo '=====> ready'; break; fi; if [ $attempt == 25 ]; then exit 1; fi; echo '=====> waiting...'; done
60+
- run: make test-integ-secure

.github/workflows/test-unit.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Unit
22

3-
on:
4-
push:
5-
branches:
6-
- "*"
7-
pull_request:
8-
branches:
9-
- "*"
3+
on: [push, pull_request]
104

115
env:
126
GITHUB_ACTIONS: true

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4343
- Read, close and replace the http Reponse Body ([#300](https://github.com/opensearch-project/opensearch-go/pull/300))
4444
- Updated and adjusted golangci-lint, solve linting complains for signer ([#352](https://github.com/opensearch-project/opensearch-go/pull/352))
4545
- Solve linting complains for opensearchtransport ([#353](https://github.com/opensearch-project/opensearch-go/pull/353))
46-
- Updated Developer guide to include docker build instructions ([#385]https://github.com/opensearch-project/opensearch-go/pull/385)
46+
- Updated Developer guide to include docker build instructions ([#385](https://github.com/opensearch-project/opensearch-go/pull/385)
47+
- Test against version 2.9.0,2.10.0, run tests in all branches, change intergration tests to wait for OpenSearch to start ([#392](https://github.com/opensearch-project/opensearch-go/pull/392))
48+
- Makefile: use docker golangci-lint, run integration test on `.` folder, change coverage generation ([#392](https://github.com/opensearch-project/opensearch-go/pull/392))
4749

4850
### Deprecated
4951

@@ -59,4 +61,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5961

6062
### Security
6163

62-
[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.2.0...HEAD
64+
[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.2.0...HEAD

DEVELOPER_GUIDE.md

+37-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
- [Execute integration tests from your terminal](#execute-integration-tests-from-your-terminal)
1212
- [Lint](#lint)
1313
- [Markdown lint](#markdown-lint)
14+
- [Go lint](#go-lint)
15+
- [Coverage](#coverage)
1416
- [Use an Editor](#use-an-editor)
1517
- [GoLand](#goland)
18+
- [Vim](#vim)
1619

1720
# Developer Guide
1821

@@ -26,9 +29,9 @@ Fork [opensearch-project/opensearch-go](https://github.com/opensearch-project/op
2629

2730
### Install Prerequisites
2831

29-
#### Go 1.11
32+
#### Go 1.15
3033

31-
OpenSearch Go Client builds using [Go](https://golang.org/doc/install) 1.11 at a minimum.
34+
OpenSearch Go Client builds using [Go](https://golang.org/doc/install) 1.15 at a minimum.
3235

3336
#### Docker
3437

@@ -38,7 +41,7 @@ OpenSearch Go Client builds using [Go](https://golang.org/doc/install) 1.11 at a
3841

3942
To build the project on Windows, use [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install), the compatibility layer for running Linux applications.
4043

41-
Install ```make```
44+
Install `make`
4245
```
4346
sudo apt install make
4447
```
@@ -64,11 +67,10 @@ In order to test opensearch-go client, you need a running OpenSearch cluster. Yo
6467

6568
### Composing an OpenSearch Docker Container
6669

67-
Ensure that Docker is installed on your local machine. You can check by running `docker --version`. Next, navigate to your local OpenSearch repository where the docker-compose.yaml file is stored. Run the following command to build the docker container.
70+
Ensure that Docker is installed on your local machine. You can check by running `docker --version`. Next, navigate to your local opensearch-go repository. Run the following command to build and start the OpenSearch docker container.
6871

6972
```
70-
cd opensearch/.ci/opensearch
71-
docker-compose -f docker-compose.yml up
73+
make cluster.build cluster.start
7274
```
7375

7476
This command will start the OpenSearch container using the `docker-compose.yaml` configuration file. During the build process, the necessary dependencies and files will be downloaded, which may take some time depending on your internet connection and system resources.
@@ -104,6 +106,30 @@ To check the markdown files, run the following command:
104106
make lint.markdown
105107
```
106108

109+
### Go lint
110+
111+
To check all go files, run the following command:
112+
113+
```
114+
make linters
115+
```
116+
117+
## Coverage
118+
119+
To get the repository test coverage, run the following command:
120+
121+
For the results to be display in your terminal:
122+
123+
```
124+
make coverage
125+
```
126+
127+
For the results to be display in your browser:
128+
129+
```
130+
make coverage-html
131+
```
132+
107133
## Use an Editor
108134

109135
### GoLand
@@ -114,3 +140,8 @@ You can import the OpenSearch project into GoLand as follows:
114140
2. In the subsequent dialog navigate to the ~/go/src/opensearch-go and click **Open**
115141

116142
After you have opened your project, you need to specify the location of the Go SDK. You can either specify a local path to the SDK or download it. To set the Go SDK, navigate to **Go | GOROOT** and set accordingly.
143+
144+
### Vim
145+
146+
To improve your vim experience with Go, you might want to check out [fatih/vim-go](https://github.com/fatih/vim-go).
147+
For example it correctly formats the file and validates it on save.

Makefile

+19-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif
3838
gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \
3939
else \
4040
echo "go test -v" $(testintegargs) "."; \
41-
go test -v $(testintegargs) "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \
41+
go test -v $(testintegargs) "." "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \
4242
fi;
4343

4444
test-integ-secure: ##Run secure integration tests
@@ -48,11 +48,24 @@ test-bench: ## Run benchmarks
4848
@printf "\033[2m→ Running benchmarks...\033[0m\n"
4949
go test -run=none -bench=. -benchmem ./...
5050

51-
test-coverage: ## Generate test coverage report
51+
coverage: ## Print test coverage report
52+
@make gen-coverage
53+
@go tool cover -func=$(PWD)/tmp/total.cov
54+
@printf "\033[0m--------------------------------------------------------------------------------\n\033[0m"
55+
56+
coverage-html: ## Open test coverage report in browser
57+
@make gen-coverage
58+
@go tool cover -html $(PWD)/tmp/total.cov
59+
60+
gen-coverage: ## Generate test coverage report
5261
@printf "\033[2m→ Generating test coverage report...\033[0m\n"
53-
@go tool cover -html=tmp/unit.cov -o tmp/coverage.html
54-
@go tool cover -func=tmp/unit.cov | 'grep' -v 'opensearchapi/api\.' | sed 's/github.com\/opensearch-project\/opensearch-go\///g'
55-
@printf "\033[0m--------------------------------------------------------------------------------\nopen tmp/coverage.html\n\n\033[0m"
62+
@rm -rf tmp
63+
@mkdir tmp
64+
@mkdir tmp/unit
65+
@mkdir tmp/integration
66+
@go test -cover ./... -args -test.gocoverdir="$(PWD)/tmp/unit"
67+
@go test -cover -tags='integration' ./... -args -test.gocoverdir="$(PWD)/tmp/integration"
68+
@go tool covdata textfmt -i=$(PWD)/tmp/unit,$(PWD)/tmp/integration -o $(PWD)/tmp/total.cov
5669

5770
##@ Development
5871
lint: ## Run lint on the package
@@ -205,7 +218,7 @@ cluster.clean: ## Remove unused Docker volumes and networks
205218
docker system prune --volumes --force
206219

207220
linters:
208-
./bin/golangci-lint run ./... --timeout=5m
221+
docker run -t --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/v1.53.3:/root/.cache -w /app golangci/golangci-lint:v1.53.3 golangci-lint run --timeout=5m
209222

210223
workflow: ## Run all github workflow commands here sequentially
211224

0 commit comments

Comments
 (0)