Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/azure-deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Azure Static Web Apps CI/CD - Docs

on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- main

jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job Docs
permissions:
contents: read
env:
NODE_VERSION: "20"
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Install playwright browsers
run: npx playwright install --with-deps

- name: Build docs
run: NODE_ENV=production npm run build
env:
CLARITY_PROJECT_ID: ${{ secrets.CLARITY_PROJECT_ID }}

- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ASHY_FLOWER_DOCS }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "dist"
api_location: ""
skip_app_build: true

close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ASHY_FLOWER_DOCS }}
action: "close"
232 changes: 232 additions & 0 deletions .github/workflows/version-monitor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
name: Version Monitor

# Trigger the workflow every 30 minutes and allow manual triggering
on:
push:
branches:
- main
schedule:
- cron: "*/30 * * * *" # Run every 30 minutes
workflow_dispatch: # Allow manual trigger from GitHub Actions UI

# Set permissions for creating branches, commits, and pull requests
permissions:
contents: write
pull-requests: write

jobs:
monitor:
name: Monitor Version Changes
runs-on: ubuntu-latest
outputs:
update_needed: ${{ steps.monitor.outputs.update_needed }}
new_version: ${{ steps.monitor.outputs.new_version }}
pr_created: ${{ steps.pr.outputs.pr_created }}
pr_url: ${{ steps.pr.outputs.pr_url }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Display configuration
run: |
echo "Version Monitor Configuration"
echo "=========================="
echo "Source URL: ${{ vars.VERSION_SOURCE_URL || 'https://desktop.dl.hagicode.com/index.json' }}"
echo "Request Timeout: 30000ms"
echo "Max Retries: 3"
echo "Repository: ${{ github.repository }}"

- name: Run version monitor
id: monitor
run: node scripts/version-monitor.js
env:
VERSION_SOURCE_URL: ${{ vars.VERSION_SOURCE_URL || 'https://desktop.dl.hagicode.com/index.json' }}
REQUEST_TIMEOUT: "30000"
MAX_RETRIES: "3"

- name: Configure Git
if: steps.monitor.outputs.update_needed == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Check existing branch
id: check_branch
if: steps.monitor.outputs.update_needed == 'true'
run: |
BRANCH_NAME="version-update-${{ steps.monitor.outputs.new_version }}"
echo "Checking for existing branch: $BRANCH_NAME"
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
echo "branch_exists=true" >> $GITHUB_OUTPUT
echo "Branch $BRANCH_NAME already exists on remote"
else
echo "branch_exists=false" >> $GITHUB_OUTPUT
echo "Branch $BRANCH_NAME does not exist on remote"
fi

- name: Create feature branch
if: steps.monitor.outputs.update_needed == 'true' && steps.check_branch.outputs.branch_exists != 'true'
run: |
BRANCH_NAME="version-update-${{ steps.monitor.outputs.new_version }}"
git checkout -b "$BRANCH_NAME"
echo "Created branch: $BRANCH_NAME"

- name: Commit version changes
if: steps.monitor.outputs.update_needed == 'true' && steps.check_branch.outputs.branch_exists != 'true'
run: |
git add public/version-index.json
git commit -m "chore: update version to ${{ steps.monitor.outputs.new_version }}"

- name: Push branch
if: steps.monitor.outputs.update_needed == 'true' && steps.check_branch.outputs.branch_exists != 'true'
run: |
BRANCH_NAME="version-update-${{ steps.monitor.outputs.new_version }}"
git push origin "$BRANCH_NAME"

- name: Check existing PR
id: check_pr
if: steps.monitor.outputs.update_needed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURRENT_VERSION: ${{ steps.monitor.outputs.new_version }}
run: |
echo "Checking for existing PR for version: ${CURRENT_VERSION}"
EXISTING_PR=$(gh pr list \
--search "chore: update version to ${CURRENT_VERSION} in:head" \
--state open \
--json number,title \
--jq '.[0]')

if [ -n "$EXISTING_PR" ]; then
PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
PR_TITLE=$(echo "$EXISTING_PR" | jq -r '.title')
echo "pr_exists=true" >> $GITHUB_OUTPUT
echo "existing_pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "existing_pr_url=$(gh pr view $PR_NUMBER --json url -q .url)" >> $GITHUB_OUTPUT
echo "Found existing PR: #$PR_NUMBER - $PR_TITLE"
else
echo "pr_exists=false" >> $GITHUB_OUTPUT
echo "No existing PR found for version ${CURRENT_VERSION}"
fi
Comment on lines +100 to +118
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

GitHub CLI gh pr list search qualifiers valid options

💡 Result:

gh pr list --search "<query>" accepts the same GitHub “issues & pull requests” search syntax (qualifiers) you use on GitHub.com. [1][2]

Common PR search qualifiers (valid in --search)

Scope / state

  • is:pr (often implied for gh pr list, but useful when combining terms) [2]
  • state:open / state:closed (also is:open / is:closed) [2]
  • is:merged / is:unmerged [3]
  • is:queued (in merge queue) [2]

Draft / review / CI

  • draft:true / draft:false (also commonly is:draft) [4][5]
  • review:none | required | approved | changes_requested [4][5]
  • reviewed-by:USER, review-requested:USER, user-review-requested:@me``, team-review-requested:ORG/TEAM [4][5]
  • status:success | failure | pending [5]

Branches / commits

  • head:BRANCHPREFIX, base:BRANCH [6]
  • <SHA> (commit SHA prefix) [6]

People / metadata

  • author:USER (including author:@me``, author:app/APPNAME) [2]
  • assignee:USER, mentions:USER, commenter:USER, involves:USER, team:ORG/TEAM [2][5]
  • label:"name", milestone:"name" [2]
  • linked:issue (PRs linked to an issue they may close) [5]
  • archived:true|false [3]

Dates / sorting / counts

  • merged:>=YYYY-MM-DD (ISO date; supports >, <, ranges, optional time) [3]
  • comments:>N, plus created:, updated:, closed: (date qualifiers) [3]
  • sort:created-asc (and other sort: options) [5]

Examples

  • Needs review + CI green: gh pr list --search "review:required status:success" [1][4][5]
  • Your review requests: gh pr list --search "is:open user-review-requested:@me" [4]
  • Targeting main from feature branches: gh pr list --search "base:main head:feature-" [6]
  • Merged since Jan 1, 2026: gh pr list --search "is:merged merged:>=2026-01-01" [3]

Tip: gh pr list also has dedicated flags (e.g., --author, --assignee, --base, --head, --draft) that overlap with some qualifiers. [1]


🌐 Web query:

GitHub search qualifier "in:title" "in:body" "in:comments" pull requests valid

💡 Result:

Yes—in:title, in:body, and in:comments are valid GitHub Issues & Pull Requests search qualifiers, and they work for pull requests as long as you restrict the search to PRs with is:pr (or type:pr). GitHub documents these under “Searching issues and pull requests” → “Search by the title, body, or comments.” [1]

Examples:

  • Search PR titles only: is:pr in:title "my phrase" [1]
  • Search PR bodies only: is:pr in:body "my phrase" [1]
  • Search PR comments only: is:pr in:comments "my phrase" [1]
  • Combine fields: is:pr "my phrase" in:title,body [1]

Sources:
[1] GitHub Docs — “Searching issues and pull requests” (sections: “Search only issues or pull requests” and “Search by the title, body, or comments”). (docs.github.com)

Citations:


🌐 Web query:

GitHub search qualifier "in:head" pull requests

💡 Result:

in:head is not a valid GitHub qualifier for searching pull requests.

In issues/PR search, the in: qualifier only limits where text is searched (e.g. in:title, in:body, in:comments). [1]

To search PRs by branch, use these PR-specific qualifiers instead: [1]

  • Head branch (source/from branch): head:<branch>
  • Base branch (target/into branch): base:<branch>

Examples:

  • PRs opened from branch feature/login (in any repo you can access):
    is:pr head:feature/login
  • PRs opened into main in a specific repo:
    repo:OWNER/REPO is:pr base:main

Sources
[1] GitHub Docs — “Searching issues and pull requests” (includes in: and head:/base: qualifiers) (docs.github.com)

Citations:


🏁 Script executed:

git ls-files .github/workflows/version-monitor.yml | head -1 | xargs wc -l

Repository: HagiCode-org/docs

Length of output: 102


🏁 Script executed:

sed -n '120,140p' .github/workflows/version-monitor.yml

Repository: HagiCode-org/docs

Length of output: 985


in:head is not a valid GitHub search qualifier — fix to use in:title to prevent duplicate PRs.

The search qualifier in:head is not recognized by GitHub's search API. Valid in: qualifiers are limited to in:title, in:body, and in:comments. When using invalid qualifiers, GitHub treats them as literal search text rather than filters, causing the query to fail silently and never match existing PRs. This will cause the workflow to create duplicate version-update PRs.

Update both occurrences:

Line ~104
-          EXISTING_PR=$(gh pr list \
-            --search "chore: update version to ${CURRENT_VERSION} in:head" \
+          EXISTING_PR=$(gh pr list \
+            --search "chore: update version to ${CURRENT_VERSION} in:title" \
             --state open \
Line ~129
-          PREVIOUS_PRS=$(gh pr list \
-            --search "chore: update version to in:head" \
+          PREVIOUS_PRS=$(gh pr list \
+            --search "chore: update version to in:title" \
             --state open \
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: |
echo "Checking for existing PR for version: ${CURRENT_VERSION}"
EXISTING_PR=$(gh pr list \
--search "chore: update version to ${CURRENT_VERSION} in:head" \
--state open \
--json number,title \
--jq '.[0]')
if [ -n "$EXISTING_PR" ]; then
PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
PR_TITLE=$(echo "$EXISTING_PR" | jq -r '.title')
echo "pr_exists=true" >> $GITHUB_OUTPUT
echo "existing_pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "existing_pr_url=$(gh pr view $PR_NUMBER --json url -q .url)" >> $GITHUB_OUTPUT
echo "Found existing PR: #$PR_NUMBER - $PR_TITLE"
else
echo "pr_exists=false" >> $GITHUB_OUTPUT
echo "No existing PR found for version ${CURRENT_VERSION}"
fi
run: |
echo "Checking for existing PR for version: ${CURRENT_VERSION}"
EXISTING_PR=$(gh pr list \
--search "chore: update version to ${CURRENT_VERSION} in:title" \
--state open \
--json number,title \
--jq '.[0]')
if [ -n "$EXISTING_PR" ]; then
PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
PR_TITLE=$(echo "$EXISTING_PR" | jq -r '.title')
echo "pr_exists=true" >> $GITHUB_OUTPUT
echo "existing_pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "existing_pr_url=$(gh pr view $PR_NUMBER --json url -q .url)" >> $GITHUB_OUTPUT
echo "Found existing PR: #$PR_NUMBER - $PR_TITLE"
else
echo "pr_exists=false" >> $GITHUB_OUTPUT
echo "No existing PR found for version ${CURRENT_VERSION}"
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/version-monitor.yml around lines 100 - 118, The GH search
uses an invalid qualifier "in:head" causing missed matches; update the --search
argument used in the gh pr list command to replace "in:head" with "in:title"
(e.g., change the search string "chore: update version to ${CURRENT_VERSION}
in:head" to "chore: update version to ${CURRENT_VERSION} in:title"), and make
the same replacement for the other occurrence of that search pattern elsewhere
in the workflow so existing version PRs are correctly detected.


- name: Close previous version PRs
id: close_prs
if: steps.monitor.outputs.update_needed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURRENT_VERSION: ${{ steps.monitor.outputs.new_version }}
run: |
echo "Closing previous version PRs (excluding current version: ${CURRENT_VERSION})..."
PREVIOUS_PRS=$(gh pr list \
--search "chore: update version to in:head" \
--state open \
--json number,title \
--jq '.[] | select(.title != "chore: update version to '"${CURRENT_VERSION}"'") | .number')

if [ -n "$PREVIOUS_PRS" ]; then
echo "$PREVIOUS_PRS" | while read -r pr_number; do
echo "Closing PR #$pr_number"
gh pr close "$pr_number" --comment "由于新的版本更新 PR 自动关闭"
done
else
echo "No previous version PRs to close"
fi

- name: Create Pull Request
id: pr
if: steps.monitor.outputs.update_needed == 'true' && steps.check_pr.outputs.pr_exists != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION="${{ steps.monitor.outputs.new_version }}"
BRANCH_NAME="version-update-${NEW_VERSION}"
PR_BODY="## Version Update

This PR updates the version index to reflect the new version detected from the official website.

- **New Version**: ${NEW_VERSION}
- **Source**: ${{ vars.VERSION_SOURCE_URL || 'https://desktop.dl.hagicode.com/index.json' }}
- **Checked At**: $(date -u +"%Y-%m-%dT%H:%M:%SZ")

### Changes
- Updated \`public/version-index.json\` with the latest version data from online API

### Next Steps
After merging this PR, the CI/CD pipeline will automatically rebuild and deploy the documentation site with the updated version information.

---
_This PR was automatically created by the [Version Monitor](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow._"

gh pr create \
--title "chore: update version to ${NEW_VERSION}" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME" \
--label "automation,version"

echo "pr_created=true" >> $GITHUB_OUTPUT
echo "pr_url=$(gh pr view --json url -q .url)" >> $GITHUB_OUTPUT

- name: Display result
if: always()
run: |
echo "Version Monitor Result"
echo "======================"
echo "Update Needed: ${{ steps.monitor.outputs.update_needed }}"
echo "New Version: ${{ steps.monitor.outputs.new_version }}"
echo "Branch Exists: ${{ steps.check_branch.outputs.branch_exists }}"
echo "PR Exists: ${{ steps.check_pr.outputs.pr_exists }}"
echo "PR Created: ${{ steps.pr.outputs.pr_created }}"
if [ "${{ steps.check_pr.outputs.pr_exists }}" == "true" ]; then
echo "Existing PR: #${{ steps.check_pr.outputs.existing_pr_number }}"
echo "Existing PR URL: ${{ steps.check_pr.outputs.existing_pr_url }}"
else
echo "PR URL: ${{ steps.pr.outputs.pr_url }}"
fi

notify-version-update:
needs: monitor
if: needs.monitor.outputs.pr_created == 'true'
runs-on: ubuntu-latest
steps:
- uses: HagiCode-org/haginotifier@v1
with:
msg_type: 'post'
title: 'Version Monitor'
message: |
## Version Monitor

**状态**: 🔄 发现新版本
**新版本**: ${{ needs.monitor.outputs.new_version }}
**仓库**: ${{ github.repository }}
**PR 链接**: ${{ needs.monitor.outputs.pr_url }}
**运行详情**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
env:
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}

notify-failure:
needs: monitor
if: failure()
runs-on: ubuntu-latest
steps:
- uses: HagiCode-org/haginotifier@v1
with:
msg_type: 'post'
title: 'Version Monitor'
message: |
## Version Monitor

**状态**: ❌ 失败
**仓库**: ${{ github.repository }}
**触发者**: ${{ github.actor }}
**运行详情**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
env:
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Dependencies
node_modules/
.pnp/
.pnp.js

# Turbo
.turbo/

# Testing
coverage/

# Production
build/
.dist/
dist/

# Misc
.DS_Store
*.pem

# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Local env files
.env
.env.local
.env.*.local

# Docusaurus
.docusaurus/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
Thumbs.db

.claude/skills/ui-ux-pro-max/scripts/__pycache__/
.astro/
tsconfig.tsbuildinfo
Loading