Merge pull request #3 from NGRsoftlab/feat/prometheus-metrics #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ['1.21', '1.22'] | |
| steps: | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-${{ matrix.go-version }}- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Generate coverage report | |
| run: go tool cover -html=coverage.out -o coverage.html | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report-go${{ matrix.go-version }} | |
| path: | | |
| coverage.out | |
| coverage.html | |
| - name: Check coverage threshold | |
| run: | | |
| go tool cover -func=coverage.out | awk '/total:/ { | |
| gsub(/%/,"",$3); | |
| if ($3 + 0 < 80.0) { | |
| print "Coverage", $3"% is below threshold 80%"; | |
| exit 1 | |
| } else { | |
| print "Coverage:", $3"%" | |
| } | |
| }' | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-lint-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-lint- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run golangci-lint | |
| uses: golangci/golangci-lint-action@v4 | |
| with: | |
| version: latest | |
| args: --timeout=5m --config=.golangci.yaml --out-format=github-actions | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: [test, lint] | |
| steps: | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Create build directory | |
| run: mkdir -p build | |
| - name: Build for multiple platforms | |
| run: | | |
| GOOS=linux GOARCH=amd64 go build -o build/pulsar-linux-amd64 ./cmd | |
| GOOS=windows GOARCH=amd64 go build -o build/pulsar-windows-amd64.exe ./cmd | |
| GOOS=darwin GOARCH=amd64 go build -o build/pulsar-darwin-amd64 ./cmd | |
| GOOS=darwin GOARCH=arm64 go build -o build/pulsar-darwin-arm64 ./cmd | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries | |
| path: build/ | |
| compression-level: 6 | |
| retention-days: 30 | |
| container: | |
| name: Container | |
| runs-on: ubuntu-latest | |
| needs: [test, lint] | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| tags: pulsar:ci | |
| load: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Verify image metadata | |
| run: | | |
| echo "Checking ENTRYPOINT and USER..." | |
| docker inspect pulsar:ci --format='ENTRYPOINT: {{.Config.Entrypoint}} | CMD: {{.Config.Cmd}} | USER: {{.Config.User}}' | |
| entrypoint=$(docker inspect pulsar:ci --format='{{json .Config.Entrypoint}}') | |
| cmd=$(docker inspect pulsar:ci --format='{{json .Config.Cmd}}') | |
| if [[ "$entrypoint" != '["/app/pulsar"]' ]]; then | |
| echo "Invalid ENTRYPOINT" | |
| exit 1 | |
| fi | |
| if [[ "$cmd" != 'null' && "$cmd" != '[]' ]]; then | |
| echo "Unexpected CMD (should be empty): $cmd" | |
| exit 1 | |
| fi | |
| - name: Smoke test — help output | |
| run: | | |
| echo "Running pulsar --help..." | |
| docker run --rm pulsar:ci --help | |
| - name: Check image size (< 50 MB) | |
| run: | | |
| size_kb=$(docker images pulsar:ci --format='{{.Size}}' | sed 's/[A-Za-z]//g') | |
| size_mb=$((size_kb / 1024)) | |
| echo "Image size: ${size_mb} MB" | |
| if [ $size_mb -gt 50 ]; then | |
| echo "Image too large (>50 MB)" | |
| exit 1 | |
| fi | |