From 1775b0ec8626e653ff9465233bf3c8aaec37b28d Mon Sep 17 00:00:00 2001 From: lpf Date: Thu, 12 Mar 2026 13:18:57 +0800 Subject: [PATCH] ci: stabilize release workflow setup --- .github/workflows/release.yml | 157 +++++++++++++++++++++++++++++++--- Makefile | 9 ++ 2 files changed, 154 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f539ff..5b97d69 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,9 +67,114 @@ jobs: echo "Targets: $build_targets" echo "Variants: $channel_variants" - build-and-package: + build-webui: needs: prepare-release runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Ensure Node.js 20 + shell: bash + run: | + set -euo pipefail + if command -v node >/dev/null 2>&1; then + node_major="$(node -p 'process.versions.node.split(".")[0]')" + else + node_major="" + fi + if [ "$node_major" != "20" ]; then + arch="$(dpkg --print-architecture)" + case "$arch" in + amd64) node_arch="x64" ;; + arm64) node_arch="arm64" ;; + *) + echo "Unsupported runner architecture for Node install: $arch" >&2 + exit 1 + ;; + esac + curl -fsSL "https://nodejs.org/dist/v20.19.5/node-v20.19.5-linux-${node_arch}.tar.xz" -o /tmp/node.tar.xz + sudo rm -rf /usr/local/lib/nodejs + sudo mkdir -p /usr/local/lib/nodejs + sudo tar -xJf /tmp/node.tar.xz -C /usr/local/lib/nodejs + echo "/usr/local/lib/nodejs/node-v20.19.5-linux-${node_arch}/bin" >> "$GITHUB_PATH" + fi + node --version + npm --version + + - name: Install WebUI dependencies + shell: bash + run: | + set -euo pipefail + cd webui + if [ -f package-lock.json ]; then + npm ci + else + npm install + fi + + - name: Build WebUI + shell: bash + run: | + set -euo pipefail + make build-webui + + - name: Upload WebUI dist + uses: actions/upload-artifact@v4 + with: + name: webui-dist + path: webui/dist + if-no-files-found: error + + prepare-go-cache: + needs: prepare-release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Go + shell: bash + run: | + set -euo pipefail + go_version="$(awk '/^go / {print $2; exit}' go.mod)" + arch="$(dpkg --print-architecture)" + case "$arch" in + amd64) go_arch="amd64" ;; + arm64) go_arch="arm64" ;; + *) + echo "Unsupported runner architecture for Go install: $arch" >&2 + exit 1 + ;; + esac + curl -fsSL "https://go.dev/dl/go${go_version}.linux-${go_arch}.tar.gz" -o /tmp/go.tgz + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf /tmp/go.tgz + echo "/usr/local/go/bin" >> "$GITHUB_PATH" + /usr/local/go/bin/go version + + - name: Warm Go module cache + shell: bash + run: | + set -euo pipefail + mkdir -p /tmp/go-cache + go mod download + GOMODCACHE="$(go env GOMODCACHE)" + tar -C "$GOMODCACHE" -czf /tmp/go-cache/gomodcache.tar.gz . + + - name: Upload Go module cache + uses: actions/upload-artifact@v4 + with: + name: go-mod-cache + path: /tmp/go-cache/gomodcache.tar.gz + if-no-files-found: error + + build-and-package: + needs: + - prepare-release + - build-webui + - prepare-go-cache + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -78,18 +183,45 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache: true + - name: Install Go + shell: bash + run: | + set -euo pipefail + go_version="$(awk '/^go / {print $2; exit}' go.mod)" + arch="$(dpkg --print-architecture)" + case "$arch" in + amd64) go_arch="amd64" ;; + arm64) go_arch="arm64" ;; + *) + echo "Unsupported runner architecture for Go install: $arch" >&2 + exit 1 + ;; + esac + curl -fsSL "https://go.dev/dl/go${go_version}.linux-${go_arch}.tar.gz" -o /tmp/go.tgz + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf /tmp/go.tgz + echo "/usr/local/go/bin" >> "$GITHUB_PATH" + /usr/local/go/bin/go version - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Download WebUI dist + uses: actions/download-artifact@v4 with: - node-version: '20' - cache: 'npm' - cache-dependency-path: webui/package-lock.json + name: webui-dist + path: webui/dist + + - name: Download Go module cache + uses: actions/download-artifact@v4 + with: + name: go-mod-cache + path: /tmp/go-cache + + - name: Restore Go module cache + shell: bash + run: | + set -euo pipefail + GOMODCACHE="$(go env GOMODCACHE)" + mkdir -p "$GOMODCACHE" + tar -C "$GOMODCACHE" -xzf /tmp/go-cache/gomodcache.tar.gz - name: Install packaging tools run: | @@ -116,7 +248,8 @@ jobs: make package-all \ VERSION="${{ needs.prepare-release.outputs.version }}" \ BUILD_TARGETS="${{ matrix.target }}" \ - CHANNEL_PACKAGE_VARIANTS="${{ needs.prepare-release.outputs.channel_variants }}" + CHANNEL_PACKAGE_VARIANTS="${{ needs.prepare-release.outputs.channel_variants }}" \ + SKIP_WEBUI_BUILD=1 rm -f build/checksums.txt - name: Upload matrix artifacts diff --git a/Makefile b/Makefile index 2410736..660113f 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ DEV_WEBUI_DIR?=$(CURDIR)/webui WEBUI_DIST_DIR=$(DEV_WEBUI_DIR)/dist WEBUI_PACKAGE_LOCK=$(DEV_WEBUI_DIR)/package-lock.json NPM?=npm +SKIP_WEBUI_BUILD?=0 # OS detection UNAME_S:=$(shell uname -s) @@ -230,6 +231,14 @@ build-webui: echo "✗ Missing WebUI directory: $(DEV_WEBUI_DIR)"; \ exit 1; \ fi + @if [ "$(SKIP_WEBUI_BUILD)" = "1" ]; then \ + if [ -d "$(WEBUI_DIST_DIR)" ]; then \ + echo "✓ Reusing existing WebUI dist from $(WEBUI_DIST_DIR)"; \ + exit 0; \ + fi; \ + echo "✗ SKIP_WEBUI_BUILD=1 but WebUI dist is missing: $(WEBUI_DIST_DIR)"; \ + exit 1; \ + fi @if ! command -v "$(NPM)" >/dev/null 2>&1; then \ echo "✗ npm is required to build the WebUI"; \ exit 1; \