danstis/go-nitrado

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
name: Build Test Release

on:
  push:
    branches:
      - master
      - beta
      - "feature/*"
      - "fix/*"
  pull_request:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.x
        uses: actions/setup-go@v3.2.0
        with:
          go-version: ^1.19
        id: go

      - name: Check out code
        uses: actions/checkout@v3.1.0
        with:
          fetch-depth: 0

      - name: Build windows x64
        run: go build -v ./nitrado/
        env:
          GOOS: windows
          GOARCH: amd64

      - name: Build linux x86
        run: go build -v ./nitrado/
        env:
          GOOS: linux
          GOARCH: 386

  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.x
        uses: actions/setup-go@v3.2.0
        with:
          go-version: ^1.19
        id: go

      - name: Check out code
        uses: actions/checkout@v3.1.0
        with:
          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

      - name: Test
        run: go test -v -race -coverprofile=cover.out -json ./nitrado/ > test-report.out

      - name: Go Vet
        run: go vet ./nitrado/

      - name: Install deepsource CLI
        if: ${{ github.actor != 'dependabot[bot]' }}
        run: curl https://deepsource.io/cli | sh

      - name: Upload Coverage data to deepsource
        if: ${{ github.actor != 'dependabot[bot]' }}
        run: ./bin/deepsource report --analyzer test-coverage --key go --value-file ./cover.out
        env:
          DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}

      - name: Upload coverage to Codecov
        if: ${{ github.actor != 'dependabot[bot]' }}
        uses: codecov/codecov-action@v3.1.1
        with:
          file: ./cover.out
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: Install GitVersion
        uses: gittools/actions/gitversion/setup@v0.9.13
        with:
          versionSpec: "5.x"
      - name: Version with GitVersion # https://github.com/marketplace/actions/use-actions
        id: gitversion
        uses: gittools/actions/gitversion/execute@v0.9.13

      - name: SonarCloud Scan
        if: ${{ github.actor != 'dependabot[bot]' }}
        uses: SonarSource/sonarcloud-github-action@master # https://github.com/marketplace/actions/sonarcloud-scan
        with:
          args: >
            -Dsonar.projectVersion=${{ steps.gitversion.outputs.FullSemVer }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.x
        uses: actions/setup-go@v3.2.0
        with:
          go-version: ^1.19
        id: go

      - name: Check out code
        uses: actions/checkout@v3.1.0

      - name: Run golangci-lint # https://github.com/marketplace/actions/run-golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.50

  tag:
    name: Tag and Release
    runs-on: ubuntu-latest
    needs: [build, test, lint]
    if: github.ref == 'refs/heads/master'
    steps:
      - name: Check out code
        uses: actions/checkout@v3.1.0
        with:
          fetch-depth: 0

      - name: Set up Go 1.x
        uses: actions/setup-go@v3.2.0
        with:
          go-version: ^1.19
        id: go

      - name: Install GitVersion
        uses: gittools/actions/gitversion/setup@v0.9.13
        with:
          versionSpec: "5.5.x"
      - name: Version with GitVersion # https://github.com/marketplace/actions/use-actions
        id: gitversion
        uses: gittools/actions/gitversion/execute@v0.9.13

      - name: Bump version and push tag
        id: tag_version
        uses: mathieudutour/github-tag-action@v6.0
        if: ${{ steps.gitversion.outputs.PreReleaseTagWithDash == '' }}
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          custom_tag: ${{ steps.gitversion.outputs.FullSemVer }}
          release_branches: master
          tag_prefix: v

      - name: Check out code
        uses: actions/checkout@v3.1.0
        if: ${{ steps.gitversion.outputs.PreReleaseTagWithDash == '' }}
        with:
          fetch-depth: 0

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v3
        if: ${{ steps.gitversion.outputs.PreReleaseTagWithDash == '' }}
        with:
          version: latest
          args: release --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}