Skip to content

Commit 60e8b65

Browse files
author
Zeusro
committed
Tue Jan 6 23:25:18 CST 2026
1 parent 5bdef41 commit 60e8b65

5 files changed

Lines changed: 367 additions & 18 deletions

File tree

.github/workflows/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# GitHub Actions Workflows
2+
3+
本项目包含两个 GitHub Actions workflow:
4+
5+
## 1. CI Workflow (`.github/workflows/ci.yml`)
6+
7+
**触发条件:**
8+
- 推送到 `main``master` 分支
9+
- 创建 Pull Request 到 `main``master` 分支
10+
11+
**功能:**
12+
- 运行所有测试
13+
- 在多个平台上测试构建(Ubuntu, macOS, Windows)
14+
- 生成代码覆盖率报告
15+
16+
## 2. Release Workflow (`.github/workflows/release.yml`)
17+
18+
**触发条件:**
19+
- 推送以 `v` 开头的 tag(例如:`v1.0.0`
20+
- 手动触发(workflow_dispatch)
21+
22+
**功能:**
23+
- 在多个平台和架构上构建:
24+
- Linux: amd64, arm64
25+
- macOS: amd64, arm64
26+
- Windows: amd64
27+
- 构建两个二进制文件:
28+
- `kube-killer` - 主程序
29+
- `kubectl-kill` - kubectl 插件
30+
- 自动创建 GitHub Release
31+
- 上传所有平台的构建产物
32+
- 生成 SHA256 校验和文件
33+
34+
## 使用方法
35+
36+
### 创建新版本发布
37+
38+
1. 更新版本号(如果需要)
39+
2. 提交更改
40+
3. 创建并推送 tag:
41+
```bash
42+
git tag v1.0.0
43+
git push origin v1.0.0
44+
```
45+
4. GitHub Actions 会自动:
46+
- 构建所有平台的二进制文件
47+
- 创建 GitHub Release
48+
- 上传所有构建产物
49+
50+
### 手动触发构建
51+
52+
1. 前往 GitHub 仓库的 Actions 页面
53+
2. 选择 "Release" workflow
54+
3. 点击 "Run workflow"
55+
4. 选择分支并运行
56+
57+
## 构建产物
58+
59+
每个 Release 包含以下文件:
60+
- `kube-killer-<version>-linux-amd64.tar.gz`
61+
- `kube-killer-<version>-linux-arm64.tar.gz`
62+
- `kube-killer-<version>-darwin-amd64.tar.gz`
63+
- `kube-killer-<version>-darwin-arm64.tar.gz`
64+
- `kube-killer-<version>-windows-amd64.zip`
65+
- `checksums.txt` - 所有文件的 SHA256 校验和
66+
67+
每个压缩包包含:
68+
- `kube-killer` (或 `kube-killer.exe` on Windows)
69+
- `kubectl-kill` (或 `kubectl-kill.exe` on Windows)
70+

.github/workflows/ci.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
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.25'
26+
27+
- name: Cache Go modules
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.cache/go-build
32+
~/go/pkg/mod
33+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
34+
restore-keys: |
35+
${{ runner.os }}-go-
36+
37+
- name: Download dependencies
38+
run: go mod download
39+
40+
- name: Run tests
41+
run: |
42+
mkdir -p artifacts/report/coverage
43+
go test -v -cover -coverprofile c.out.tmp ./...
44+
cat c.out.tmp | grep -v "_mock.go" > c.out || true
45+
go tool cover -html=c.out -o artifacts/report/coverage/index.html || true
46+
47+
- name: Upload coverage report
48+
uses: actions/upload-artifact@v4
49+
if: always()
50+
with:
51+
name: coverage-report
52+
path: artifacts/report/coverage/
53+
retention-days: 7
54+
55+
build-test:
56+
name: Build Test on ${{ matrix.os }}
57+
runs-on: ${{ matrix.os }}
58+
strategy:
59+
matrix:
60+
os: [ubuntu-latest, macos-latest, windows-latest]
61+
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Go
67+
uses: actions/setup-go@v5
68+
with:
69+
go-version: '1.25'
70+
71+
- name: Build kube-killer
72+
run: |
73+
if [ "${{ runner.os }}" == "Windows" ]; then
74+
go build -o kube-killer.exe .
75+
else
76+
go build -o kube-killer .
77+
fi
78+
79+
- name: Build kubectl-kill plugin
80+
run: |
81+
if [ "${{ runner.os }}" == "Windows" ]; then
82+
go build -o kubectl-kill.exe ./cmd/kubectl-kill
83+
else
84+
go build -o kubectl-kill ./cmd/kubectl-kill
85+
fi
86+
87+
- name: Verify binaries
88+
run: |
89+
if [ "${{ runner.os }}" == "Windows" ]; then
90+
./kube-killer.exe version
91+
./kubectl-kill.exe --help
92+
else
93+
./kube-killer version
94+
./kubectl-kill --help
95+
fi
96+

.github/workflows/release.yml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # 当推送以 v 开头的 tag 时触发
7+
workflow_dispatch: # 允许手动触发
8+
9+
jobs:
10+
build:
11+
name: Build for ${{ matrix.os }}/${{ matrix.arch }}
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
# Linux
18+
- os: ubuntu-latest
19+
arch: amd64
20+
goarch: amd64
21+
goos: linux
22+
- os: ubuntu-latest
23+
arch: arm64
24+
goarch: arm64
25+
goos: linux
26+
# macOS
27+
- os: macos-latest
28+
arch: amd64
29+
goarch: amd64
30+
goos: darwin
31+
- os: macos-latest
32+
arch: arm64
33+
goarch: arm64
34+
goos: darwin
35+
# Windows
36+
- os: windows-latest
37+
arch: amd64
38+
goarch: amd64
39+
goos: windows
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: '1.25'
49+
50+
- name: Get version from tag
51+
id: get_version
52+
run: |
53+
if [ "${{ github.ref_type }}" == "tag" ]; then
54+
VERSION=${GITHUB_REF#refs/tags/}
55+
else
56+
VERSION="dev-$(git rev-parse --short HEAD)"
57+
fi
58+
echo "version=$VERSION" >> $GITHUB_OUTPUT
59+
echo "Version: $VERSION"
60+
61+
- name: Build kube-killer
62+
env:
63+
GOOS: ${{ matrix.goos }}
64+
GOARCH: ${{ matrix.goarch }}
65+
CGO_ENABLED: 0
66+
shell: bash
67+
run: |
68+
OUTPUT="kube-killer"
69+
if [ "${{ matrix.goos }}" == "windows" ]; then
70+
OUTPUT="kube-killer.exe"
71+
fi
72+
go build -ldflags="-s -w -X github.com/p-program/kube-killer/cmd.VERSION=${{ steps.get_version.outputs.version }}" -o $OUTPUT .
73+
mkdir -p dist
74+
mv $OUTPUT dist/
75+
76+
- name: Build kubectl-kill plugin
77+
env:
78+
GOOS: ${{ matrix.goos }}
79+
GOARCH: ${{ matrix.goarch }}
80+
CGO_ENABLED: 0
81+
shell: bash
82+
run: |
83+
OUTPUT="kubectl-kill"
84+
if [ "${{ matrix.goos }}" == "windows" ]; then
85+
OUTPUT="kubectl-kill.exe"
86+
fi
87+
go build -ldflags="-s -w -X github.com/p-program/kube-killer/cmd.VERSION=${{ steps.get_version.outputs.version }}" -o $OUTPUT ./cmd/kubectl-kill
88+
mkdir -p dist
89+
mv $OUTPUT dist/
90+
91+
- name: Create archive (Linux/macOS)
92+
if: matrix.goos != 'windows'
93+
shell: bash
94+
run: |
95+
cd dist
96+
ARCHIVE_NAME="kube-killer-${{ steps.get_version.outputs.version }}-${{ matrix.goos }}-${{ matrix.arch }}"
97+
tar czf "${ARCHIVE_NAME}.tar.gz" *
98+
cd ..
99+
mv "dist/${ARCHIVE_NAME}.tar.gz" dist/
100+
101+
- name: Create archive (Windows)
102+
if: matrix.goos == 'windows'
103+
shell: pwsh
104+
run: |
105+
$version = "${{ steps.get_version.outputs.version }}"
106+
$archiveName = "kube-killer-$version-windows-${{ matrix.arch }}.zip"
107+
Compress-Archive -Path dist\* -DestinationPath "dist\$archiveName" -Force
108+
109+
- name: Upload artifacts
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: kube-killer-${{ matrix.goos }}-${{ matrix.arch }}
113+
path: |
114+
dist/kube-killer-${{ steps.get_version.outputs.version }}-${{ matrix.goos }}-${{ matrix.arch }}.*
115+
retention-days: 30
116+
117+
release:
118+
name: Create Release
119+
needs: build
120+
runs-on: ubuntu-latest
121+
if: github.ref_type == 'tag'
122+
123+
steps:
124+
- name: Checkout code
125+
uses: actions/checkout@v4
126+
127+
- name: Get version from tag
128+
id: get_version
129+
run: |
130+
VERSION=${GITHUB_REF#refs/tags/}
131+
echo "version=$VERSION" >> $GITHUB_OUTPUT
132+
echo "Version: $VERSION"
133+
134+
- name: Download all artifacts
135+
uses: actions/download-artifact@v4
136+
with:
137+
path: artifacts
138+
139+
- name: Prepare release assets
140+
run: |
141+
mkdir -p release-assets
142+
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release-assets/ \;
143+
ls -lh release-assets/
144+
145+
- name: Generate checksums
146+
run: |
147+
cd release-assets
148+
sha256sum *.tar.gz *.zip > checksums.txt 2>/dev/null || true
149+
cd ..
150+
151+
- name: Create Release
152+
uses: softprops/action-gh-release@v2
153+
with:
154+
files: release-assets/*
155+
name: Release ${{ steps.get_version.outputs.version }}
156+
body: |
157+
## kube-killer ${{ steps.get_version.outputs.version }}
158+
159+
### Downloads
160+
161+
#### kube-killer (Main Binary)
162+
- **Linux amd64**: `kube-killer-${{ steps.get_version.outputs.version }}-linux-amd64.tar.gz`
163+
- **Linux arm64**: `kube-killer-${{ steps.get_version.outputs.version }}-linux-arm64.tar.gz`
164+
- **macOS amd64**: `kube-killer-${{ steps.get_version.outputs.version }}-darwin-amd64.tar.gz`
165+
- **macOS arm64**: `kube-killer-${{ steps.get_version.outputs.version }}-darwin-arm64.tar.gz`
166+
- **Windows amd64**: `kube-killer-${{ steps.get_version.outputs.version }}-windows-amd64.zip`
167+
168+
#### kubectl-kill (Plugin)
169+
All archives include both `kube-killer` and `kubectl-kill` binaries.
170+
171+
### Installation
172+
173+
**Linux/macOS:**
174+
```bash
175+
# Download and extract
176+
tar -xzf kube-killer-${{ steps.get_version.outputs.version }}-linux-amd64.tar.gz
177+
# Install kube-killer
178+
sudo mv kube-killer /usr/local/bin/
179+
# Install kubectl plugin
180+
mkdir -p ~/.local/bin
181+
mv kubectl-kill ~/.local/bin/
182+
export PATH=$PATH:~/.local/bin
183+
```
184+
185+
**Windows:**
186+
```powershell
187+
# Extract the zip file
188+
Expand-Archive kube-killer-${{ steps.get_version.outputs.version }}-windows-amd64.zip
189+
# Add to PATH or move to desired location
190+
```
191+
192+
### Verify Checksums
193+
See `checksums.txt` for SHA256 checksums of all release files.
194+
draft: false
195+
prerelease: ${{ contains(steps.get_version.outputs.version, '-') }}
196+
env:
197+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
198+

TODO.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

cmd/version.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
const (
10-
VERSION = "1.0.0"
9+
var (
10+
// VERSION is set during build via ldflags
11+
VERSION = "dev"
1112
)
1213

1314
func NewVersionCommand() *cobra.Command {

0 commit comments

Comments
 (0)