From cc33199e4060b8ce4fa5d714c6c04d16940d8f83 Mon Sep 17 00:00:00 2001 From: shiquda Date: Sun, 1 Dec 2024 15:08:08 +0800 Subject: [PATCH] fix(CI): build and release --- .github/workflows/build.yml | 160 +++++++++++++++++++++++++++--------- 1 file changed, 121 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef09a2a..bcc44db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,98 +4,180 @@ on: push: tags: - "v*.*.*" # trigger when tag is vX.X.X + workflow_dispatch: + inputs: + tag: + description: "Tag to build and release" + required: true + default: "v0.0.0" jobs: build: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + build-platform: linux/amd64 + build-name: crypto-monitor + - os: macos-latest + build-platform: darwin/universal + build-name: crypto-monitor + - os: windows-latest + build-platform: windows/amd64 + installer-name: crypto-monitor-installer.exe + executable-name: crypto-monitor-windows-amd64.exe + steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Go + - name: Setup GoLang uses: actions/setup-go@v4 with: go-version: "1.21" - - name: Set up Node.js + - name: Setup NodeJS uses: actions/setup-node@v3 with: node-version: "18" - - name: Install dependencies + - name: Install Linux Wails deps + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu + + - name: Install Wails + run: go install github.com/wailsapp/wails/v2/cmd/wails@latest + + - name: Install Go Dependencies + run: go mod tidy + + - name: Install frontend dependencies run: | cd frontend npm install - - name: Build frontend + # https://wails.io/docs/reference/cli/#build + - name: Build Wails App (Non-Windows) + if: runner.os != 'Windows' run: | - cd frontend - npm run build + wails build --platform ${{ matrix.build-platform }} -o ${{ matrix.build-name }} + working-directory: ./ - - name: Install Wails + - name: Build Windows Installer + if: runner.os == 'Windows' run: | - go install github.com/wailsapp/wails/v2/cmd/wails@latest - env: - GOPATH: ${{ github.workspace }}/go + wails build --platform ${{ matrix.build-platform }} -nsis -o ${{ matrix.installer-name }} - - name: Build Wails App + - name: Build Windows Executable + if: runner.os == 'Windows' run: | - wails build -m release - env: - GOOS: ${{ matrix.os == 'windows-latest' && 'windows' || matrix.os == 'darwin-latest' && 'darwin' || 'linux' }} - GOARCH: "amd64" + wails build --platform ${{ matrix.build-platform }} -o ${{ matrix.executable-name }} - - name: Upload Build Artifact + - name: Package macOS .app + if: runner.os == 'macOS' + run: | + cd build/bin + zip -r "${{ matrix.build-name }}.zip" "${{ matrix.build-name }}.app" + + - name: Upload Linux Build Artifact + if: runner.os == 'linux' + uses: actions/upload-artifact@v3 + with: + name: crypto-monitor-${{ matrix.os }} + path: ./build/bin/${{ matrix.build-name }} + + - name: Upload macOS Build Artifact + if: runner.os == 'macOS' uses: actions/upload-artifact@v3 with: name: crypto-monitor-${{ matrix.os }} - path: build/bin/crypto-monitor.${{ matrix.os == 'windows-latest' && 'exe' || matrix.os == 'darwin' && 'app' || 'linux' }} + path: ./build/bin/${{ matrix.build-name }}.zip + + - name: Upload Windows Installer Artifact + if: runner.os == 'Windows' + uses: actions/upload-artifact@v3 + with: + name: crypto-monitor-windows-installer + path: ./build/bin/${{ matrix.installer-name }} + + - name: Upload Windows Executable Artifact + if: runner.os == 'Windows' + uses: actions/upload-artifact@v3 + with: + name: crypto-monitor-windows-executable + path: ./build/bin/${{ matrix.executable-name }} release: - needs: build runs-on: ubuntu-latest + needs: build + if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' + steps: - - name: Download artifacts + - name: Download Non-Windows Ubuntu Artifact uses: actions/download-artifact@v3 with: name: crypto-monitor-ubuntu-latest - path: ./build + path: ./artifacts/ubuntu-latest - - name: Download macOS artifact + - name: Download Non-Windows macOS Artifact uses: actions/download-artifact@v3 with: name: crypto-monitor-macos-latest - path: ./build/macos + path: ./artifacts/macos-latest - - name: Download Windows artifact + - name: Download Windows Installer Artifact uses: actions/download-artifact@v3 with: - name: crypto-monitor-windows-latest - path: ./build/windows + name: crypto-monitor-windows-installer + path: ./artifacts/windows-installer - - name: Create GitHub Release + - name: Download Windows Executable Artifact + uses: actions/download-artifact@v3 + with: + name: crypto-monitor-windows-executable + path: ./artifacts/windows-executable + + - name: Get Version + id: get_version + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "ref_name=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + else + ref_name=${GITHUB_REF/refs\/tags\//} # This strips the refs/tags/ prefix + echo "ref_name=${ref_name}" >> $GITHUB_ENV + fi + + - name: Create Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} draft: false prerelease: false - - name: Upload Windows Release Asset + - name: Upload Windows Installer Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./artifacts/windows-installer/crypto-monitor-installer.exe + asset_name: crypto-monitor-${{ github.ref_name }}-windows-amd64-installer.exe + asset_content_type: application/vnd.microsoft.portable-executable + + - name: Upload Windows Executable 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/windows/crypto-monitor.exe - asset_name: crypto-monitor-windows.exe - asset_content_type: application/vnd.microsoft.package + asset_path: ./artifacts/windows-executable/crypto-monitor-windows-amd64.exe + asset_name: crypto-monitor-${{ github.ref_name }}-windows-amd64.exe + asset_content_type: application/vnd.microsoft.portable-executable - name: Upload macOS Release Asset uses: actions/upload-release-asset@v1 @@ -103,9 +185,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/macos/crypto-monitor.app - asset_name: crypto-monitor-macos.app - asset_content_type: application/x-apple-app + asset_path: ./artifacts/macos-latest/crypto-monitor.zip + asset_name: crypto-monitor-${{ github.ref_name }}-macos-universal.zip + asset_content_type: application/zip - name: Upload Linux Release Asset uses: actions/upload-release-asset@v1 @@ -113,6 +195,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/ubuntu-latest/crypto-monitor - asset_name: crypto-monitor-linux - asset_content_type: application/octet-stream + asset_path: ./artifacts/ubuntu-latest/crypto-monitor + asset_name: crypto-monitor-${{ github.ref_name }}-linux-amd64 + asset_content_type: application/x-elf