mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-06-26 05:21:23 +08:00
187 lines
6.0 KiB
YAML
187 lines
6.0 KiB
YAML
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: Download frontend assets
|
|
run: |
|
|
echo "Downloading latest frontend build from s3-balance-web..."
|
|
LATEST_RELEASE=$(curl -s https://api.github.com/repos/DullJZ/s3-balance-web/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
|
echo "Latest frontend release: $LATEST_RELEASE"
|
|
|
|
curl -L -o dist.tar.gz "https://github.com/DullJZ/s3-balance-web/releases/download/$LATEST_RELEASE/dist.tar.gz"
|
|
|
|
mkdir -p internal/webui/dist
|
|
tar -xzf dist.tar.gz -C internal/webui/dist/
|
|
rm dist.tar.gz
|
|
|
|
echo "Frontend assets downloaded and extracted to internal/webui/dist"
|
|
ls -la internal/webui/dist/
|
|
|
|
- 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: Copy Dockerfile
|
|
run: |
|
|
cp deploy/docker/Dockerfile .
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
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: Download frontend assets
|
|
run: |
|
|
echo "Downloading latest frontend build from s3-balance-web..."
|
|
LATEST_RELEASE=$(curl -s https://api.github.com/repos/DullJZ/s3-balance-web/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
|
echo "Latest frontend release: $LATEST_RELEASE"
|
|
|
|
curl -L -o dist.tar.gz "https://github.com/DullJZ/s3-balance-web/releases/download/$LATEST_RELEASE/dist.tar.gz"
|
|
|
|
mkdir -p internal/webui/dist
|
|
tar -xzf dist.tar.gz -C internal/webui/dist/
|
|
rm dist.tar.gz
|
|
|
|
echo "Frontend assets downloaded and extracted to internal/webui/dist"
|
|
ls -la internal/webui/dist/
|
|
|
|
- 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
|
|
continue-on-error: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
tag_name: ${{ env.VERSION }}
|
|
release_name: Release ${{ env.VERSION }}
|
|
draft: false
|
|
prerelease: false
|
|
|
|
- name: Upload Linux AMD64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_linux_amd64
|
|
asset_name: S3Balance_linux_amd64
|
|
asset_content_type: application/octet-stream
|
|
|
|
- name: Upload Linux ARM64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_linux_arm64
|
|
asset_name: S3Balance_linux_arm64
|
|
asset_content_type: application/octet-stream
|
|
|
|
- name: Upload Darwin AMD64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_darwin_amd64
|
|
asset_name: S3Balance_darwin_amd64
|
|
asset_content_type: application/octet-stream
|
|
|
|
- name: Upload Darwin ARM64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_darwin_arm64
|
|
asset_name: S3Balance_darwin_arm64
|
|
asset_content_type: application/octet-stream
|
|
|
|
- name: Upload Windows AMD64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_windows_amd64.exe
|
|
asset_name: S3Balance_windows_amd64.exe
|
|
asset_content_type: application/octet-stream
|
|
|
|
- name: Upload Windows ARM64 Release Asset
|
|
uses: actions/upload-release-asset@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
asset_path: ./build/S3Balance_windows_arm64.exe
|
|
asset_name: S3Balance_windows_arm64.exe
|
|
asset_content_type: application/octet-stream
|