Commit 27063d48 authored by Steven's avatar Steven

chore(ci): auto-upload binaries to GitHub Release on publish

parent 71e8a064
name: Build Binaries name: Build Binaries
# Manually triggered workflow to build multi-platform binaries # Build multi-platform binaries on release or manual trigger
# Produces distributable packages for Linux, macOS, and Windows # Produces distributable packages for Linux, macOS, and Windows
on: on:
release:
types: [published]
workflow_dispatch: workflow_dispatch:
# Environment variables for build configuration # Environment variables for build configuration
...@@ -11,6 +13,8 @@ env: ...@@ -11,6 +13,8 @@ env:
NODE_VERSION: "22" NODE_VERSION: "22"
PNPM_VERSION: "10" PNPM_VERSION: "10"
ARTIFACT_RETENTION_DAYS: 60 ARTIFACT_RETENTION_DAYS: 60
# Artifact naming: {ARTIFACT_PREFIX}_{version}_{os}_{arch}.tar.gz|zip
ARTIFACT_PREFIX: memos
jobs: jobs:
# Job 1: Extract version information # Job 1: Extract version information
...@@ -152,9 +156,9 @@ jobs: ...@@ -152,9 +156,9 @@ jobs:
if [ "$GOOS" = "windows" ]; then if [ "$GOOS" = "windows" ]; then
OUTPUT_NAME="memos.exe" OUTPUT_NAME="memos.exe"
fi fi
mkdir -p build mkdir -p build
# Build static binary with optimizations # Build static binary with optimizations
go build \ go build \
-trimpath \ -trimpath \
...@@ -162,7 +166,7 @@ jobs: ...@@ -162,7 +166,7 @@ jobs:
-tags netgo,osusergo \ -tags netgo,osusergo \
-o "build/${OUTPUT_NAME}" \ -o "build/${OUTPUT_NAME}" \
./cmd/memos ./cmd/memos
echo "✓ Built: build/${OUTPUT_NAME}" echo "✓ Built: build/${OUTPUT_NAME}"
ls -lh build/ ls -lh build/
...@@ -175,13 +179,13 @@ jobs: ...@@ -175,13 +179,13 @@ jobs:
GOARM: ${{ matrix.goarm }} GOARM: ${{ matrix.goarm }}
run: | run: |
cd build cd build
# Construct package name: memos-{version}-{os}-{arch}[v{arm_version}] # Construct package name: {prefix}_{version}_{os}_{arch}[v{arm_version}]
PACKAGE_NAME="memos-${VERSION}-${GOOS}-${GOARCH}" PACKAGE_NAME="${ARTIFACT_PREFIX}_${VERSION}_${GOOS}_${GOARCH}"
if [ -n "$GOARM" ]; then if [ -n "$GOARM" ]; then
PACKAGE_NAME="${PACKAGE_NAME}v${GOARM}" PACKAGE_NAME="${PACKAGE_NAME}v${GOARM}"
fi fi
# Package based on platform # Package based on platform
if [ "$GOOS" = "windows" ]; then if [ "$GOOS" = "windows" ]; then
ARTIFACT_NAME="${PACKAGE_NAME}.zip" ARTIFACT_NAME="${PACKAGE_NAME}.zip"
...@@ -190,7 +194,7 @@ jobs: ...@@ -190,7 +194,7 @@ jobs:
ARTIFACT_NAME="${PACKAGE_NAME}.tar.gz" ARTIFACT_NAME="${PACKAGE_NAME}.tar.gz"
tar czf "${ARTIFACT_NAME}" memos tar czf "${ARTIFACT_NAME}" memos
fi fi
# Output for next step # Output for next step
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
echo "✓ Package created: ${ARTIFACT_NAME} ($(du -h "${ARTIFACT_NAME}" | cut -f1))" echo "✓ Package created: ${ARTIFACT_NAME} ($(du -h "${ARTIFACT_NAME}" | cut -f1))"
...@@ -202,60 +206,26 @@ jobs: ...@@ -202,60 +206,26 @@ jobs:
path: build/${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
# Job 4: Generate build summary # Job 4: Upload artifacts to GitHub Release
# - Downloads all built artifacts # - Only runs when triggered by a release publish event
# - Creates formatted summary table with sizes # - Downloads all built artifacts and attaches them to the release
# - Displayed in GitHub Actions UI release:
summary: name: Upload Release Assets
name: Generate Summary needs: build-binaries
needs: [prepare, build-binaries] if: github.event_name == 'release'
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: always() permissions:
contents: write
steps: steps:
- name: Download all artifacts - name: Download all artifacts
uses: actions/download-artifact@v7 uses: actions/download-artifact@v7
with: with:
path: artifacts path: artifacts
pattern: memos-* pattern: ${{ env.ARTIFACT_PREFIX }}_*
merge-multiple: false merge-multiple: true
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: artifacts/*
- name: Generate build summary
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |
{
echo "## 🎉 Build Complete"
echo ""
echo "### Build Information"
echo "| Key | Value |"
echo "|-----|-------|"
echo "| **Version** | \`${VERSION}\` |"
echo "| **Branch** | \`${{ github.ref_name }}\` |"
echo "| **Commit** | \`${{ github.sha }}\` |"
echo "| **Triggered by** | @${{ github.actor }} |"
echo ""
echo "### 📦 Built Artifacts"
echo ""
echo "| Platform | Artifact | Size |"
echo "|----------|----------|------|"
} >> $GITHUB_STEP_SUMMARY
# List all artifacts with sizes
cd artifacts
for dir in */; do
if [ -d "$dir" ]; then
artifact=$(ls "$dir" 2>/dev/null | head -1)
if [ -n "$artifact" ]; then
size=$(du -h "$dir/$artifact" | cut -f1)
# Extract platform from filename (remove memos-version- prefix and extension)
platform=$(echo "$artifact" | sed "s/memos-${VERSION}-//;s/\.(tar\.gz|zip)$//")
echo "| \`$platform\` | \`$artifact\` | **$size** |" >> $GITHUB_STEP_SUMMARY
fi
fi
done
{
echo ""
echo "### 📥 Download"
echo "Artifacts are available in the **Artifacts** section above (retention: ${{ env.ARTIFACT_RETENTION_DAYS }} days)."
} >> $GITHUB_STEP_SUMMARY
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment