Skip to content

Update go.yml

Update go.yml #315

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: write
packages: write
env:
GOVERSION: "1.20"
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- { runner: macos-latest, go-os: darwin, go-arch: amd64, tags: netcgo }
- { runner: macos-latest, go-os: darwin, go-arch: arm64, tags: netcgo }
- { runner: ubuntu-latest, go-os: linux, go-arch: amd64, env: CGO_ENABLED=0 }
- { runner: ubuntu-latest, go-os: linux, go-arch: arm64, env: CGO_ENABLED=0 }
- { runner: windows-latest, go-os: windows, go-arch: amd64, env: CGO_ENABLED=0 }
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Set up Go ${{env.GOVERSION}}
uses: actions/setup-go@v3
with:
go-version: ${{env.GOVERSION}}
- name: Set up binary name
run: |
if [[ '${{matrix.go-os}}' == 'windows' ]]; then
SUFFIX=.exe
fi
BINARY_NAME=${{github.repository}}-${{matrix.go-os}}-${{matrix.go-arch}}${SUFFIX}
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV
- name: Install goimports
run: |
go install golang.org/x/tools/cmd/goimports@latest
export PATH="$HOME/go/bin:$PATH"
- name: Build
working-directory: ./src
run: |
if [[ '${{matrix.go-os}}' == 'windows' ]]; then
export CGO_ENABLED=1
fi
GOOS=${{ matrix.go-os }} GOARCH=${{ matrix.go-arch }} go build -o "$BINARY_NAME" -v ./...
- name: Test
working-directory: ./src
run: go test -v ./...
- name: Format
run: if [ "$(goimports -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
if: ${{env.GOVERSION == 1.20}}
- name: Release Notes
run:
git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:* %h %s%n * %an <%ae>' --no-merges >> ".github/RELEASE-TEMPLATE.md"
- name: Release with Notes
uses: softprops/action-gh-release@v2
with:
body_path: ".github/RELEASE-TEMPLATE.md"
files: ./src/${{env.BINARY_NAME}}
tag_name: latest