Skip to content

Commit 37b6aa2

Browse files
kinokopioclaude
andcommitted
init
Co-Authored-By: Claude <claude@anthropic.com>
0 parents  commit 37b6aa2

35 files changed

+7878
-0
lines changed

.github/workflows/ci.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
13+
jobs:
14+
# 代码格式和静态检查
15+
lint:
16+
name: Lint & Format Check
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.24'
26+
cache: true
27+
28+
- name: Check go mod tidy
29+
run: |
30+
go mod tidy
31+
git diff --exit-code go.mod go.sum
32+
33+
- name: Check formatting
34+
run: |
35+
if [ -n "$(gofmt -l .)" ]; then
36+
echo "The following files are not formatted correctly:"
37+
gofmt -l .
38+
exit 1
39+
fi
40+
41+
- name: Run go vet
42+
run: go vet ./...
43+
44+
- name: Run golangci-lint
45+
uses: golangci/golangci-lint-action@v6
46+
with:
47+
version: latest
48+
args: --timeout=5m
49+
50+
# 编译测试
51+
build:
52+
name: Build
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
goos: [linux, darwin, windows]
57+
goarch: [amd64, arm64]
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Go
63+
uses: actions/setup-go@v5
64+
with:
65+
go-version: '1.24'
66+
cache: true
67+
68+
- name: Build binary
69+
env:
70+
GOOS: ${{ matrix.goos }}
71+
GOARCH: ${{ matrix.goarch }}
72+
run: |
73+
echo "Building for $GOOS/$GOARCH..."
74+
if [ "$GOOS" = "windows" ]; then
75+
go build -v -ldflags "-X main.Version=ci-test" -o bin/kctl-$GOOS-$GOARCH.exe ./main/main.go
76+
else
77+
go build -v -ldflags "-X main.Version=ci-test" -o bin/kctl-$GOOS-$GOARCH ./main/main.go
78+
fi
79+
80+
- name: Verify binary exists
81+
run: ls -la bin/
82+
83+
# 使用 Makefile 构建测试
84+
build-make:
85+
name: Build with Makefile
86+
runs-on: ubuntu-latest
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: Set up Go
92+
uses: actions/setup-go@v5
93+
with:
94+
go-version: '1.24'
95+
cache: true
96+
97+
- name: Build with make
98+
run: make build
99+
100+
- name: Build all platforms
101+
run: make build-all
102+
103+
- name: List built binaries
104+
run: ls -la bin/
105+
106+
# 单元测试
107+
test:
108+
name: Test
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
113+
114+
- name: Set up Go
115+
uses: actions/setup-go@v5
116+
with:
117+
go-version: '1.24'
118+
cache: true
119+
120+
- name: Run tests
121+
run: go test -v -race -coverprofile=coverage.out ./...
122+
123+
- name: Upload coverage
124+
uses: codecov/codecov-action@v4
125+
with:
126+
files: ./coverage.out
127+
fail_ci_if_error: false
128+
continue-on-error: true
129+
130+
# 安全扫描
131+
security:
132+
name: Security Scan
133+
runs-on: ubuntu-latest
134+
steps:
135+
- name: Checkout code
136+
uses: actions/checkout@v4
137+
138+
- name: Set up Go
139+
uses: actions/setup-go@v5
140+
with:
141+
go-version: '1.24'
142+
cache: true
143+
144+
- name: Run govulncheck
145+
run: |
146+
go install golang.org/x/vuln/cmd/govulncheck@latest
147+
govulncheck ./...
148+
149+
- name: Run gosec
150+
uses: securego/gosec@master
151+
with:
152+
args: '-no-fail -fmt sarif -out results.sarif ./...'
153+
continue-on-error: true
154+
155+
# 依赖审计
156+
dependency-review:
157+
name: Dependency Review
158+
runs-on: ubuntu-latest
159+
if: github.event_name == 'pull_request'
160+
steps:
161+
- name: Checkout code
162+
uses: actions/checkout@v4
163+
164+
- name: Dependency Review
165+
uses: actions/dependency-review-action@v4
166+
with:
167+
fail-on-severity: high

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '1.24'
25+
cache: true
26+
27+
- name: Run tests
28+
run: go test -v ./...
29+
30+
- name: Run GoReleaser
31+
uses: goreleaser/goreleaser-action@v6
32+
with:
33+
distribution: goreleaser
34+
version: '~> v2'
35+
args: release --clean
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/
8+
release/
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool
14+
*.out
15+
16+
# Dependency directories
17+
vendor/
18+
19+
# Go workspace file
20+
go.work
21+
22+
# IDE specific files
23+
.idea/
24+
.vscode/
25+
*.swp
26+
*.swo
27+
*~
28+
29+
# OS specific files
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Temporary files
34+
*.tmp
35+
*.log
36+
37+
# Build artifacts
38+
39+
# Config files (optional, uncomment if needed)
40+
# config.yaml
41+
42+
doc

