add: ci action

This commit is contained in:
RookieCuzz
2025-10-08 10:31:37 +08:00
parent 81a8126d68
commit 80cfc45cb0

75
.github/workflows/server.yml vendored Normal file
View File

@@ -0,0 +1,75 @@
name: Server CI/CD
on:
push:
branches: [ "main", "master" ]
tags:
- '*'
pull_request:
branches: [ "main", "master" ]
jobs:
build:
name: Build server binaries
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, windows ]
goarch: [ amd64 ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.22.x'
cache: true
- name: Download modules
run: go mod download
- name: Vet & Test
run: |
go vet ./...
go test ./... -v
- name: Build cmd/server
shell: bash
run: |
mkdir -p build
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
OUT="server-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
echo "Building $OUT"
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
go build -trimpath -ldflags="-s -w" -o "build/${OUT}" ./cmd/server
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: server-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/server-${{ matrix.goos }}-${{ matrix.goarch }}*
release:
name: Release binaries
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: dist
- name: List artifacts
run: ls -R dist
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/**/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}