Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chores: add contributing doc #76

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ GO_FILES:=$$(find ./ -type f -name '*.go' -not -path ".//vendor/*")
COVER_FILE ?= coverage.out
SOURCE_PATHS ?= ./pkg/...

test:
go test ./...

cover: ## Generates coverage report
go test -gcflags=all=-l -timeout=10m `go list $(SOURCE_PATHS)` -coverprofile $(COVER_FILE) ${TEST_FLAGS}

Expand All @@ -11,16 +14,22 @@ clean:

check-fmt:
test -z $$(goimports -l -w -e -local=kcl-lang.io $(GO_FILES))
gofmt -l -w .

regenerate:
regenerate: ## regenerate all the golden files
go run scripts/regenerate.go

build-local-linux:
# Delete old artifacts
-rm -rf ./_build
-rm -rf ./_build/linux
mkdir -p ./_build/linux/

# Build kcl-openapi
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -o ./_build/linux/kcl-openapi \
-ldflags="-s -w" .
-ldflags="-s -w" .
build:
-rm -rf ./_build/local/
mkdir -p ./_build/local/
# Build kcl-openapi
CGO_ENABLED=0 go build -o ./_build/local/kcl-openapi -ldflags="-s -w" .
71 changes: 71 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Contributing

Welcome contributing to kcl-openapi tool. This document provides a quick guide for developing the project.

### Project Structure

The kcl-openapi project provides a kcl-openapi tool for extracting and generating KCL models from OpenAPI spec files or Kuberenetes CRDs:

```sh
├── _build # the tmp directory to store locally built binaries
├── examples # examples of inputs and outputs of the kcl-openapi tool. The examples will also be used as test cases for e2e tests
│ ├── kube_resource
│ │ ├── complex
│ │ └── simple
│ └── swagger
│ ├── complex
│ └── simple
├── main.go
├── pkg
│ ├── cmds
│ │ └── kcl-openapi.go # defines the kcl-openapi cmd
│ ├── kube_resource # generating logic specifically for kube_resources(CRDs). The CRD will first be transfered to a corresponding OpenAPI spec, then be processed as a normal OpenAPI spec file
│ │ └── generator
│ │ └── assets # the k8s.json OpenAPI spec files to used in CRD generating
│ ├── swagger # generating logic for OpenAPI spec files
│ │ └── generator
│ │ └── templates # the `gotmpl` files providing the templates for generating KCL files
│ └── utils
│ └── integrate_gen.go # provides APIs to build the binary and generate/check all the golden files using the binary
└── scripts
├── preprocess # scripts to preprocess the Kubernetes OpenAPI spec before generating the KCL models from it. ref: generate_from_k8s_spec.md
│ └── main.py
└── regenerate.go # scripts to quickly regenerate all the golden files
```

### Enviroment Requirements

- `git`
- `Go 1.18`

### How to Build

In the top level of the `kcl-lang/kcl-openapi` repo and run:

```sh
make build
```

### Check and Fix Code Format

In the top level of the `kcl-lang/kcl-openapi` repo and run:

```sh
make check-fmt
```

### Unit Test

In the top level of the `kcl-lang/kcl-openapi` repo and run:

```sh
make test
```

### Regenerate golden files

We'll often need to generate the golden files and check if the file changes are as expected. To do so, in the top level of the `kcl-lang/kcl-openapi` repo and run:

```sh
make regenerate
```
File renamed without changes.
Loading