boynux/squid-exporter

View on GitHub
.github/workflows/release.yml

Summary

Maintainability
Test Coverage
name: Makefile CI

on:
  push:
    tags:
      - "v*"
    branches:
      - "master"

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        arch: [386, amd64, arm64]
        include:
          - arch: arm
            armver: 6
          - arch: arm
            armver: 7
    env:
      arch_name: ${{ matrix.arch }}${{ matrix.arch == 'arm' && 'v' || '' }}${{ matrix.armver }}
    name: Build for ${{ matrix.arch }}${{ matrix.arch == 'arm' && 'v' || '' }}${{ matrix.armver }}

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Setup Go environment
      uses: actions/setup-go@v4
      with:
        # Path to the go.mod or go.work file.
        go-version-file: go.mod

    - name: Build ${{ env.arch_name }} binary
      run: make build
      env:
        GOARCH: ${{ matrix.arch }}
        GOARM: ${{ matrix.armver }}

    - name: Rename ${{ env.arch_name }} binary
      run: mv bin/squid-exporter bin/squid-exporter-linux-${{ env.arch_name }}

    - name: Upload binary
      uses: actions/upload-artifact@v3
      with:
        name: binary
        path: bin/*

  release:
    runs-on: ubuntu-latest

    steps:
      - name: Download binaries for release
        uses: actions/download-artifact@v3
        with:
          name: binary
          path: bin

      - name: Release latest version
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: bin/squid-exporter-*
          file_glob: true
          tag: unstable
          overwrite: true
          body: "pre-release"
          prerelease: true

      - name: Release tag version
        if: startsWith(github.ref, 'refs/tags/v') 
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: bin/squid-exporter-*
          file_glob: true
          tag: ${{ github.ref }}
          overwrite: true
          body: "Stable release"

    needs: [build]