Update build.yml

This commit is contained in:
BlueSkyXN
2025-02-20 10:06:25 +08:00
committed by GitHub
parent 629123a9ac
commit 5ab2b47497
+106 -90
View File
@@ -8,103 +8,119 @@ on:
workflow_dispatch: # 支持手动触发
jobs:
build:
name: Build
setup:
name: Setup Build Environment
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set version
id: set-version
run: |
echo "version=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
build:
name: Build for ${{ matrix.os }}-${{ matrix.arch }}
needs: setup
runs-on: ubuntu-latest
strategy:
fail-fast: false # 允许部分失败不影响其他构建
matrix:
include:
- os: windows
arch: amd64
ext: .exe
goos: windows
goarch: amd64
- os: windows
arch: 386
ext: .exe
goos: windows
goarch: 386
- os: linux
arch: amd64
ext: ""
goos: linux
goarch: amd64
- os: linux
arch: 386
ext: ""
goos: linux
goarch: 386
- os: linux
arch: arm64
ext: ""
goos: linux
goarch: arm64
- os: darwin
arch: amd64
ext: ""
goos: darwin
goarch: amd64
- os: darwin
arch: arm64
ext: ""
goos: darwin
goarch: arm64
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
check-latest: true
cache: true
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
check-latest: true
cache: true
- name: Get dependencies
run: |
go mod init github.com/BlueSkyXN/DeepAI
go mod tidy
- name: Get dependencies
run: |
go mod init github.com/BlueSkyXN/DeepAI
go mod tidy
- name: Build for Windows
run: |
GOOS=windows GOARCH=amd64 go build -o DeepAI-windows-amd64.exe
GOOS=windows GOARCH=386 go build -o DeepAI-windows-386.exe
- name: Build for ${{ matrix.os }}-${{ matrix.arch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ needs.setup.outputs.version }}
run: |
BINARY_NAME="DeepAI-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}"
go build -ldflags "-X main.Version=$VERSION" -o "$BINARY_NAME"
if [ "${{ matrix.os }}" != "windows" ]; then
chmod +x "$BINARY_NAME"
fi
- name: Build for Linux
run: |
GOOS=linux GOARCH=amd64 go build -o DeepAI-linux-amd64
GOOS=linux GOARCH=386 go build -o DeepAI-linux-386
GOOS=linux GOARCH=arm64 go build -o DeepAI-linux-arm64
chmod +x DeepAI-linux-*
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-${{ matrix.os }}-${{ matrix.arch }}-${{ needs.setup.outputs.version }}
path: DeepAI-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
retention-days: 90
- name: Build for macOS
run: |
GOOS=darwin GOARCH=amd64 go build -o DeepAI-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -o DeepAI-darwin-arm64
chmod +x DeepAI-darwin-*
package-all:
name: Package All Artifacts
needs: [setup, build]
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: binaries
pattern: DeepAI-*-${{ needs.setup.outputs.version }}
merge-multiple: true
- name: Upload All Binaries as Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-binaries-all
path: |
DeepAI-windows-amd64.exe
DeepAI-windows-386.exe
DeepAI-linux-amd64
DeepAI-linux-386
DeepAI-linux-arm64
DeepAI-darwin-amd64
DeepAI-darwin-arm64
retention-days: 90 # 保留90天
- name: Create Release Package
run: |
cd binaries
zip -r ../DeepAI-all-platforms-${{ needs.setup.outputs.version }}.zip .
- name: Upload Windows amd64 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-windows-amd64
path: DeepAI-windows-amd64.exe
retention-days: 90
- name: Upload Windows 386 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-windows-386
path: DeepAI-windows-386.exe
retention-days: 90
- name: Upload Linux amd64 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-linux-amd64
path: DeepAI-linux-amd64
retention-days: 90
- name: Upload Linux 386 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-linux-386
path: DeepAI-linux-386
retention-days: 90
- name: Upload Linux arm64 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-linux-arm64
path: DeepAI-linux-arm64
retention-days: 90
- name: Upload macOS amd64 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-darwin-amd64
path: DeepAI-darwin-amd64
retention-days: 90
- name: Upload macOS arm64 Artifact
uses: actions/upload-artifact@v4
with:
name: DeepAI-darwin-arm64
path: DeepAI-darwin-arm64
retention-days: 90
- name: Upload Combined Package
uses: actions/upload-artifact@v4
with:
name: DeepAI-all-platforms-${{ needs.setup.outputs.version }}
path: DeepAI-all-platforms-${{ needs.setup.outputs.version }}.zip
retention-days: 90