mirror of https://github.com/usememos/memos.git
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
This commit is contained in:
parent
29412f4690
commit
4033f64b9a
|
|
@ -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
|
||||
Loading…
Reference in New Issue