Auto Update Catalog Daily #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Update Catalog Daily | |
| on: | |
| schedule: | |
| # Runs at 00:00 UTC every day. | |
| # This corresponds to 08:00 AM UTC+8 (Beijing time) every day. | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| jobs: | |
| auto-update-catalog: | |
| if: github.repository == 'CherryHQ/cherry-studio' | |
| runs-on: ubuntu-latest | |
| name: Auto Update Catalog | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: 🐈⬛ Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: 📦 Setting Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: 📦 Install pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: 📂 Get pnpm store directory | |
| id: pnpm-cache | |
| shell: bash | |
| run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT | |
| - name: 💾 Cache pnpm dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm- | |
| - name: 📦 Install dependencies | |
| run: | | |
| pnpm install | |
| - name: 🏃♀️ Generate catalog | |
| run: pnpm --filter @cherrystudio/provider-registry generate | |
| - name: 🔍 Check for changes | |
| id: git_status | |
| run: | | |
| git diff --exit-code --quiet -- packages/provider-registry/data || echo "::set-output name=has_changes::true" | |
| git status --porcelain -- packages/provider-registry/data | |
| - name: 📅 Set current date for PR title | |
| id: set_date | |
| run: echo "CURRENT_DATE=$(date +'%b %d, %Y')" >> $GITHUB_ENV # e.g., "Jun 06, 2024" | |
| - name: 🚀 Create Pull Request if changes exist | |
| if: steps.git_status.outputs.has_changes == 'true' | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| token: ${{ secrets.TOKEN_GITHUB_WRITE }} # PAT so the bot PR triggers CI (GITHUB_TOKEN would not) | |
| commit-message: "feat(bot): Daily automated catalog update" | |
| title: "🤖 Daily Auto Catalog Update: ${{ env.CURRENT_DATE }}" | |
| body: | | |
| This PR includes model/provider catalog changes generated by the daily auto update. | |
| Review the changes before merging. | |
| --- | |
| _Generated by the automated daily workflow_ | |
| add-paths: packages/provider-registry/data | |
| branch: "auto-update-catalog-daily" # Stable branch so an open catalog PR is updated, not duplicated | |
| base: "main" # Or 'develop', set your base branch | |
| delete-branch: true # Delete the branch after merging or closing the PR | |
| - name: 📢 Notify if no changes | |
| if: steps.git_status.outputs.has_changes != 'true' | |
| run: echo "Bot script ran, but no changes were detected. No PR created." | |
| - name: Send failure notification to Feishu | |
| if: always() && (failure() || cancelled()) | |
| shell: bash | |
| env: | |
| FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }} | |
| FEISHU_WEBHOOK_SECRET: ${{ secrets.FEISHU_WEBHOOK_SECRET }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| JOB_STATUS: ${{ job.status }} | |
| run: | | |
| # Determine status and color | |
| if [ "$JOB_STATUS" = "cancelled" ]; then | |
| STATUS_TEXT="已取消" | |
| COLOR="orange" | |
| else | |
| STATUS_TEXT="失败" | |
| COLOR="red" | |
| fi | |
| # Build description using printf | |
| DESCRIPTION=$(printf "**状态:** %s\n\n**工作流:** [查看详情](%s)" "$STATUS_TEXT" "$RUN_URL") | |
| # Send notification | |
| pnpm tsx scripts/feishu-notify.ts send \ | |
| -t "自动 Catalog 更新${STATUS_TEXT}" \ | |
| -d "$DESCRIPTION" \ | |
| -c "${COLOR}" |