Skip to content

支持跨平台编译 #9

支持跨平台编译

支持跨平台编译 #9

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build-release:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- GOOS: linux
GOARCH: amd64
output_name: bestipTest_linux_amd64
- GOOS: windows
GOARCH: amd64
output_name: bestipTest.exe
- GOOS: darwin
GOARCH: amd64
output_name: bestipTest_darwin_amd64
- GOOS: darwin
GOARCH: arm64
output_name: bestipTest_darwin_arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Install dependencies
run: go mod tidy
- name: Build
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
run: go build -o ${{ matrix.output_name }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.output_name }}
path: ${{ matrix.output_name }}
if-no-files-found: error
create-release:
needs: build-release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Get tag description
id: tag_description
run: |
TAG_DESCRIPTION=$(git tag -l --format='%(contents)' ${{ github.ref_name }})
echo "tag_description=${TAG_DESCRIPTION}" >> $GITHUB_OUTPUT
shell: bash
- name: Get latest commit message
id: commit_message
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "commit_message=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
shell: bash
- name: List artifacts
run: ls -R ./artifacts
shell: bash
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ github.ref_name }} \
--title "${{ github.ref_name }} ${{ steps.tag_description.outputs.tag_description }}" \
--notes "Release for ${{ github.ref_name }}
Changes in this release:
${{ steps.commit_message.outputs.commit_message }}" \
--draft=false \
./artifacts/bestipTest_linux_amd64/bestipTest_linux_amd64 \
./artifacts/bestipTest.exe/bestipTest.exe \
./artifacts/bestipTest_darwin_amd64/bestipTest_darwin_amd64 \
./artifacts/bestipTest_darwin_arm64/bestipTest_darwin_arm64
shell: bash