Update go.yml #312
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
jobs: | |
build: | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
fail-fast: false | |
matrix: | |
go-version: ["1.20"] | |
include: | |
- { runner: macos-latest, goos: darwin, goarch: amd64, tags: netcgo } | |
- { runner: macos-latest, goos: darwin, goarch: arm64, tags: netcgo } | |
- { runner: ubuntu-latest, goos: linux, goarch: amd64, env: CGO_ENABLED=0 } | |
- { runner: ubuntu-latest, goos: linux, goarch: arm64, env: CGO_ENABLED=0 } | |
- { runner: windows-latest, goos: windows, goarch: amd64, env: CGO_ENABLED=1 } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Set up binary name | |
run: | | |
if [[ '${{matrix.goos}}' == 'windows' ]]; then | |
SUFFIX=.exe | |
fi | |
BINARY_NAME=${{github.repository}}-${{matrix.goos}}-${{matrix.goarch}}${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.goos}}' == 'windows' ]]; then | |
export CGO_ENABLED=1 | |
fi | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} 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: matrix.go-version == 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 |