Commit 7465fbb4 authored by Steven's avatar Steven

refactor: improve GitHub Actions workflows structure and maintainability

- Add build-binaries workflow for multi-platform binary releases
- Rename workflows for conciseness:
  - demo-render-deploy.yml → demo-deploy.yml
  - build-and-push-canary-image.yml → build-canary-image.yml
  - build-and-push-stable-image.yml → build-stable-image.yml
- Centralize version config with env variables (GO_VERSION, NODE_VERSION, PNPM_VERSION)
- Standardize step names across all workflows
- Add concurrency controls to prevent redundant runs
- Update Node.js (20→22) and pnpm (9→10) versions to match build-binaries
- Improve job names with descriptive labels
- Add consistent comments and formatting
- Set artifact retention to 60 days for binary builds
parent 4033f64b
...@@ -4,8 +4,7 @@ on: ...@@ -4,8 +4,7 @@ on:
push: push:
branches: [main] branches: [main]
pull_request: pull_request:
branches: branches: [main]
- main
paths: paths:
- "go.mod" - "go.mod"
- "go.sum" - "go.sum"
...@@ -15,55 +14,58 @@ concurrency: ...@@ -15,55 +14,58 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
env:
GO_VERSION: "1.25"
jobs: jobs:
go-static-checks: static-checks:
name: Static Checks
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
uses: actions/checkout@v6
- uses: actions/setup-go@v6 - name: Setup Go
uses: actions/setup-go@v6
with: with:
go-version: 1.25 go-version: ${{ env.GO_VERSION }}
cache: true cache: true
cache-dependency-path: go.sum cache-dependency-path: go.sum
- name: Verify go.mod is tidy - name: Verify go.mod is tidy
run: | run: |
go mod tidy -go=1.25 go mod tidy -go=${{ env.GO_VERSION }}
git diff --exit-code git diff --exit-code
- name: golangci-lint - name: Run golangci-lint
uses: golangci/golangci-lint-action@v9 uses: golangci/golangci-lint-action@v9
with: with:
version: v2.4.0 version: v2.4.0
args: --timeout=3m args: --timeout=3m
go-tests: tests:
name: Tests (${{ matrix.test-group }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
test-group: test-group: [store, server, plugin, other]
- store
- server
- plugin
- other
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
uses: actions/checkout@v6
- uses: actions/setup-go@v6 - name: Setup Go
uses: actions/setup-go@v6
with: with:
go-version: 1.25 go-version: ${{ env.GO_VERSION }}
cache: true cache: true
cache-dependency-path: go.sum cache-dependency-path: go.sum
- name: Run tests - ${{ matrix.test-group }} - name: Run tests
run: | run: |
case "${{ matrix.test-group }}" in case "${{ matrix.test-group }}" in
store) store)
# Run store tests for all drivers (sqlite, mysql, postgres) # Run store tests for all drivers (sqlite, mysql, postgres)
# The TestMain in store/test runs all drivers when DRIVER is not set
# Note: We run without -race for container tests due to testcontainers race issues
go test -v -coverprofile=coverage.out -covermode=atomic ./store/... go test -v -coverprofile=coverage.out -covermode=atomic ./store/...
;; ;;
server) server)
......
name: Build Binaries name: Build Binaries
# Manually triggered workflow to build multi-platform binaries
# Produces distributable packages for Linux, macOS, and Windows
on: on:
workflow_dispatch: workflow_dispatch:
# Environment variables for build configuration
env:
GO_VERSION: "1.25"
NODE_VERSION: "22"
PNPM_VERSION: "10"
ARTIFACT_RETENTION_DAYS: 60
jobs: jobs:
# Job 1: Extract version information
# - For git tags: use tag version (e.g., v0.28.1 -> 0.28.1)
# - For branches: use branch-name-shortSHA format
prepare:
name: Extract Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Full history for git describe
- name: Extract version
id: version
run: |
# Try to get version from git tag
TAG=$(git describe --tags --exact-match 2>/dev/null || echo "")
if [ -n "$TAG" ]; then
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
echo "Version from tag: ${TAG#v}"
else
# Use branch name + short SHA
BRANCH="${GITHUB_REF_NAME//\//-}"
SHORT_SHA="${GITHUB_SHA:0:7}"
echo "version=${BRANCH}-${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "Version from branch: ${BRANCH}-${SHORT_SHA}"
fi
# Job 2: Build frontend assets
# - Builds React frontend with Vite
# - Produces static files that will be embedded in Go binary
# - Shared across all platform builds
build-frontend: build-frontend:
name: Build Frontend
needs: prepare
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
uses: actions/checkout@v6
- uses: pnpm/action-setup@v4.2.0 - name: Setup pnpm
uses: pnpm/action-setup@v4.2.0
with: with:
version: 10 version: ${{ env.PNPM_VERSION }}
- uses: actions/setup-node@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with: with:
node-version: "22" node-version: ${{ env.NODE_VERSION }}
cache: pnpm cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml" cache-dependency-path: web/pnpm-lock.yaml
- name: Get pnpm store directory - name: Get pnpm store directory
id: pnpm-cache id: pnpm-cache
shell: bash shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache - name: Setup pnpm cache
uses: actions/cache@v5 uses: actions/cache@v5
with: with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('web/pnpm-lock.yaml') }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('web/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store- restore-keys: ${{ runner.os }}-pnpm-store-
- run: pnpm install --frozen-lockfile
- name: Install dependencies
working-directory: web working-directory: web
- name: Run frontend build run: pnpm install --frozen-lockfile
run: pnpm release
- name: Build frontend
working-directory: web working-directory: web
run: pnpm release
- name: Upload frontend artifacts - name: Upload frontend artifacts
uses: actions/upload-artifact@v6 uses: actions/upload-artifact@v6
with: with:
name: frontend-dist name: frontend-dist
path: server/router/frontend/dist path: server/router/frontend/dist
retention-days: 7 retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
# Job 3: Build Go binaries for multiple platforms
# - Cross-compiles using native Go toolchain
# - Embeds frontend assets built in previous job
# - Produces static binaries with no external dependencies
# - Packages as tar.gz (Unix) or zip (Windows)
build-binaries: build-binaries:
needs: build-frontend name: Build ${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
needs: [prepare, build-frontend]
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
include: include:
# Linux targets
- goos: linux - goos: linux
goarch: amd64 goarch: amd64
platform: linux/amd64
- goos: linux - goos: linux
goarch: arm64 goarch: arm64
platform: linux/arm64
- goos: linux - goos: linux
goarch: arm goarch: arm
goarm: "7" goarm: "7"
platform: linux/arm/v7 # macOS targets
- goos: darwin - goos: darwin
goarch: amd64 goarch: amd64 # Intel Macs
platform: darwin/amd64
- goos: darwin - goos: darwin
goarch: arm64 goarch: arm64 # Apple Silicon
platform: darwin/arm64 # Windows targets
- goos: windows - goos: windows
goarch: amd64 goarch: amd64
platform: windows/amd64
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
uses: actions/checkout@v6
- uses: actions/setup-go@v6 - name: Setup Go
uses: actions/setup-go@v6
with: with:
go-version: "1.25" go-version: ${{ env.GO_VERSION }}
cache: true cache: true
- name: Download frontend artifacts - name: Download frontend artifacts
...@@ -86,13 +147,15 @@ jobs: ...@@ -86,13 +147,15 @@ jobs:
GOARM: ${{ matrix.goarm }} GOARM: ${{ matrix.goarm }}
CGO_ENABLED: "0" CGO_ENABLED: "0"
run: | run: |
# Determine output file name # Determine output binary name
OUTPUT_NAME="memos" OUTPUT_NAME="memos"
if [ "${{ matrix.goos }}" = "windows" ]; then if [ "$GOOS" = "windows" ]; then
OUTPUT_NAME="memos.exe" OUTPUT_NAME="memos.exe"
fi fi
# Build with optimizations mkdir -p build
# Build static binary with optimizations
go build \ go build \
-trimpath \ -trimpath \
-ldflags="-s -w -extldflags '-static'" \ -ldflags="-s -w -extldflags '-static'" \
...@@ -100,69 +163,99 @@ jobs: ...@@ -100,69 +163,99 @@ jobs:
-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/
- name: Package binary - name: Package binary
id: package
env:
VERSION: ${{ needs.prepare.outputs.version }}
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
run: | run: |
cd build cd build
# Create package name # Construct package name: memos-{version}-{os}-{arch}[v{arm_version}]
PACKAGE_NAME="memos-${{ matrix.goos }}-${{ matrix.goarch }}" PACKAGE_NAME="memos-${VERSION}-${GOOS}-${GOARCH}"
if [ -n "${{ matrix.goarm }}" ]; then if [ -n "$GOARM" ]; then
PACKAGE_NAME="memos-${{ matrix.goos }}-${{ matrix.goarch }}v${{ matrix.goarm }}" PACKAGE_NAME="${PACKAGE_NAME}v${GOARM}"
fi fi
# Package based on OS # Package based on platform
if [ "${{ matrix.goos }}" = "windows" ]; then if [ "$GOOS" = "windows" ]; then
zip "${PACKAGE_NAME}.zip" memos.exe ARTIFACT_NAME="${PACKAGE_NAME}.zip"
echo "ARTIFACT_NAME=${PACKAGE_NAME}.zip" >> $GITHUB_ENV zip -q "${ARTIFACT_NAME}" memos.exe
else else
tar czf "${PACKAGE_NAME}.tar.gz" memos ARTIFACT_NAME="${PACKAGE_NAME}.tar.gz"
echo "ARTIFACT_NAME=${PACKAGE_NAME}.tar.gz" >> $GITHUB_ENV tar czf "${ARTIFACT_NAME}" memos
fi fi
ls -lh # Output for next step
echo "Package created: ${ARTIFACT_NAME}" echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
echo "✓ Package created: ${ARTIFACT_NAME} ($(du -h "${ARTIFACT_NAME}" | cut -f1))"
- name: Upload binary artifact - name: Upload binary artifact
uses: actions/upload-artifact@v6 uses: actions/upload-artifact@v6
with: with:
name: ${{ env.ARTIFACT_NAME }} name: ${{ env.ARTIFACT_NAME }}
path: build/${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }}
retention-days: 7 retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
# Job 4: Generate build summary
# - Downloads all built artifacts
# - Creates formatted summary table with sizes
# - Displayed in GitHub Actions UI
summary: summary:
needs: build-binaries name: Generate Summary
needs: [prepare, build-binaries]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: always()
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: memos-*
merge-multiple: false
- name: Generate build summary - name: Generate build summary
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: | run: |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY {
echo "" >> $GITHUB_STEP_SUMMARY echo "## 🎉 Build Complete"
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY echo ""
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY echo "### Build Information"
echo "" >> $GITHUB_STEP_SUMMARY echo "| Key | Value |"
echo "### Built Artifacts" >> $GITHUB_STEP_SUMMARY echo "|-----|-------|"
echo "" >> $GITHUB_STEP_SUMMARY echo "| **Version** | \`${VERSION}\` |"
echo "| Platform | Artifact | Size |" >> $GITHUB_STEP_SUMMARY echo "| **Branch** | \`${{ github.ref_name }}\` |"
echo "|----------|----------|------|" >> $GITHUB_STEP_SUMMARY 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 cd artifacts
for dir in */; do for dir in */; do
if [ -d "$dir" ]; then
artifact=$(ls "$dir" 2>/dev/null | head -1) artifact=$(ls "$dir" 2>/dev/null | head -1)
if [ -n "$artifact" ]; then if [ -n "$artifact" ]; then
size=$(du -h "$dir/$artifact" | cut -f1) size=$(du -h "$dir/$artifact" | cut -f1)
platform=$(echo "$artifact" | sed 's/memos-//;s/\.(tar\.gz|zip)$//') # Extract platform from filename (remove memos-version- prefix and extension)
echo "| \`$platform\` | \`$artifact\` | $size |" >> $GITHUB_STEP_SUMMARY platform=$(echo "$artifact" | sed "s/memos-${VERSION}-//;s/\.(tar\.gz|zip)$//")
echo "| \`$platform\` | \`$artifact\` | **$size** |" >> $GITHUB_STEP_SUMMARY
fi
fi fi
done done
echo "" >> $GITHUB_STEP_SUMMARY {
echo "**Download:** Go to the workflow run summary to download artifacts." >> $GITHUB_STEP_SUMMARY echo ""
echo "### 📥 Download"
echo "Artifacts are available in the **Artifacts** section above (retention: ${{ env.ARTIFACT_RETENTION_DAYS }} days)."
} >> $GITHUB_STEP_SUMMARY
name: Build and Push Canary Image name: Build Canary Image
on: on:
push: push:
......
name: Build and Push Stable Image name: Build Stable Image
on: on:
push: push:
......
name: Demo Render Deploy name: Demo Deploy
on: on:
workflow_dispatch: workflow_dispatch:
......
...@@ -4,44 +4,69 @@ on: ...@@ -4,44 +4,69 @@ on:
push: push:
branches: [main] branches: [main]
pull_request: pull_request:
branches: branches: [main]
- main
paths: paths:
- "web/**" - "web/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: "22"
PNPM_VERSION: "10"
jobs: jobs:
static-checks: lint:
name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
- uses: pnpm/action-setup@v4.2.0 uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4.2.0
with: with:
version: 9 version: ${{ env.PNPM_VERSION }}
- uses: actions/setup-node@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with: with:
node-version: "20" node-version: ${{ env.NODE_VERSION }}
cache: pnpm cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml" cache-dependency-path: web/pnpm-lock.yaml
- run: pnpm install
- name: Install dependencies
working-directory: web working-directory: web
- name: Run check run: pnpm install --frozen-lockfile
run: pnpm lint
- name: Run lint
working-directory: web working-directory: web
run: pnpm lint
frontend-build: build:
name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - name: Checkout code
- uses: pnpm/action-setup@v4.2.0 uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4.2.0
with: with:
version: 9 version: ${{ env.PNPM_VERSION }}
- uses: actions/setup-node@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with: with:
node-version: "20" node-version: ${{ env.NODE_VERSION }}
cache: pnpm cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml" cache-dependency-path: web/pnpm-lock.yaml
- run: pnpm install
- name: Install dependencies
working-directory: web working-directory: web
- name: Run frontend build run: pnpm install --frozen-lockfile
run: pnpm build
- name: Build frontend
working-directory: web working-directory: web
run: pnpm build
...@@ -4,30 +4,37 @@ on: ...@@ -4,30 +4,37 @@ on:
push: push:
branches: [main] branches: [main]
pull_request: pull_request:
branches: branches: [main]
- main
paths: paths:
- "proto/**" - "proto/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
lint-protos: lint:
name: Lint Protos
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout code
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Setup buf - name: Setup buf
uses: bufbuild/buf-setup-action@v1 uses: bufbuild/buf-setup-action@v1
with: with:
github_token: ${{ github.token }} github_token: ${{ github.token }}
- name: buf lint
- name: Run buf lint
uses: bufbuild/buf-lint-action@v1 uses: bufbuild/buf-lint-action@v1
with: with:
input: "proto" input: proto
- name: buf format
- name: Check buf format
run: | run: |
if [[ $(buf format -d) ]]; then if [[ $(buf format -d) ]]; then
echo "Run 'buf format -d'" echo "❌ Proto files are not formatted. Run 'buf format -w' to fix."
exit 1 exit 1
fi fi
name: Stale name: Stale Issues
on: on:
schedule: schedule:
- cron: "0 */8 * * *" - cron: "0 */8 * * *" # Every 8 hours
jobs: jobs:
stale: close-stale:
name: Close Stale Issues
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
issues: write issues: write
steps: steps:
- uses: actions/stale@v10.1.1 - name: Close stale issues
uses: actions/stale@v10.1.1
with: with:
days-before-issue-stale: 14 days-before-issue-stale: 14
days-before-issue-close: 7 days-before-issue-close: 7
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