Skip to content

Merge pull request #22 from XxxXTeam/dependabot/go_modules/go_modules… #95

Merge pull request #22 from XxxXTeam/dependabot/go_modules/go_modules…

Merge pull request #22 from XxxXTeam/dependabot/go_modules/go_modules… #95

Workflow file for this run

name: Build and Release
on:
push:
branches: [main, master]
tags:
- 'v*'
pull_request:
branches: [main, master]
workflow_dispatch:
env:
GO_VERSION: '1.23'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
exclude:
- goos: windows
goarch: arm64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Get version
id: version
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ steps.version.outputs.VERSION }}
GOTOOLCHAIN: auto
run: |
EXT=""
if [ "$GOOS" = "windows" ]; then
EXT=".exe"
fi
CGO_ENABLED=0 go build \
-tags "with_quic,with_utls" \
-ldflags="-s -w -X main.Version=${VERSION}" \
-o business2api-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} .
- name: Prepare package
run: |
mkdir -p dist
mv business2api-* dist/
cp config/config.json.example dist/
cp README.md dist/
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: business2api-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*
retention-days: 30
docker:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release files
run: |
mkdir -p release
for dir in artifacts/business2api-*/; do
# 获取平台名称
platform=$(basename "$dir")
# 创建临时目录
mkdir -p "tmp/$platform"
cp "$dir"/* "tmp/$platform/"
# 设置可执行权限
for f in "tmp/$platform"/business2api-*; do
if [[ ! "$f" == *.exe ]]; then
chmod +x "$f"
fi
done
# 打包
tar -czvf "release/${platform}.tar.gz" -C tmp "$platform"
rm -rf "tmp/$platform"
done
rm -rf tmp
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: release/*
generate_release_notes: true