martin-helmich/prometheus-nginxlog-exporter

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
name: Compile & Test

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  build:
    name: Compile binary
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.18.x

      - name: Compile
        run: CGO_ENABLED=0 go build -a -installsuffix cgo -o prometheus-nginxlog-exporter .

      - name: Upload build artifact
        uses: actions/upload-artifact@v3
        with:
          name: build
          path: prometheus-nginxlog-exporter

  tests_unit:
    name: Run unit tests
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.18.x

      - name: Run unit tests
        run: go test ./...
  
  test_acceptance:
    name: Run acceptance tests
    needs: build
    runs-on: ubuntu-latest

    steps:
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.7"

      - name: Install Behave
        run: pip install behave requests

      - uses: actions/checkout@v4

      - name: Download build artifact
        uses: actions/download-artifact@v3
        with:
          name: build
          path: build

      - name: Link built file to cwd
        run: |
          cp build/prometheus-nginxlog-exporter .
          chmod +x ./prometheus-nginxlog-exporter
      
      - name: Run acceptance tests
        run: behave

  test_release:
    name: Test release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        
      - name: Unshallow
        run: git fetch --prune --unshallow

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.18.x

      - name: Validate Goreleaser config
        uses: goreleaser/goreleaser-action@v5
        with:
          version: v1.11.5
          args: check

      - name: Set current date
        id: set_date
        run: |
          echo "BUILD_DATE=$(date)" >> $GITHUB_ENV

      - name: Generate temporary dummy key for signing
        run: |
          sudo apt-get update
          sudo apt-get install -y gnupg
          export GNUPGHOME=/tmp
          gpg --batch --gen-key <<EOF
          %no-protection
          Key-Type: default
          Key-Length: 2048
          Subkey-Type: default
          Subkey-Length: 2048
          Name-Real: Github Action
          Name-Email: helmich-bot@helmich.example
          Expire-Date: seconds=120
          EOF
          gpg --export-secret-key --armor helmich-bot@helmich.example > /tmp/signing-key

      - name: Build Goreleaser snapshot release
        uses: goreleaser/goreleaser-action@v5
        with:
          version: v1.11.5
          args: release --rm-dist --skip-publish --snapshot
        env:
          BUILD_USER: ${{ github.actor }} (via Github Actions)