50 lines
1.4 KiB
YAML
50 lines
1.4 KiB
YAML
name: Go Build and Release
|
||
|
||
#on:
|
||
# push:
|
||
# tags:
|
||
# - 'v*.*.*' # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
|
||
on:
|
||
push:
|
||
branches: [ "master" ]
|
||
pull_request:
|
||
branches: [ "master" ]
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu-latest
|
||
|
||
strategy:
|
||
matrix:
|
||
goos: [ linux, windows ] # 指定要构建的操作系统
|
||
goarch: [ amd64 ] # 指定架构
|
||
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Set up Go environment
|
||
uses: actions/setup-go@v4
|
||
with:
|
||
go-version: '1.22' # 选择 Go 版本
|
||
- name: install gcc
|
||
run: sudo apt-get install gcc-mingw-w64-x86-64
|
||
|
||
- name: tidy
|
||
run: go mod tidy
|
||
|
||
- name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
|
||
run: |
|
||
if [ "${{ matrix.goos }}" = "windows" ]; then
|
||
CC=x86_64-w64-mingw32-gcc GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=1 go build -o ./release/apimain.exe ./cmd/apimain.go
|
||
else
|
||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
||
fi
|
||
|
||
- name: Upload artifact
|
||
uses: actions/upload-artifact@v3
|
||
with:
|
||
name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
|
||
path: |
|
||
release/apimain
|
||
release/apimain.exe |