.goreleaser.yaml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
4+
version: 2
5+
6+
project_name: kctl
7+
8+
before:
9+
hooks:
10+
- go mod tidy
11+
- go generate ./...
12+
13+
builds:
14+
- id: kctl
15+
main: ./main/main.go
16+
binary: kctl
17+
env:
18+
- CGO_ENABLED=0
19+
goos:
20+
- linux
21+
- darwin
22+
- windows
23+
goarch:
24+
- amd64
25+
- arm64
26+
ldflags:
27+
- -s -w
28+
- -X kctl/cmd/version.version={{.Version}}
29+
- -X kctl/cmd/version.commit={{.Commit}}
30+
- -X kctl/cmd/version.date={{.Date}}
31+
- -X kctl/cmd/version.builtBy=goreleaser
32+
mod_timestamp: "{{ .CommitTimestamp }}"
33+
34+
archives:
35+
- id: default
36+
formats:
37+
- tar.gz
38+
name_template: >-
39+
{{ .ProjectName }}_
40+
{{- .Version }}_
41+
{{- .Os }}_
42+
{{- .Arch }}
43+
format_overrides:
44+
- goos: windows
45+
formats:
46+
- zip
47+
files:
48+
- README.md
49+
- LICENSE*
50+
51+
checksum:
52+
name_template: "checksums.txt"
53+
algorithm: sha256
54+
ids:
55+
- default
56+
57+
snapshot:
58+
version_template: "{{ incpatch .Version }}-next"
59+
60+
changelog:
61+
sort: asc
62+
use: github
63+
filters:
64+
exclude:
65+
- "^docs:"
66+
- "^test:"
67+
- "^chore:"
68+
- "^ci:"
69+
- Merge pull request
70+
- Merge branch
71+
groups:
72+
- title: "New Features"
73+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
74+
order: 0
75+
- title: "Bug Fixes"
76+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
77+
order: 1
78+
- title: "Performance Improvements"
79+
regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$'
80+
order: 2
81+
- title: "Refactoring"
82+
regexp: '^.*?refactor(\([[:word:]]+\))??!?:.+$'
83+
order: 3
84+
- title: "Other Changes"
85+
order: 999
86+
87+
release:
88+
github:
89+
owner: "{{ .Env.GITHUB_REPOSITORY_OWNER }}"
90+
name: kctl
91+
draft: false
92+
prerelease: auto
93+
mode: replace
94+
header: |
95+
## kctl {{ .Version }}
96+
97+
Kubernetes Kubelet 安全工具集
98+
footer: |
99+
---
100+
101+
**Full Changelog**: https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/kctl/compare/{{ .PreviousTag }}...{{ .Tag }}
102+
103+
## Installation
104+
105+
### macOS (Apple Silicon)
106+
```bash
107+
curl -LO https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/kctl/releases/download/{{ .Tag }}/kctl_{{ .Version }}_darwin_arm64.tar.gz
108+
tar -xzf kctl_{{ .Version }}_darwin_arm64.tar.gz
109+
chmod +x kctl && sudo mv kctl /usr/local/bin/
110+
```
111+
112+
### macOS (Intel)
113+
```bash
114+
curl -LO https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/kctl/releases/download/{{ .Tag }}/kctl_{{ .Version }}_darwin_amd64.tar.gz
115+
tar -xzf kctl_{{ .Version }}_darwin_amd64.tar.gz
116+
chmod +x kctl && sudo mv kctl /usr/local/bin/
117+
```
118+
119+
### Linux (amd64)
120+
```bash
121+
curl -LO https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/kctl/releases/download/{{ .Tag }}/kctl_{{ .Version }}_linux_amd64.tar.gz
122+
tar -xzf kctl_{{ .Version }}_linux_amd64.tar.gz
123+
chmod +x kctl && sudo mv kctl /usr/local/bin/
124+
```
125+
126+
### Linux (arm64)
127+
```bash
128+
curl -LO https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/kctl/releases/download/{{ .Tag }}/kctl_{{ .Version }}_linux_arm64.tar.gz
129+
tar -xzf kctl_{{ .Version }}_linux_arm64.tar.gz
130+
chmod +x kctl && sudo mv kctl /usr/local/bin/
131+
```
132+
133+
### Windows
134+
Download `kctl_{{ .Version }}_windows_amd64.zip` from the assets below and extract it.

0 commit comments

Comments
 (0)