Skip to content

Commit b4ee40e

Browse files
committed
feat: 添加 CI/CD 工作流和自动化发布流程,更新标签创建脚本
1 parent e6595e2 commit b4ee40e

File tree

7 files changed

+590
-0
lines changed

7 files changed

+590
-0
lines changed

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
go: ["1.21"]
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: ${{ matrix.go }}
26+
27+
- name: Cache Go modules
28+
uses: actions/cache@v3
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: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
42+
43+
- name: Upload coverage to Codecov
44+
if: matrix.os == 'ubuntu-latest'
45+
uses: codecov/codecov-action@v3
46+
with:
47+
files: ./coverage.out
48+
flags: unittests
49+
name: codecov-umbrella
50+
51+
- name: Build
52+
run: go build -v ./cmd/sshx
53+
54+
lint:
55+
name: Lint
56+
runs-on: ubuntu-latest
57+
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.21"
66+
67+
- name: Run golangci-lint
68+
uses: golangci/golangci-lint-action@v3
69+
with:
70+
version: latest
71+
args: --timeout=5m
72+
73+
security:
74+
name: Security Scan
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Run Gosec Security Scanner
82+
uses: securego/gosec@master
83+
with:
84+
args: "-no-fail -fmt sarif -out results.sarif ./..."
85+
86+
- name: Upload SARIF file
87+
uses: github/codeql-action/upload-sarif@v2
88+
with:
89+
sarif_file: results.sarif

.github/workflows/release.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
name: Build and Release
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: "1.21"
26+
27+
- name: Get version
28+
id: get_version
29+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
30+
31+
- name: Build binaries
32+
run: |
33+
# 创建输出目录
34+
mkdir -p dist
35+
36+
# 定义构建函数
37+
build() {
38+
local os=$1
39+
local arch=$2
40+
local output="dist/sshx-${os}-${arch}"
41+
42+
if [ "$os" = "windows" ]; then
43+
output="${output}.exe"
44+
fi
45+
46+
echo "Building for $os/$arch..."
47+
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build \
48+
-ldflags="-s -w -X main.Version=${{ steps.get_version.outputs.VERSION }}" \
49+
-o "$output" \
50+
./cmd/sshx
51+
52+
# 压缩二进制文件
53+
if [ "$os" = "windows" ]; then
54+
zip "dist/sshx-${os}-${arch}.zip" "$output"
55+
rm "$output"
56+
else
57+
tar czf "dist/sshx-${os}-${arch}.tar.gz" -C dist "$(basename $output)"
58+
rm "$output"
59+
fi
60+
}
61+
62+
# 构建所有平台
63+
build linux amd64
64+
build linux arm64
65+
build darwin amd64
66+
build darwin arm64
67+
build windows amd64
68+
69+
- name: Generate checksums
70+
run: |
71+
cd dist
72+
sha256sum * > checksums.txt
73+
cat checksums.txt
74+
75+
- name: Create Release
76+
uses: softprops/action-gh-release@v1
77+
with:
78+
name: Release ${{ steps.get_version.outputs.VERSION }}
79+
body: |
80+
## SSH & SFTP Remote Tool with MCP Support
81+
82+
### 下载说明
83+
84+
请根据您的操作系统选择对应的二进制文件:
85+
86+
- **Linux (x86_64)**: `sshx-linux-amd64.tar.gz`
87+
- **Linux (ARM64)**: `sshx-linux-arm64.tar.gz`
88+
- **macOS (Intel)**: `sshx-darwin-amd64.tar.gz`
89+
- **macOS (Apple Silicon)**: `sshx-darwin-arm64.tar.gz`
90+
- **Windows (x86_64)**: `sshx-windows-amd64.zip`
91+
92+
### 安装方法
93+
94+
#### Linux / macOS
95+
```bash
96+
# 下载并解压
97+
tar xzf sshx-<platform>-<arch>.tar.gz
98+
99+
# 移动到系统路径
100+
sudo mv sshx /usr/local/bin/
101+
102+
# 赋予执行权限
103+
sudo chmod +x /usr/local/bin/sshx
104+
105+
# 验证安装
106+
sshx --help
107+
```
108+
109+
#### Windows
110+
```powershell
111+
# 解压 zip 文件
112+
# 将 sshx.exe 添加到系统 PATH
113+
# 或直接在解压目录下使用
114+
```
115+
116+
### 功能特性
117+
118+
- ✅ SSH 远程命令执行
119+
- ✅ SFTP 文件传输(上传/下载/列表/创建目录/删除)
120+
- ✅ 跨平台密码管理(系统 Keyring)
121+
- ✅ 命令安全检查(防止危险操作)
122+
- ✅ MCP (Model Context Protocol) 支持
123+
- ✅ Sudo 密码自动填充
124+
125+
### 校验和
126+
127+
请使用 `checksums.txt` 验证下载文件的完整性:
128+
```bash
129+
sha256sum -c checksums.txt
130+
```
131+
132+
### 更新日志
133+
134+
查看 [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) 了解详细更新内容。
135+
136+
files: |
137+
dist/*
138+
draft: false
139+
prerelease: false
140+
env:
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
143+
- name: Upload artifacts
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: binaries
147+
path: dist/*
148+
retention-days: 30

.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
run:
2+
timeout: 5m
3+
tests: true
4+
modules-download-mode: readonly
5+
6+
linters:
7+
enable:
8+
- errcheck
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- unused
14+
- gofmt
15+
- goimports
16+
- misspell
17+
- unconvert
18+
- unparam
19+
- nakedret
20+
- prealloc
21+
- exportloopref
22+
- noctx
23+
- gosec
24+
25+
linters-settings:
26+
errcheck:
27+
check-type-assertions: true
28+
check-blank: true
29+
30+
govet:
31+
check-shadowing: true
32+
33+
gofmt:
34+
simplify: true
35+
36+
misspell:
37+
locale: US
38+
39+
nakedret:
40+
max-func-lines: 30
41+
42+
issues:
43+
exclude-rules:
44+
- path: _test\.go
45+
linters:
46+
- errcheck
47+
- gosec

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial release
13+
- SSH remote command execution
14+
- SFTP file operations (upload, download, list, mkdir, remove)
15+
- Cross-platform password management using system keyring
16+
- Command safety checks to prevent dangerous operations
17+
- MCP (Model Context Protocol) support
18+
- Sudo password auto-fill from keyring
19+
- Environment variable support
20+
- Comprehensive unit tests
21+
22+
### Changed
23+
24+
- Code refactored into modular structure
25+
- Improved error handling
26+
27+
### Fixed
28+
29+
- N/A
30+
31+
## [1.0.0] - 2025-01-12
32+
33+
### Added
34+
35+
- Initial public release
36+
- Core SSH/SFTP functionality
37+
- Password management
38+
- MCP support
39+
- Safety checks
40+
- Multi-platform support (Linux, macOS, Windows)
41+
42+
[Unreleased]: https://github.com/talkincode/sshmcp/compare/v1.0.0...HEAD
43+
[1.0.0]: https://github.com/talkincode/sshmcp/releases/tag/v1.0.0

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ check: fmt vet test ## 运行所有检查(格式化、vet、测试)
150150
ci: deps check test-coverage ## CI/CD 流程(依赖、检查、覆盖率)
151151
@echo "CI 流程完成!"
152152

153+
tag:
154+
@echo "🏷️ 开始标签创建流程..."
155+
@./scripts/tag.sh
156+
153157
dev: ## 开发模式(安装依赖、格式化、测试、构建)
154158
@echo "开发模式..."
155159
@$(MAKE) deps

0 commit comments

Comments
 (0)