Skip to content

Commit 642f075

Browse files
committed
initial code
1 parent e6467b7 commit 642f075

13 files changed

Lines changed: 797 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Dependabot Auto
2+
on: pull_request
3+
4+
permissions:
5+
pull-requests: write
6+
contents: write
7+
8+
jobs:
9+
dependabot-approve:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.actor == 'dependabot[bot]' }}
12+
steps:
13+
- name: Dependabot metadata
14+
id: metadata
15+
uses: dependabot/fetch-metadata@v2.5.0
16+
with:
17+
github-token: "${{ secrets.GITHUB_TOKEN }}"
18+
- name: Approve a PR
19+
run: gh pr review --approve "$PR_URL"
20+
env:
21+
PR_URL: ${{github.event.pull_request.html_url}}
22+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
23+
dependabot-merge:
24+
runs-on: ubuntu-latest
25+
if: ${{ github.actor == 'dependabot[bot]' }}
26+
steps:
27+
- name: Dependabot metadata
28+
id: metadata
29+
uses: dependabot/fetch-metadata@v2.5.0
30+
with:
31+
github-token: "${{ secrets.GITHUB_TOKEN }}"
32+
- name: Enable auto-merge for Dependabot PRs
33+
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
34+
run: gh pr merge --auto --merge "$PR_URL"
35+
env:
36+
PR_URL: ${{github.event.pull_request.html_url}}
37+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/golang.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Golang CI
2+
permissions:
3+
contents: read
4+
5+
on:
6+
push:
7+
branches: [main, develop]
8+
paths:
9+
- "**/*.go"
10+
- "go.mod"
11+
- "go.sum"
12+
pull_request:
13+
branches: [main, develop]
14+
paths:
15+
- "**/*.go"
16+
- "go.mod"
17+
- "go.sum"
18+
19+
env:
20+
GO_MODULE: https://github.com/opendefensecloud/testkit
21+
GO_VERSION: 1.25.7
22+
23+
jobs:
24+
lint:
25+
runs-on: arc-scale-set
26+
steps:
27+
- uses: actions/checkout@v6
28+
- uses: actions/setup-go@v6
29+
with:
30+
go-version: ${{ env.GO_VERSION }}
31+
- name: lint-license-and-shell
32+
run: |
33+
make lint-no-golangci
34+
- name: golangci-lint
35+
uses: golangci/golangci-lint-action@v9
36+
37+
test:
38+
needs: lint
39+
runs-on: arc-scale-set
40+
steps:
41+
- uses: actions/checkout@v6
42+
- uses: actions/setup-go@v6
43+
with:
44+
go-version: ${{ env.GO_VERSION }}
45+
- name: test
46+
run: make test
47+
- name: Coveralls GitHub Action
48+
uses: coverallsapp/github-action@v2.3.7
49+
with:
50+
github-token: ${{ secrets.github_token }}
51+
path-to-lcov: coverage.lcov

