From 4033f64b9ab8f784410e2a9120178cb0aa3f5077 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 2 Feb 2026 22:54:30 +0800 Subject: [PATCH] feat: add build binaries workflow for multi-platform releases - Add workflow_dispatch trigger for manual binary builds - Build for linux (amd64, arm64, arm/v7), darwin (amd64, arm64), windows (amd64) - Package as tar.gz (Unix) and zip (Windows) - Generate build summary with artifact sizes --- .github/workflows/build-binaries.yml | 168 +++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 .github/workflows/build-binaries.yml diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml new file mode 100644 index 000000000..ccaf85ca4 --- /dev/null +++ b/.github/workflows/build-binaries.yml @@ -0,0 +1,168 @@ +name: Build Binaries + +on: + workflow_dispatch: + +jobs: + build-frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - uses: pnpm/action-setup@v4.2.0 + with: + version: 10 + - uses: actions/setup-node@v6 + with: + node-version: "22" + cache: pnpm + cache-dependency-path: "web/pnpm-lock.yaml" + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + - name: Setup pnpm cache + uses: actions/cache@v5 + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('web/pnpm-lock.yaml') }} + restore-keys: ${{ runner.os }}-pnpm-store- + - run: pnpm install --frozen-lockfile + working-directory: web + - name: Run frontend build + run: pnpm release + working-directory: web + + - name: Upload frontend artifacts + uses: actions/upload-artifact@v6 + with: + name: frontend-dist + path: server/router/frontend/dist + retention-days: 7 + + build-binaries: + needs: build-frontend + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: linux + goarch: amd64 + platform: linux/amd64 + - goos: linux + goarch: arm64 + platform: linux/arm64 + - goos: linux + goarch: arm + goarm: "7" + platform: linux/arm/v7 + - goos: darwin + goarch: amd64 + platform: darwin/amd64 + - goos: darwin + goarch: arm64 + platform: darwin/arm64 + - goos: windows + goarch: amd64 + platform: windows/amd64 + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-go@v6 + with: + go-version: "1.25" + cache: true + + - name: Download frontend artifacts + uses: actions/download-artifact@v7 + with: + name: frontend-dist + path: server/router/frontend/dist + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + GOARM: ${{ matrix.goarm }} + CGO_ENABLED: "0" + run: | + # Determine output file name + OUTPUT_NAME="memos" + if [ "${{ matrix.goos }}" = "windows" ]; then + OUTPUT_NAME="memos.exe" + fi + + # Build with optimizations + go build \ + -trimpath \ + -ldflags="-s -w -extldflags '-static'" \ + -tags netgo,osusergo \ + -o "build/${OUTPUT_NAME}" \ + ./cmd/memos + + echo "Built: build/${OUTPUT_NAME}" + ls -lh build/ + + - name: Package binary + run: | + cd build + + # Create package name + PACKAGE_NAME="memos-${{ matrix.goos }}-${{ matrix.goarch }}" + if [ -n "${{ matrix.goarm }}" ]; then + PACKAGE_NAME="memos-${{ matrix.goos }}-${{ matrix.goarch }}v${{ matrix.goarm }}" + fi + + # Package based on OS + if [ "${{ matrix.goos }}" = "windows" ]; then + zip "${PACKAGE_NAME}.zip" memos.exe + echo "ARTIFACT_NAME=${PACKAGE_NAME}.zip" >> $GITHUB_ENV + else + tar czf "${PACKAGE_NAME}.tar.gz" memos + echo "ARTIFACT_NAME=${PACKAGE_NAME}.tar.gz" >> $GITHUB_ENV + fi + + ls -lh + echo "Package created: ${ARTIFACT_NAME}" + + - name: Upload binary artifact + uses: actions/upload-artifact@v6 + with: + name: ${{ env.ARTIFACT_NAME }} + path: build/${{ env.ARTIFACT_NAME }} + retention-days: 7 + + summary: + needs: build-binaries + runs-on: ubuntu-latest + steps: + - name: Download all artifacts + uses: actions/download-artifact@v7 + with: + path: artifacts + pattern: memos-* + + - name: Generate build summary + run: | + echo "## Build Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY + echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### Built Artifacts" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| Platform | Artifact | Size |" >> $GITHUB_STEP_SUMMARY + echo "|----------|----------|------|" >> $GITHUB_STEP_SUMMARY + + cd artifacts + for dir in */; do + artifact=$(ls "$dir" 2>/dev/null | head -1) + if [ -n "$artifact" ]; then + size=$(du -h "$dir/$artifact" | cut -f1) + platform=$(echo "$artifact" | sed 's/memos-//;s/\.(tar\.gz|zip)$//') + echo "| \`$platform\` | \`$artifact\` | $size |" >> $GITHUB_STEP_SUMMARY + fi + done + + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Download:** Go to the workflow run summary to download artifacts." >> $GITHUB_STEP_SUMMARY