Refactor auto-update workflow and metadata logic #5
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 Project Metadata | |
| on: | |
| push: | |
| branches: | |
| - main | |
| # 確保同一個分支上,一次只有一個工作流程在運行 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| update-metadata: | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| # 獲取所有歷史紀錄,以便腳本可以比較 commits | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run update script | |
| id: run_script | |
| run: node scripts/update-projects.js | |
| env: | |
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
| - name: Commit and Push Results | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # 只需要檢查 metadata.json 是否有變動 | |
| if git diff --quiet metadata.json; then | |
| echo "✅ metadata.json is up to date. No changes to commit." | |
| else | |
| git add metadata.json | |
| # 在 commit message 中加入 [skip ci] 來防止無限循環 | |
| git commit -m "chore(bot): auto-update project metadata [skip ci]" | |
| git push | |
| echo "🚀 Committed and pushed updated metadata.json" | |
| fi |