gh actions build

This commit is contained in:
DullJZ
2025-10-02 22:05:38 +08:00
parent f33f93e74d
commit 9cb5e2cf6e
3 changed files with 108 additions and 3 deletions

99
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,99 @@
name: Build and Publish
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-docker:
name: Build and Publish Docker Image
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Set VERSION
run: |
echo "VERSION=$(cat VERSION | tr -d '\n')" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
use: true
- name: Install QEMU for multi-platform builds
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: ./deploy/docker
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/s3-balance:latest
${{ secrets.DOCKER_USERNAME }}/s3-balance:${{ env.VERSION }}
build-binary:
name: Build and Release Binary
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Set VERSION
run: |
echo "VERSION=$(cat VERSION | tr -d '\n')" >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '^1.24'
- name: Build Binary
run: |
platforms=("linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64" "windows/amd64" "windows/arm64")
for platform in "${platforms[@]}"; do
IFS="/" read -r GOOS GOARCH <<< "$platform"
output_name="build/S3Balance_${GOOS}_${GOARCH}"
if [ "$GOOS" == "windows" ]; then
output_name+=".exe"
fi
GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name cmd/s3-balance/main.go
done
sudo apt-get update
sudo apt-get install -y upx
upx --best --lzma build/S3Balance_* || true
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
draft: false
prerelease: false
- name: Upload All Release Assets
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build
asset_name: ""
asset_content_type: application/octet-stream