1- name : CI
1+ # CI:Runner Manager 的测试与构建
2+ name : CI (Manager)
23
34on :
45 push :
89
910env :
1011 GO_VERSION : " 1.26.0"
11- # 若 Go 代码在子目录(与 publish-image 的 DOCKER_CONTEXT 一致),改为该目录如 github-actions;留空则自动检测含 go.mod 且含 cmd/runner-manager 的目录
1212 WORKING_DIR : .
1313
1414jobs :
@@ -21,103 +21,81 @@ jobs:
2121
2222 - name : Detect Go module root
2323 id : modroot
24- run : |
25- set -e
26- cd "$GITHUB_WORKSPACE"
27- ROOT=""
28- if [ -d "$GITHUB_WORKSPACE/${{ env.WORKING_DIR }}/cmd/runner-manager" ]; then
29- ROOT="${{ env.WORKING_DIR }}"
30- fi
31- if [ -z "$ROOT" ]; then
32- ROOT=$(find . -name go.mod 2>/dev/null | while IFS= read -r f; do
33- d=$(dirname "$f")
34- if [ -d "$d/cmd/runner-manager" ]; then echo "$d"; break; fi
35- done | head -1)
36- fi
37- if [ -z "$ROOT" ]; then
38- echo "::error::Could not find directory containing go.mod and cmd/runner-manager. Set env WORKING_DIR to the Go module root (e.g. . or a subdir)."
39- exit 1
40- fi
41- echo "root=$ROOT" >> $GITHUB_OUTPUT
42- echo "Using Go module root: $ROOT"
24+ uses : ./.github/actions/detect-go-module-root
25+ with :
26+ working_dir : ${{ env.WORKING_DIR }}
4327
4428 - name : Set up Go
29+ if : steps.modroot.outputs.found == 'true'
4530 uses : actions/setup-go@v6
4631 with :
4732 go-version : ${{ env.GO_VERSION }}
4833 cache-dependency-path : ${{ steps.modroot.outputs.root }}/go.sum
4934
5035 - name : Vet
51- run : go vet ./...
36+ if : steps.modroot.outputs.found == 'true'
37+ run : go vet ./cmd/runner-manager/... ./internal/...
5238 working-directory : ${{ steps.modroot.outputs.root }}
5339
5440 - name : Lint
41+ if : steps.modroot.outputs.found == 'true'
5542 uses : golangci/golangci-lint-action@v9
5643 with :
5744 version : latest
58- args : --max-same-issues=100000
45+ args : --max-same-issues=100000 ./cmd/runner-manager/... ./internal/...
5946 working-directory : ${{ steps.modroot.outputs.root }}
6047
6148 - name : Run tests
62- run : go test -v ./...
49+ if : steps.modroot.outputs.found == 'true'
50+ run : go test -v ./cmd/runner-manager/... ./internal/...
6351 working-directory : ${{ steps.modroot.outputs.root }}
6452
53+ - name : Skip (no project structure)
54+ if : steps.modroot.outputs.found != 'true'
55+ run : echo "Skipped: no go.mod + cmd/runner-manager in this repo."
56+
6557 build :
6658 name : Build
6759 runs-on : ubuntu-latest
6860 needs : [test]
61+ timeout-minutes : 15
6962 steps :
7063 - name : Checkout code
7164 uses : actions/checkout@v6
7265
7366 - name : Detect Go module root
7467 id : modroot
75- run : |
76- set -e
77- cd "$GITHUB_WORKSPACE"
78- ROOT=""
79- if [ -d "$GITHUB_WORKSPACE/${{ env.WORKING_DIR }}/cmd/runner-manager" ]; then
80- ROOT="${{ env.WORKING_DIR }}"
81- fi
82- if [ -z "$ROOT" ]; then
83- ROOT=$(find . -name go.mod 2>/dev/null | while IFS= read -r f; do
84- d=$(dirname "$f")
85- if [ -d "$d/cmd/runner-manager" ]; then echo "$d"; break; fi
86- done | head -1)
87- fi
88- if [ -z "$ROOT" ]; then
89- echo "::error::Could not find directory containing go.mod and cmd/runner-manager. Set env WORKING_DIR to the Go module root (e.g. . or a subdir)."
90- exit 1
91- fi
92- echo "root=$ROOT" >> $GITHUB_OUTPUT
93- echo "Using Go module root: $ROOT"
68+ uses : ./.github/actions/detect-go-module-root
69+ with :
70+ working_dir : ${{ env.WORKING_DIR }}
9471
9572 - name : Set up Go
73+ if : steps.modroot.outputs.found == 'true'
9674 uses : actions/setup-go@v6
9775 with :
9876 go-version : ${{ env.GO_VERSION }}
9977 cache-dependency-path : ${{ steps.modroot.outputs.root }}/go.sum
10078
10179 - name : Get version information
80+ if : steps.modroot.outputs.found == 'true'
10281 id : version
10382 run : |
10483 VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
10584 echo "version=$VERSION" >> $GITHUB_OUTPUT
10685
10786 - name : Build Manager
87+ if : steps.modroot.outputs.found == 'true'
10888 run : |
10989 go build -ldflags "-s -w -X main.Version=${{ steps.version.outputs.version }}" -o runner-manager ./cmd/runner-manager
11090 working-directory : ${{ steps.modroot.outputs.root }}
11191
112- - name : Build Runner Agent (container mode)
113- run : go build -o runner-agent ./cmd/runner-agent
114- working-directory : ${{ steps.modroot.outputs.root }}
115-
11692 - name : Init example config
93+ if : steps.modroot.outputs.found == 'true'
11794 run : cp config.yaml.example config.yaml
11895 working-directory : ${{ steps.modroot.outputs.root }}
11996
12097 - name : Verify binary
98+ if : steps.modroot.outputs.found == 'true'
12199 run : |
122100 ./runner-manager -version
123101 ./runner-manager -config config.yaml &
@@ -128,3 +106,7 @@ jobs:
128106 kill $PID 2>/dev/null || true
129107 wait $PID 2>/dev/null || true
130108 working-directory : ${{ steps.modroot.outputs.root }}
109+
110+ - name : Skip (no project structure)
111+ if : steps.modroot.outputs.found != 'true'
112+ run : echo "Skipped: no go.mod + cmd/runner-manager in this repo."
0 commit comments