Skip to content

回退一下

回退一下 #559

Workflow file for this run

name: Build Check
permissions:
contents: read
actions: write
on:
push:
branches: ["**"]
paths:
- "frontend/**"
pull_request:
paths:
- "frontend/**"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
env:
NEXT_TELEMETRY_DISABLED: "1"
CI: "true"
steps:
- uses: actions/checkout@v4
# Enable corepack to ensure the exact pnpm version from package.json is used
- name: Enable Corepack
run: corepack enable
- uses: pnpm/action-setup@v4
with:
version: 10.20.0 # 明确指定版本或让它去 frontend/package.json 找
package_json_file: frontend/package.json
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 20
# 注意:这里不再使用 cache: pnpm,改为使用 pnpm action 自带的缓存或手动处理
# 使用 pnpm 官方推荐的缓存方式
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('frontend/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Verify pnpm version matches package.json packageManager field
- name: Check pnpm version
run: node scripts/check-pnpm-version.mjs
- run: pnpm install
# Verify lockfile wasn't modified by install
- name: Check lockfile consistency
run: |
if ! git diff --exit-code pnpm-lock.yaml; then
echo "❌ Error: pnpm-lock.yaml was modified after install"
echo "This indicates a pnpm version mismatch or corrupted lockfile"
echo ""
echo "Expected pnpm version from package.json:"
grep '"packageManager"' package.json | grep -o 'pnpm@[^"]*' || \
node -e "try { console.log(require('./package.json').packageManager || 'not specified') } catch(e) { console.log('Could not read') }" || \
echo "Could not extract version"
echo ""
echo "Actual pnpm version:"
pnpm --version || echo "pnpm not found"
exit 1
fi
echo "✅ Lockfile is consistent"
- run: pnpm run lint
- run: pnpm run lint:images
- run: pnpm run typecheck
# === IndexNow 提交(仅在 main 分支执行) ===
- name: Install jq (for JSON build)
if: github.ref == 'refs/heads/main'
run: sudo apt-get update && sudo apt-get install -y jq
- name: Submit IndexNow (changed URLs)
if: github.ref == 'refs/heads/main'
env:
SITE_ORIGIN: https://involutionhell.com
INDEXNOW_API: https://involutionhell.com/api/indexnow
INDEXNOW_API_TOKEN: ${{ secrets.INDEXNOW_API_TOKEN }}
run: |
set -euo pipefail
cd ..
git fetch --depth=2 origin ${{ github.ref }} || true
CHANGED="$(git diff --name-only HEAD~1 HEAD || true)"
CHANGED_DOCS="$(echo "$CHANGED" | grep -E '^frontend/(app/docs/|content/docs/).*\.(mdx?|tsx?)$' || true)"
URLS=()
while IFS= read -r f; do
[ -z "$f" ] && continue
if [[ "$f" =~ ^frontend/app/docs/(.*)/page\.(mdx|md|tsx|ts|jsx|js)$ ]]; then
slug="${BASH_REMATCH[1]}"
URLS+=("$SITE_ORIGIN/docs/$slug")
fi
done <<< "$CHANGED_DOCS"
while IFS= read -r f; do
[ -z "$f" ] && continue
if [[ "$f" =~ ^frontend/content/docs/(.*)\.(md|mdx)$ ]]; then
slug="${BASH_REMATCH[1]}"
slug="${slug%/index}"
URLS+=("$SITE_ORIGIN/docs/$slug")
fi
done <<< "$CHANGED_DOCS"
mapfile -t URLS < <(printf "%s\n" "${URLS[@]}" | awk 'NF' | sort -u)
if [ "${#URLS[@]}" -eq 0 ]; then
URLS=("$SITE_ORIGIN/")
fi
echo "✅ Submitting URLs to IndexNow:"
printf ' - %s\n' "${URLS[@]}"
JSON="$(jq -n --argjson arr "$(printf '%s\n' "${URLS[@]}" | jq -R . | jq -s .)" '{urlList: $arr}')"
AUTH_HEADER=()
if [ -n "${INDEXNOW_API_TOKEN:-}" ]; then
AUTH_HEADER=(-H "Authorization: Bearer ${INDEXNOW_API_TOKEN}")
fi
echo "📡 Sending request to $INDEXNOW_API ..."
RESPONSE=$(curl -sS -w "\nHTTP_STATUS=%{http_code}" -X POST "$INDEXNOW_API" \
-H "Content-Type: application/json" \
"${AUTH_HEADER[@]}" \
-d "$JSON")
BODY=$(echo "$RESPONSE" | sed -e 's/HTTP_STATUS=.*//g')
STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTP_STATUS=//')
echo "📥 API Response Status: $STATUS"
echo "📦 Response Body:"
echo "$BODY"
if [ "$STATUS" -ge 400 ]; then
echo "❌ IndexNow submission failed!"
exit 1
fi
echo "✅ IndexNow submission completed."