Skip to content

Dev

Dev #121

Workflow file for this run

name: Lint, Test and Build
permissions:
contents: read
on:
push:
branches: [main, dev]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
fmt-vet:
name: Format and Vet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Check formatting
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "The following files need formatting:"
gofmt -s -l .
exit 1
fi
- name: Run go vet
run: go vet ./...
test:
name: Run Tests
runs-on: ubuntu-latest
needs: [fmt-vet]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Download dependencies
run: go mod download
- name: Run unit tests
env:
MUSIC_DIR: /tmp/test-music
GIN_MODE: release
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Generate coverage report
run: go tool cover -func=coverage.out
lint:
runs-on: ubuntu-latest
needs: [fmt-vet]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
build:
runs-on: ubuntu-latest
needs: [test, lint]
strategy:
matrix:
goos: [linux]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Get Go version
id: go-version
run: echo "version=$(go version | awk '{print $3}' | sed 's/go//')" >> $GITHUB_OUTPUT
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ steps.go-version.outputs.version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ steps.go-version.outputs.version }}-
- name: Build binary
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags "-X main.BuildTime=$(date --utc +%Y-%m-%dT%H:%M:%SZ) -X main.CommitHash=${{ github.sha }} -X main.Version=${{ github.ref_name }}" \
-tags netgo -trimpath \
-o go-music-${{ matrix.goos }}-${{ matrix.goarch }} main.go