From dcf08b5911a4faefc41664779713956b21980081 Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 27 Oct 2026 20:22:30 +0800 Subject: [PATCH] chore(ci): share Go and web setup through composite actions Add .github/actions/setup-go (Go version from go.mod) and .github/actions/setup-web (pnpm from web/package.json, Node 24, frozen install), and use them in every workflow that installed the toolchains by hand. Drop the per-workflow version env vars and the redundant pnpm store cache steps that duplicated setup-node's cache. --- .github/actions/setup-go/action.yml | 12 +++++++ .github/actions/setup-web/action.yml | 23 ++++++++++++++ .github/workflows/backend-tests.yml | 22 ++++--------- .github/workflows/build-canary-image.yml | 23 ++------------ .github/workflows/frontend-tests.yml | 40 ++++-------------------- .github/workflows/release.yml | 37 ++-------------------- .github/workflows/upgrade-smoke.yml | 29 +++-------------- AGENTS.md | 4 ++- 8 files changed, 60 insertions(+), 130 deletions(-) create mode 100644 .github/actions/setup-go/action.yml create mode 100644 .github/actions/setup-web/action.yml diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml new file mode 100644 index 000000000..7ef241c8d --- /dev/null +++ b/.github/actions/setup-go/action.yml @@ -0,0 +1,12 @@ +name: Setup Go +description: Install the Go version declared in go.mod and restore the module and build cache. + +runs: + using: composite + steps: + - name: Setup Go + uses: actions/setup-go@v6 + with: + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum diff --git a/.github/actions/setup-web/action.yml b/.github/actions/setup-web/action.yml new file mode 100644 index 000000000..24b25bd95 --- /dev/null +++ b/.github/actions/setup-web/action.yml @@ -0,0 +1,23 @@ +name: Setup Web +description: Install Node.js and the pnpm version pinned in web/package.json, then install web dependencies. + +runs: + using: composite + steps: + - name: Setup pnpm + uses: pnpm/action-setup@v4.2.0 + with: + package_json_file: web/package.json + + # setup-node's pnpm cache covers the pnpm store, so no separate actions/cache step is needed. + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "24" + cache: pnpm + cache-dependency-path: web/pnpm-lock.yaml + + - name: Install dependencies + shell: bash + working-directory: web + run: pnpm install --frozen-lockfile diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index 53e59290c..ff2fb0f60 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -10,15 +10,13 @@ on: - "go.sum" - "**.go" - ".golangci.yaml" + - ".github/actions/setup-go/**" - ".github/workflows/backend-tests.yml" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -env: - GO_VERSION: "1.27.2" - jobs: static-checks: name: Static Checks @@ -26,17 +24,13 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v6 - + - name: Setup Go - uses: actions/setup-go@v6 - with: - go-version: ${{ env.GO_VERSION }} - cache: true - cache-dependency-path: go.sum + uses: ./.github/actions/setup-go - name: Verify go.mod is tidy run: | - go mod tidy -go=${{ env.GO_VERSION }} + go mod tidy git diff --exit-code - name: Verify go fix @@ -58,13 +52,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v6 - + - name: Setup Go - uses: actions/setup-go@v6 - with: - go-version: ${{ env.GO_VERSION }} - cache: true - cache-dependency-path: go.sum + uses: ./.github/actions/setup-go - name: Run tests run: | diff --git a/.github/workflows/build-canary-image.yml b/.github/workflows/build-canary-image.yml index 108d7fb39..8bbf4ddfb 100644 --- a/.github/workflows/build-canary-image.yml +++ b/.github/workflows/build-canary-image.yml @@ -17,26 +17,9 @@ jobs: steps: - uses: actions/checkout@v6 - - uses: pnpm/action-setup@v4.2.0 - with: - version: 11.0.1 - - uses: actions/setup-node@v6 - with: - node-version: "24" - 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: Setup web + uses: ./.github/actions/setup-web + - name: Run frontend build run: pnpm release working-directory: web diff --git a/.github/workflows/frontend-tests.yml b/.github/workflows/frontend-tests.yml index d616c6224..4d302e07e 100644 --- a/.github/workflows/frontend-tests.yml +++ b/.github/workflows/frontend-tests.yml @@ -7,15 +7,13 @@ on: branches: [main] paths: - "web/**" + - ".github/actions/setup-web/**" + - ".github/workflows/frontend-tests.yml" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -env: - NODE_VERSION: "24" - PNPM_VERSION: "11.0.1" - jobs: lint: name: Lint @@ -24,21 +22,8 @@ jobs: - name: Checkout code uses: actions/checkout@v6 - - name: Setup pnpm - uses: pnpm/action-setup@v4.2.0 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - cache-dependency-path: web/pnpm-lock.yaml - - - name: Install dependencies - working-directory: web - run: pnpm install --frozen-lockfile + - name: Setup web + uses: ./.github/actions/setup-web - name: Run lint working-directory: web @@ -55,21 +40,8 @@ jobs: - name: Checkout code uses: actions/checkout@v6 - - name: Setup pnpm - uses: pnpm/action-setup@v4.2.0 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - cache-dependency-path: web/pnpm-lock.yaml - - - name: Install dependencies - working-directory: web - run: pnpm install --frozen-lockfile + - name: Setup web + uses: ./.github/actions/setup-web - name: Build frontend working-directory: web diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8919650db..66a055083 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,9 +16,6 @@ permissions: contents: read env: - GO_VERSION: "1.27.2" - NODE_VERSION: "24" - PNPM_VERSION: "11.0.1" ARTIFACT_RETENTION_DAYS: 60 ARTIFACT_PREFIX: memos @@ -73,33 +70,8 @@ jobs: - name: Checkout code uses: actions/checkout@v6 - - name: Setup pnpm - uses: pnpm/action-setup@v4.2.0 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version: ${{ env.NODE_VERSION }} - 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@v4 - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('web/pnpm-lock.yaml') }} - restore-keys: ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - working-directory: web - run: pnpm install --frozen-lockfile + - name: Setup web + uses: ./.github/actions/setup-web - name: Build frontend release assets working-directory: web @@ -138,10 +110,7 @@ jobs: uses: actions/checkout@v6 - name: Setup Go - uses: actions/setup-go@v6 - with: - go-version: ${{ env.GO_VERSION }} - cache: true + uses: ./.github/actions/setup-go - name: Download frontend artifacts uses: actions/download-artifact@v4 diff --git a/.github/workflows/upgrade-smoke.yml b/.github/workflows/upgrade-smoke.yml index 5e41e2f72..9ec68df3f 100644 --- a/.github/workflows/upgrade-smoke.yml +++ b/.github/workflows/upgrade-smoke.yml @@ -28,6 +28,7 @@ on: - "scripts/release_smoke_test.sh" - "scripts/release_version*" - "scripts/install*" + - ".github/actions/**" - ".github/workflows/release.yml" - ".github/workflows/upgrade-smoke.yml" @@ -38,11 +39,6 @@ concurrency: group: ${{ github.workflow }}-upgrade-smoke-${{ github.ref }} cancel-in-progress: true -env: - GO_VERSION: "1.27.2" - NODE_VERSION: "24" - PNPM_VERSION: "11.0.1" - jobs: migration-upgrade: name: Upgrade from previous stable (${{ matrix.driver }}) @@ -56,11 +52,7 @@ jobs: uses: actions/checkout@v6 - name: Setup Go - uses: actions/setup-go@v6 - with: - go-version: ${{ env.GO_VERSION }} - cache: true - cache-dependency-path: go.sum + uses: ./.github/actions/setup-go - name: Test release versioning and installer run: go test -v ./scripts/... @@ -84,21 +76,8 @@ jobs: # tags, so it needs full history and tags. fetch-depth: 0 - - name: Setup pnpm - uses: pnpm/action-setup@v4.2.0 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - cache-dependency-path: web/pnpm-lock.yaml - - - name: Install frontend dependencies - working-directory: web - run: pnpm install --frozen-lockfile + - name: Setup web + uses: ./.github/actions/setup-web - name: Run release smoke test run: ./scripts/release_smoke_test.sh diff --git a/AGENTS.md b/AGENTS.md index da12b67a7..ae12e6ad1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -152,7 +152,9 @@ Black-box service tests live in `server/api/test/`, unit tests next to the code. - Docker excludes `.git`; pass `--build-arg VERSION="$(bash scripts/release_version.sh development-version)"` and `--build-arg COMMIT="$(git rev-parse HEAD)"` when building locally (build frontend assets first). -- Backend CI: Go 1.27.2, `go mod tidy -go=1.27.2`, `go fix -diff ./...`, golangci-lint v2.14.0 (including goimports), test groups +- Workflows install toolchains through `.github/actions/setup-go` (Go version from `go.mod`) and `.github/actions/setup-web` + (pnpm from `web/package.json`, Node 24, `pnpm install`); change versions there, not per workflow. +- Backend CI: Go 1.27.2, `go mod tidy`, `go fix -diff ./...`, golangci-lint v2.14.0 (including goimports), test groups `store`, `server`, `internal`, `other` (`cmd`, `core`, `markdown`, `filter`, `provider`, `proto`). - Frontend CI: Node 24, pnpm 11.0.1, `pnpm lint`, `pnpm test`, `pnpm build`. - Proto CI: `buf lint` and `buf format` check.