mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-12-24 12:37:53 +08:00
refactor: merge workflows, add VERSION file, prevent .build commits
- Create VERSION file (0.0.1) for centralized version management - Merge build-ui.yml and build-all.yml into single build.yml - Fix Fyne CLI path to fyne.io/tools/cmd/fyne@latest - Fix --app-version flag usage (was -appVersion) - Upload artifacts to latest GitHub release instead of committing to repo - Add .build/ to .gitignore to prevent large APK files from being committed - Keep Android build logic unchanged (working correctly) - Fix desktop platform builds with proper version handling
This commit is contained in:
342
.github/workflows/build.yml
vendored
Normal file
342
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
name: Build All Platforms
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'android-app'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
name: Prepare Version
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.VERSION }}
|
||||
app_version: ${{ steps.version.outputs.APP_VERSION }}
|
||||
is_release: ${{ steps.version.outputs.IS_RELEASE }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get version info
|
||||
id: version
|
||||
run: |
|
||||
BASE_VERSION=$(cat VERSION)
|
||||
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
APP_VERSION=${VERSION#v}
|
||||
IS_RELEASE="true"
|
||||
else
|
||||
APP_VERSION="$BASE_VERSION"
|
||||
VERSION=v${BASE_VERSION}-$(date +%Y%m%d)-$(git rev-parse --short HEAD)
|
||||
IS_RELEASE="false"
|
||||
fi
|
||||
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "IS_RELEASE=$IS_RELEASE" >> $GITHUB_OUTPUT
|
||||
echo "Building version: $VERSION"
|
||||
echo "App version: $APP_VERSION"
|
||||
|
||||
build-android:
|
||||
name: Build Android APK
|
||||
needs: prepare
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23.x'
|
||||
cache: true
|
||||
|
||||
- name: Install Fyne CLI
|
||||
run: |
|
||||
go install fyne.io/tools/cmd/fyne@latest
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
- name: Install Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
|
||||
- name: Install Android NDK
|
||||
run: |
|
||||
sdkmanager --install "ndk;25.2.9519653"
|
||||
echo "ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/25.2.9519653" >> $GITHUB_ENV
|
||||
|
||||
- name: Install Android Build Tools
|
||||
run: |
|
||||
sdkmanager --install "build-tools;33.0.2"
|
||||
sdkmanager --install "platforms;android-33"
|
||||
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Configure Git for Private Modules
|
||||
run: |
|
||||
git config --global url."https://${{ secrets.GHT }}@github.com/".insteadOf "https://github.com/"
|
||||
git config --global url."git@github.com:".insteadOf "https://github.com/"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GHT }}
|
||||
|
||||
- name: Download dependencies
|
||||
run: go mod download
|
||||
env:
|
||||
GOPRIVATE: github.com/oneclickvirt/security
|
||||
|
||||
- name: Verify dependencies
|
||||
run: go mod verify
|
||||
|
||||
- name: Update FyneApp.toml version
|
||||
run: |
|
||||
sed -i "s/Version = .*/Version = \"${{ needs.prepare.outputs.version }}\"/" FyneApp.toml
|
||||
cat FyneApp.toml
|
||||
|
||||
- name: Build Android APK (arm64)
|
||||
env:
|
||||
ANDROID_NDK_HOME: ${{ env.ANDROID_NDK_HOME }}
|
||||
GOPRIVATE: github.com/oneclickvirt/security
|
||||
run: |
|
||||
fyne package --os android --app-id com.oneclickvirt.goecs --app-version "${{ needs.prepare.outputs.app_version }}"
|
||||
if [ -f *.apk ]; then
|
||||
mkdir -p .build
|
||||
mv *.apk .build/goecs-android-arm64-${{ needs.prepare.outputs.version }}.apk
|
||||
echo "ARM64 APK 构建成功"
|
||||
else
|
||||
echo "ARM64 APK 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build Android APK (x86_64)
|
||||
env:
|
||||
ANDROID_NDK_HOME: ${{ env.ANDROID_NDK_HOME }}
|
||||
GOPRIVATE: github.com/oneclickvirt/security
|
||||
run: |
|
||||
fyne package --os android/amd64 --app-id com.oneclickvirt.goecs --app-version "${{ needs.prepare.outputs.app_version }}"
|
||||
if [ -f *.apk ]; then
|
||||
mv *.apk .build/goecs-android-x86_64-${{ needs.prepare.outputs.version }}.apk
|
||||
echo "x86_64 APK 构建成功"
|
||||
else
|
||||
echo "x86_64 APK 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: List build artifacts
|
||||
run: |
|
||||
ls -lh .build/
|
||||
du -sh .build/*.apk
|
||||
|
||||
- name: Upload ARM64 APK
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: goecs-android-arm64-${{ needs.prepare.outputs.version }}
|
||||
path: .build/goecs-android-arm64-${{ needs.prepare.outputs.version }}.apk
|
||||
retention-days: 90
|
||||
|
||||
- name: Upload x86_64 APK
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: goecs-android-x86_64-${{ needs.prepare.outputs.version }}
|
||||
path: .build/goecs-android-x86_64-${{ needs.prepare.outputs.version }}.apk
|
||||
retention-days: 90
|
||||
|
||||
build-desktop:
|
||||
name: Build Desktop Apps
|
||||
needs: prepare
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
# macOS builds
|
||||
- os: macos-latest
|
||||
platform: darwin
|
||||
arch: arm64
|
||||
name: macos-arm64
|
||||
- os: macos-latest
|
||||
platform: darwin
|
||||
arch: amd64
|
||||
name: macos-amd64
|
||||
|
||||
# Windows builds
|
||||
- os: windows-latest
|
||||
platform: windows
|
||||
arch: arm64
|
||||
name: windows-arm64
|
||||
- os: windows-latest
|
||||
platform: windows
|
||||
arch: amd64
|
||||
name: windows-amd64
|
||||
|
||||
# Linux builds
|
||||
- os: ubuntu-latest
|
||||
platform: linux
|
||||
arch: arm64
|
||||
name: linux-arm64
|
||||
- os: ubuntu-latest
|
||||
platform: linux
|
||||
arch: amd64
|
||||
name: linux-amd64
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23.x'
|
||||
cache: true
|
||||
|
||||
- name: Install Fyne CLI
|
||||
run: go install fyne.io/tools/cmd/fyne@latest
|
||||
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Configure Git for Private Modules
|
||||
run: |
|
||||
git config --global url."https://${{ secrets.GHT }}@github.com/".insteadOf "https://github.com/"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GHT }}
|
||||
|
||||
- name: Download dependencies
|
||||
run: go mod download
|
||||
env:
|
||||
GOPRIVATE: github.com/oneclickvirt/security
|
||||
|
||||
- name: Verify dependencies
|
||||
run: go mod verify
|
||||
|
||||
- name: Update FyneApp.toml version
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ runner.os }}" == "macOS" ]; then
|
||||
sed -i '' "s/Version = .*/Version = \"${{ needs.prepare.outputs.version }}\"/" FyneApp.toml
|
||||
else
|
||||
sed -i "s/Version = .*/Version = \"${{ needs.prepare.outputs.version }}\"/" FyneApp.toml
|
||||
fi
|
||||
cat FyneApp.toml
|
||||
|
||||
- name: Build for ${{ matrix.name }}
|
||||
env:
|
||||
GOPRIVATE: github.com/oneclickvirt/security
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p .build
|
||||
|
||||
# Build the package
|
||||
fyne package -os ${{ matrix.platform }}/${{ matrix.arch }} -name goecs --app-version "${{ needs.prepare.outputs.app_version }}"
|
||||
|
||||
# Package the output
|
||||
if [ "${{ matrix.platform }}" == "darwin" ]; then
|
||||
if [ -d goecs.app ]; then
|
||||
tar -czf .build/goecs-${{ matrix.name }}-${{ needs.prepare.outputs.version }}.tar.gz goecs.app
|
||||
echo "macOS app 构建成功"
|
||||
else
|
||||
echo "macOS app 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "${{ matrix.platform }}" == "windows" ]; then
|
||||
if [ -f goecs.exe ]; then
|
||||
mv goecs.exe .build/goecs-${{ matrix.name }}-${{ needs.prepare.outputs.version }}.exe
|
||||
echo "Windows exe 构建成功"
|
||||
else
|
||||
echo "Windows exe 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "${{ matrix.platform }}" == "linux" ]; then
|
||||
if [ -f goecs ]; then
|
||||
tar -czf .build/goecs-${{ matrix.name }}-${{ needs.prepare.outputs.version }}.tar.gz goecs
|
||||
echo "Linux binary 构建成功"
|
||||
else
|
||||
echo "Linux binary 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: List build artifacts
|
||||
shell: bash
|
||||
run: |
|
||||
ls -lh .build/
|
||||
du -sh .build/*
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: goecs-${{ matrix.name }}-${{ needs.prepare.outputs.version }}
|
||||
path: .build/*
|
||||
retention-days: 90
|
||||
|
||||
upload-to-release:
|
||||
name: Upload to Latest Release
|
||||
needs: [prepare, build-android, build-desktop]
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/android-app'
|
||||
|
||||
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: Display structure of downloaded files
|
||||
run: ls -R artifacts/
|
||||
|
||||
- name: Get latest release
|
||||
id: get_release
|
||||
run: |
|
||||
LATEST_RELEASE=$(gh release list --limit 1 --json tagName,url --jq '.[0]')
|
||||
if [ -z "$LATEST_RELEASE" ]; then
|
||||
echo "No existing release found, creating a new one"
|
||||
gh release create "${{ needs.prepare.outputs.version }}" \
|
||||
--title "Release ${{ needs.prepare.outputs.version }}" \
|
||||
--notes "Automated build from ${{ github.sha }}"
|
||||
RELEASE_TAG="${{ needs.prepare.outputs.version }}"
|
||||
else
|
||||
RELEASE_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tagName')
|
||||
echo "Found existing release: $RELEASE_TAG"
|
||||
fi
|
||||
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Upload artifacts to release
|
||||
run: |
|
||||
cd artifacts
|
||||
for dir in */; do
|
||||
cd "$dir"
|
||||
for file in *; do
|
||||
if [ -f "$file" ]; then
|
||||
echo "Uploading $file to release ${{ steps.get_release.outputs.RELEASE_TAG }}"
|
||||
gh release upload "${{ steps.get_release.outputs.RELEASE_TAG }}" "$file" --clobber
|
||||
fi
|
||||
done
|
||||
cd ..
|
||||
done
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
Reference in New Issue
Block a user