-
Notifications
You must be signed in to change notification settings - Fork 39
77 lines (63 loc) · 2.35 KB
/
go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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