|
| 1 | +# CI:Runner Manager 的测试与构建 |
| 2 | +name: CI (Manager) |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [main, master, develop] |
| 7 | + pull_request: |
| 8 | + branches: [main, master, develop] |
| 9 | + |
| 10 | +env: |
| 11 | + GO_VERSION: "1.26.0" |
| 12 | + WORKING_DIR: . |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + name: Test |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v6 |
| 21 | + |
| 22 | + - name: Detect Go module root |
| 23 | + id: modroot |
| 24 | + uses: ./.github/actions/detect-go-module-root |
| 25 | + with: |
| 26 | + working_dir: ${{ env.WORKING_DIR }} |
| 27 | + |
| 28 | + - name: Set up Go |
| 29 | + if: steps.modroot.outputs.found == 'true' |
| 30 | + uses: actions/setup-go@v6 |
| 31 | + with: |
| 32 | + go-version: ${{ env.GO_VERSION }} |
| 33 | + cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum |
| 34 | + |
| 35 | + - name: Vet |
| 36 | + if: steps.modroot.outputs.found == 'true' |
| 37 | + run: go vet ./cmd/runner-manager/... ./internal/... |
| 38 | + working-directory: ${{ steps.modroot.outputs.root }} |
| 39 | + |
| 40 | + - name: Lint |
| 41 | + if: steps.modroot.outputs.found == 'true' |
| 42 | + uses: golangci/golangci-lint-action@v9 |
| 43 | + with: |
| 44 | + version: latest |
| 45 | + args: --max-same-issues=100000 ./cmd/runner-manager/... ./internal/... |
| 46 | + working-directory: ${{ steps.modroot.outputs.root }} |
| 47 | + |
| 48 | + - name: Run tests |
| 49 | + if: steps.modroot.outputs.found == 'true' |
| 50 | + run: go test -v ./cmd/runner-manager/... ./internal/... |
| 51 | + working-directory: ${{ steps.modroot.outputs.root }} |
| 52 | + |
| 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 | + |
| 57 | + build: |
| 58 | + name: Build |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: [test] |
| 61 | + timeout-minutes: 15 |
| 62 | + steps: |
| 63 | + - name: Checkout code |
| 64 | + uses: actions/checkout@v6 |
| 65 | + |
| 66 | + - name: Detect Go module root |
| 67 | + id: modroot |
| 68 | + uses: ./.github/actions/detect-go-module-root |
| 69 | + with: |
| 70 | + working_dir: ${{ env.WORKING_DIR }} |
| 71 | + |
| 72 | + - name: Set up Go |
| 73 | + if: steps.modroot.outputs.found == 'true' |
| 74 | + uses: actions/setup-go@v6 |
| 75 | + with: |
| 76 | + go-version: ${{ env.GO_VERSION }} |
| 77 | + cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum |
| 78 | + |
| 79 | + - name: Get version information |
| 80 | + if: steps.modroot.outputs.found == 'true' |
| 81 | + id: version |
| 82 | + run: | |
| 83 | + VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)") |
| 84 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 85 | +
|
| 86 | + - name: Build Manager |
| 87 | + if: steps.modroot.outputs.found == 'true' |
| 88 | + run: | |
| 89 | + go build -ldflags "-s -w -X main.Version=${{ steps.version.outputs.version }}" -o runner-manager ./cmd/runner-manager |
| 90 | + working-directory: ${{ steps.modroot.outputs.root }} |
| 91 | + |
| 92 | + - name: Init example config |
| 93 | + if: steps.modroot.outputs.found == 'true' |
| 94 | + run: cp config.yaml.example config.yaml |
| 95 | + working-directory: ${{ steps.modroot.outputs.root }} |
| 96 | + |
| 97 | + - name: Verify binary |
| 98 | + if: steps.modroot.outputs.found == 'true' |
| 99 | + run: | |
| 100 | + ./runner-manager -version |
| 101 | + ./runner-manager -config config.yaml & |
| 102 | + PID=$! |
| 103 | + trap "kill $PID 2>/dev/null || true; wait $PID 2>/dev/null || true" EXIT |
| 104 | + for i in 1 2 3 4 5; do sleep 1; curl -sf http://localhost:8080/health | grep -q '"status":"ok"' && break; done |
| 105 | + curl -sf http://localhost:8080/health | grep -q '"status":"ok"' || (echo "health check failed"; exit 1) |
| 106 | + kill $PID 2>/dev/null || true |
| 107 | + wait $PID 2>/dev/null || true |
| 108 | + 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