|
| 1 | +name: Instana Go Client CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint: |
| 12 | + name: Lint |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Go |
| 20 | + uses: actions/setup-go@v5 |
| 21 | + with: |
| 22 | + go-version: '1.23' |
| 23 | + |
| 24 | + - name: Run golangci-lint |
| 25 | + uses: golangci/golangci-lint-action@v8 |
| 26 | + with: |
| 27 | + version: v2.1.0 |
| 28 | + args: --timeout=5m |
| 29 | + |
| 30 | + - name: Check code formatting |
| 31 | + run: | |
| 32 | + if [ -n "$(gofmt -l .)" ]; then |
| 33 | + echo "❌ Code is not formatted" |
| 34 | + gofmt -l . |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + echo "✅ Code is properly formatted" |
| 38 | +
|
| 39 | + test: |
| 40 | + name: Test |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 45 | + go-version: ['1.23'] # Only test minimum required version from go.mod |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Go |
| 52 | + uses: actions/setup-go@v5 |
| 53 | + with: |
| 54 | + go-version: ${{ matrix.go-version }} |
| 55 | + |
| 56 | + - name: Cache Go modules |
| 57 | + uses: actions/cache@v4 |
| 58 | + with: |
| 59 | + path: | |
| 60 | + ~/go/pkg/mod |
| 61 | + ~/.cache/go-build |
| 62 | + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} |
| 63 | + restore-keys: | |
| 64 | + ${{ runner.os }}-go-${{ matrix.go-version }}- |
| 65 | + |
| 66 | + - name: Download dependencies |
| 67 | + run: go mod download |
| 68 | + |
| 69 | + - name: Verify dependencies |
| 70 | + run: go mod verify |
| 71 | + |
| 72 | + - name: Run tests |
| 73 | + shell: bash |
| 74 | + run: go test -v -race ./... |
| 75 | + |
| 76 | + build: |
| 77 | + name: Build |
| 78 | + runs-on: ubuntu-latest |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Set up Go |
| 85 | + uses: actions/setup-go@v5 |
| 86 | + with: |
| 87 | + go-version: '1.23' |
| 88 | + |
| 89 | + - name: Build |
| 90 | + run: go build -v ./... |
| 91 | + |
| 92 | + - name: Verify go.mod and go.sum |
| 93 | + run: | |
| 94 | + go mod tidy |
| 95 | + if [ -n "$(git diff go.mod go.sum)" ]; then |
| 96 | + echo "❌ go.mod or go.sum is not tidy" |
| 97 | + git diff go.mod go.sum |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + echo "✅ go.mod and go.sum are tidy" |
| 101 | +
|
| 102 | + coverage-report: |
| 103 | + name: Coverage Report |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: test |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout code |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Set up Go |
| 112 | + uses: actions/setup-go@v5 |
| 113 | + with: |
| 114 | + go-version: '1.23' |
| 115 | + |
| 116 | + - name: Generate coverage report |
| 117 | + shell: bash |
| 118 | + run: | |
| 119 | + go test -coverprofile=coverage.out -covermode=atomic ./... |
| 120 | + go tool cover -html=coverage.out -o coverage.html |
| 121 | + COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}') |
| 122 | + echo "Coverage: ${COVERAGE}" |
| 123 | + |
| 124 | + - name: Upload coverage report |
| 125 | + uses: actions/upload-artifact@v4 |
| 126 | + with: |
| 127 | + name: coverage-report |
| 128 | + path: ./coverage.html |
| 129 | + |
| 130 | + notify: |
| 131 | + name: Notify |
| 132 | + runs-on: ubuntu-latest |
| 133 | + needs: [lint, test, build, coverage-report] |
| 134 | + if: always() |
| 135 | + |
| 136 | + steps: |
| 137 | + - name: Check job status |
| 138 | + run: | |
| 139 | + if [ "${{ needs.lint.result }}" == "failure" ] || \ |
| 140 | + [ "${{ needs.test.result }}" == "failure" ] || \ |
| 141 | + [ "${{ needs.build.result }}" == "failure" ] || \ |
| 142 | + [ "${{ needs.coverage-report.result }}" == "failure" ]; then |
| 143 | + echo "❌ CI pipeline failed" |
| 144 | + echo "Lint: ${{ needs.lint.result }}" |
| 145 | + echo "Test: ${{ needs.test.result }}" |
| 146 | + echo "Build: ${{ needs.build.result }}" |
| 147 | + echo "Coverage: ${{ needs.coverage-report.result }}" |
| 148 | + exit 1 |
| 149 | + else |
| 150 | + echo "✅ CI pipeline passed" |
| 151 | + fi |
| 152 | +
|
| 153 | +
|
0 commit comments