.github/workflows/osv-scanner.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: OSV-Scanner
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
merge_group:
7+
types: [checks_requested]
8+
schedule:
9+
- cron: "12 12 * * 1"
10+
push:
11+
branches: ["main"]
12+
13+
permissions:
14+
# Required to upload SARIF file to CodeQL. See: https://github.com/github/codeql-action/issues/2117
15+
actions: read
16+
# Require writing security events to upload SARIF file to security tab
17+
security-events: write
18+
# Read commit contents
19+
contents: read
20+
21+
jobs:
22+
scan-scheduled:
23+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
24+
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@c5996e0193a3df57d695c1b8a1dec2a4c62e8730" # v2.3.3
25+
with:
26+
# Example of specifying custom arguments
27+
scan-args: |-
28+
--include-git-root
29+
--config ./.osv-scanner.toml
30+
-r
31+
./
32+
scan-pr:
33+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
34+
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@c5996e0193a3df57d695c1b8a1dec2a4c62e8730" # v2.3.3
35+
with:
36+
# Example of specifying custom arguments
37+
scan-args: |-
38+
--include-git-root
39+
--config ./.osv-scanner.toml
40+
-r
41+
./

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dll
88
*.so
99
*.dylib
10+
/bin/*
1011

1112
# Test binary, built with `go test -c`
1213
*.test

Makefile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
# Setting SHELL to bash allows bash commands to be executed by recipes.
3+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
4+
SHELL = /usr/bin/env bash -o pipefail
5+
.SHELLFLAGS = -ec
6+
7+
# Set MAKEFLAGS to suppress entering/leaving directory messages
8+
MAKEFLAGS += --no-print-directory
9+
10+
BUILD_PATH ?= $(shell pwd)
11+
HACK_DIR ?= $(shell cd hack 2>/dev/null && pwd)
12+
LOCALBIN ?= $(BUILD_PATH)/bin
13+
14+
OS := $(shell go env GOOS)
15+
ARCH := $(shell go env GOARCH)
16+
17+
GO ?= go
18+
SHELLCHECK ?= shellcheck
19+
OSV_SCANNER ?= osv-scanner
20+
MKDOCS ?= mkdocs
21+
DOCKER ?= docker
22+
GINKGO ?= $(LOCALBIN)/ginkgo
23+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
24+
SETUP_ENVTEST ?= $(LOCALBIN)/setup-envtest
25+
ADDLICENSE ?= $(LOCALBIN)/addlicense
26+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
27+
OPENAPI_GEN ?= $(LOCALBIN)/openapi-gen
28+
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
29+
OCM ?= $(LOCALBIN)/ocm
30+
31+
GINKGO_VERSION ?= $(shell go list -json -m -u github.com/onsi/ginkgo/v2 | jq -r '.Version')
32+
GOLANGCI_LINT_VERSION ?= v2.10.1
33+
SETUP_ENVTEST_VERSION ?= release-0.22
34+
ADDLICENSE_VERSION ?= v1.1.1
35+
CRD_REF_DOCS_VERSION ?= v0.2.0
36+
37+
export GOPRIVATE=*.go.opendefense.cloud/testkit
38+
export GNOSUMDB=*.go.opendefense.cloud/testkit
39+
export GNOPROXY=*.go.opendefense.cloud/testkit
40+
41+
##@ General
42+
43+
# The help target prints out all targets with their descriptions organized
44+
# beneath their categories. The categories are represented by '##@' and the
45+
# target descriptions by '##'. The awk commands is responsible for reading the
46+
# entire set of makefiles included in this invocation, looking for lines of the
47+
# file as xyz: ## something, and then pretty-format the target and help. Then,
48+
# if there's a line with ##@ something, that gets pretty-printed as a category.
49+
# More info on the usage of ANSI control characters for terminal formatting:
50+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
51+
# More info on the awk command:
52+
# http://linuxcommand.org/lc3_adv_awk.php
53+
54+
help: ## Display this help.
55+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[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)
56+
57+
.PHONY: clean
58+
clean:
59+
rm -rf $(LOCALBIN)
60+
61+
62+
.PHONY: fmt
63+
fmt: addlicense golangci-lint ## Add license headers and format
64+
echo $(ADDLICENCE)
65+
find . -not -path '*/.*' -name '*.go' -exec $(ADDLICENSE) -c 'BWI GmbH and Testkit contributors' -l apache -s=only {} +
66+
$(GO) fmt ./...
67+
$(GOLANGCI_LINT) run --fix
68+
69+
.PHONY: mod
70+
mod: ## Do go mod tidy, download, verify
71+
@$(GO) mod tidy
72+
@$(GO) mod download
73+
@$(GO) mod verify
74+
75+
.PHONY: lint
76+
lint: lint-no-golangci golangci-lint ## Run linters such as golangci-lint and addlicence checks
77+
$(GOLANGCI_LINT) run -v
78+
79+
.PHONY: lint-no-golangci
80+
lint-no-golangci: addlicense
81+
find . -not -path '*/.*' -name '*.go' -exec $(ADDLICENSE) -check -l apache -s=only -check {} +
82+
shellcheck hack/*.sh
83+
84+
.PHONY: scan
85+
scan:
86+
$(OSV_SCANNER) scan --config ./.osv-scanner.toml -r .
87+
88+
.PHONY: test
89+
test: ginkgo ## Run all tests
90+
$(GINKGO) -r -cover --fail-fast --require-suite -covermode count --output-dir=$(BUILD_PATH) -coverprofile=testkit.coverprofile $(testargs)
91+
92+
TIMESTAMP ?= $(shell date '+%Y%m%d%H%M%S')
93+
94+
$(LOCALBIN):
95+
mkdir -p $(LOCALBIN)
96+
97+
.PHONY: golangci-lint
98+
golangci-lint: $(LOCALBIN) ## Download golangci-lint locally if necessary.
99+
@test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION) || \
100+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
101+
102+
.PHONY: ginkgo
103+
ginkgo: $(LOCALBIN) ## Download ginkgo locally if necessary.
104+
@test -s $(LOCALBIN)/ginkgo && $(LOCALBIN)/ginkgo version | grep -q $(subst v,,$(GINKGO_VERSION)) || \
105+
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
106+
107+
.PHONY: addlicense
108+
addlicense: $(LOCALBIN) ## Download addlicense locally if necessary.
109+
@test -s $(LOCALBIN)/addlicense && grep -q $(ADDLICENSE_VERSION) $(LOCALBIN)/.addlicense-version 2>/dev/null || \
110+
GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION); \
111+
echo $(ADDLICENSE_VERSION) > $(LOCALBIN)/.addlicense-version
112+
113+
114+
115+
.PHONY: crd-ref-docs
116+
crd-ref-docs: $(LOCALBIN) ## Download crd-ref-docs locally if necessary.
117+
@test -s $(LOCALBIN)/crd-ref-docs && $(LOCALBIN)/crd-ref-docs --version | grep -q $(CRD_REF_DOCS_VERSION) || \
118+
GOBIN=$(LOCALBIN) go install github.com/elastic/crd-ref-docs@$(CRD_REF_DOCS_VERSION)

0 commit comments

Comments
 (0)