Skip to content

Commit 7487732

Browse files
authored
Merge pull request #3 from scriptscat/feat/sctl-daemon
✨ 新增 sctl 本地守护进程与 MCP 桥接
2 parents ad78de4 + fe83e03 commit 7487732

79 files changed

Lines changed: 10593 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
# 发布不允许被后续运行打断。
12+
group: release-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
# 复用测试工作流的全部门禁(lint / test / 协议一致性),门禁不过不发布。
17+
test:
18+
uses: ./.github/workflows/test.yaml
19+
permissions:
20+
contents: read
21+
22+
build:
23+
needs: test
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
include:
29+
- goos: darwin
30+
goarch: amd64
31+
arch: x86_64
32+
format: tar.gz
33+
- goos: darwin
34+
goarch: arm64
35+
arch: arm64
36+
format: tar.gz
37+
- goos: linux
38+
goarch: amd64
39+
arch: x86_64
40+
format: tar.gz
41+
- goos: linux
42+
goarch: arm64
43+
arch: arm64
44+
format: tar.gz
45+
- goos: windows
46+
goarch: amd64
47+
arch: x86_64
48+
format: zip
49+
- goos: windows
50+
goarch: arm64
51+
arch: arm64
52+
format: zip
53+
steps:
54+
- uses: actions/checkout@v5
55+
- uses: actions/setup-go@v6
56+
with:
57+
go-version-file: go.mod
58+
cache: true
59+
- name: 构建并打包
60+
env:
61+
GOOS: ${{ matrix.goos }}
62+
GOARCH: ${{ matrix.goarch }}
63+
CGO_ENABLED: "0"
64+
run: |
65+
set -euo pipefail
66+
VERSION="${GITHUB_REF_NAME#v}"
67+
BUILD_DATE=$(git show -s --format=%cI HEAD)
68+
COMMIT_TIMESTAMP=$(git show -s --format=%ct HEAD)
69+
PACKAGE="sctl_${VERSION}_${GOOS}_${{ matrix.arch }}"
70+
STAGE="dist/${PACKAGE}"
71+
BINARY=sctl
72+
if [ "$GOOS" = windows ]; then
73+
BINARY=sctl.exe
74+
fi
75+
76+
mkdir -p "$STAGE/docs"
77+
go build -trimpath -ldflags "-s -w \
78+
-X github.com/scriptscat/sctl/internal/cli.Version=${VERSION} \
79+
-X github.com/scriptscat/sctl/internal/cli.Commit=${GITHUB_SHA} \
80+
-X github.com/scriptscat/sctl/internal/cli.BuildDate=${BUILD_DATE}" \
81+
-o "$STAGE/$BINARY" ./cmd/sctl
82+
cp README.md LICENSE* "$STAGE/"
83+
cp -R docs/. "$STAGE/docs/"
84+
find "$STAGE" -exec touch -d "@${COMMIT_TIMESTAMP}" {} +
85+
86+
if [ "${{ matrix.format }}" = zip ]; then
87+
(cd dist && zip -X -q -r "${PACKAGE}.zip" "$PACKAGE")
88+
else
89+
tar --sort=name --mtime="@${COMMIT_TIMESTAMP}" --owner=0 --group=0 --numeric-owner \
90+
-C dist -czf "dist/${PACKAGE}.tar.gz" "$PACKAGE"
91+
fi
92+
- uses: actions/upload-artifact@v7
93+
with:
94+
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
95+
path: dist/*.${{ matrix.format }}
96+
if-no-files-found: error
97+
98+
release:
99+
name: Create Release
100+
needs: build
101+
runs-on: ubuntu-latest
102+
permissions:
103+
contents: write # 创建 GitHub Release 并上传产物
104+
id-token: write # 构建来源证明(build provenance)签名
105+
attestations: write
106+
steps:
107+
- uses: actions/checkout@v5
108+
- uses: actions/download-artifact@v8
109+
with:
110+
path: artifacts
111+
pattern: release-*
112+
merge-multiple: true
113+
- name: 生成校验和
114+
run: cd artifacts && sha256sum * > checksums.txt
115+
- name: 判断是否为预发布
116+
id: prerelease
117+
env:
118+
TAG: ${{ github.ref_name }}
119+
run: |
120+
if [[ "$TAG" == *-* ]]; then
121+
echo "flag=--prerelease" >> "$GITHUB_OUTPUT"
122+
fi
123+
- name: 创建 GitHub 草稿 Release
124+
env:
125+
GH_TOKEN: ${{ github.token }}
126+
PRERELEASE_FLAG: ${{ steps.prerelease.outputs.flag }}
127+
run: |
128+
gh release create "$GITHUB_REF_NAME" \
129+
--draft \
130+
--title "$GITHUB_REF_NAME" \
131+
--generate-notes \
132+
$PRERELEASE_FLAG \
133+
artifacts/*
134+
- name: 生成构建来源证明
135+
# 只对 checksums.txt 签名即可:它覆盖了全部产物的 sha256,
136+
# 用户先 `sha256sum -c` 再 `gh attestation verify checksums.txt` 就形成完整信任链。
137+
uses: actions/attest-build-provenance@v4
138+
with:
139+
subject-path: artifacts/checksums.txt
140+
- name: 输出发布摘要
141+
run: |
142+
{
143+
echo "## sctl ${GITHUB_REF_NAME} 发布产物"
144+
echo
145+
echo '```'
146+
cat artifacts/checksums.txt
147+
echo '```'
148+
echo
149+
echo "Release 以**草稿**形式创建,确认 changelog 后手动点击 Publish。"
150+
} >> "$GITHUB_STEP_SUMMARY"

.github/workflows/test.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches: [main, "release/**"]
6+
pull_request:
7+
# 供 release 工作流复用:打 tag 发布前跑同一套门禁,避免两边规则漂移。
8+
workflow_call:
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
# PR 上新提交会取消上一次运行;main / release 分支保留每次运行。
16+
group: test-${{ github.ref }}
17+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
18+
19+
jobs:
20+
lint:
21+
name: lint
22+
runs-on: ubuntu-latest
23+
env:
24+
# 与本地开发保持同一版本,避免"本地过 CI 挂"。升级时同步改 docs/development.md。
25+
GOLANGCI_LINT_VERSION: v2.12.2
26+
steps:
27+
- uses: actions/checkout@v5
28+
- uses: actions/setup-go@v6
29+
with:
30+
go-version-file: go.mod
31+
cache: true
32+
- uses: golangci/golangci-lint-action@v9
33+
with:
34+
version: ${{ env.GOLANGCI_LINT_VERSION }}
35+
36+
test:
37+
name: test (${{ matrix.os }})
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
os: [ubuntu-latest, macos-latest, windows-latest]
42+
runs-on: ${{ matrix.os }}
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: actions/setup-go@v6
46+
with:
47+
go-version-file: go.mod
48+
cache: true
49+
- run: go build ./...
50+
- run: go vet ./...
51+
- run: go test -race ./...
52+
53+
protocol-schema:
54+
name: protocol schema and ScriptCat mirror
55+
runs-on: ubuntu-latest
56+
env:
57+
SCRIPTCAT_REF: e32bb5a43d3061aa1d380f62328bd249fdf55ac8
58+
steps:
59+
- uses: actions/checkout@v5
60+
with:
61+
path: sctl
62+
- uses: actions/checkout@v5
63+
with:
64+
repository: scriptscat/scriptcat
65+
ref: ${{ env.SCRIPTCAT_REF }}
66+
path: scriptcat
67+
- uses: actions/setup-go@v6
68+
with:
69+
go-version-file: sctl/go.mod
70+
cache-dependency-path: sctl/go.sum
71+
- uses: actions/setup-node@v4
72+
with:
73+
node-version: 22
74+
- name: Check generated artifacts and exact paired mirror
75+
working-directory: sctl
76+
run: |
77+
make protocol-check
78+
mkdir -p ../formatted
79+
cp internal/pkg/protocol/generated/*.ts ../formatted/
80+
npx --yes prettier@3.6.2 --config ../scriptcat/.prettierrc --write ../formatted/*.ts
81+
cmp ../formatted/protocol.generated.ts ../scriptcat/src/app/service/service_worker/external_access/generated/protocol.generated.ts
82+
cmp ../formatted/validators.generated.ts ../scriptcat/src/app/service/service_worker/external_access/generated/validators.generated.ts
83+
{
84+
echo "ScriptCat ref: $SCRIPTCAT_REF"
85+
sha256sum ../formatted/*.ts
86+
} >> "$GITHUB_STEP_SUMMARY"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/sctl
2+
/bin/
3+
dist/
4+
# 一次性端到端验证脚本与证据(见 docs/verification.md),永远不进版本库
5+
/e2e/scratch/

.golangci.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: "2"
2+
3+
# 注意:golangci-lint 只分析当前 GOOS 下参与构建的文件,`_windows.go` 一类
4+
# 带构建标签的代码在 Linux 测试 CI 上不会被检查;跨平台产物由发布流程编译。
5+
6+
linters:
7+
default: standard # errcheck govet ineffassign staticcheck unused
8+
enable:
9+
- bodyclose # HTTP body 未关闭
10+
- errorlint # %w / errors.Is 用法
11+
- gocritic
12+
- misspell
13+
- nilerr # 拿到 err 却返回 nil
14+
- nolintlint # //nolint 必须写明理由
15+
- revive
16+
- unconvert
17+
- usestdlibvars
18+
- whitespace
19+
settings:
20+
errcheck:
21+
check-type-assertions: true
22+
nolintlint:
23+
require-explanation: true
24+
require-specific: true
25+
revive:
26+
rules:
27+
- name: exported
28+
disabled: true # 内部包为主,不强制导出符号注释
29+
- name: unused-parameter
30+
disabled: true
31+
exclusions:
32+
generated: lax
33+
presets:
34+
- comments
35+
- common-false-positives
36+
- legacy
37+
- std-error-handling
38+
rules:
39+
# 测试里大量 defer close / 断言,放宽噪音较大的检查。
40+
- path: _test\.go
41+
linters:
42+
- bodyclose
43+
- errcheck
44+
45+
formatters:
46+
enable:
47+
- gofmt
48+
- goimports
49+
settings:
50+
goimports:
51+
local-prefixes:
52+
- github.com/scriptscat/sctl

0 commit comments

Comments
 (0)