update-metadata #2410
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: update-metadata | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '* */12 * * *' # 每12个小时运行一次 | |
| push: | |
| paths: | |
| - '.github/workflows/update.yml' | |
| - '**.py' | |
| permissions: | |
| pages: write | |
| contents: write | |
| id-token: write | |
| jobs: | |
| update-metadata: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set time | |
| run: sudo timedatectl set-timezone 'Asia/Shanghai' | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: | | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install xmljson requests python-dateutil | |
| - name: Fetch forge-metadata changes | |
| run: | | |
| cd ./forge/scripts | |
| python3 xml_to_json.py | |
| python3 main.py | |
| python3 install.py | |
| python3 gettime.py | |
| mv index.json ../ | |
| - name: Fetch cleanroom-metadata changes | |
| run: | | |
| cd ./cleanroom/scripts | |
| python3 main.py | |
| mv index.json ../ | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Fetch optifine-metadata changes | |
| run: | | |
| cd ./optifine/scripts | |
| python3 main.py | |
| python3 converter.py | |
| mv index.json ../ | |
| - name: Commit changes | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes detected, skip commit and push." | |
| echo "SKIP=true" >> $GITHUB_ENV | |
| exit 0 | |
| fi | |
| git commit -m "Update metadata (`date '+%Y-%m-%d %H:%M:%S'` +0800) | |
| GitHub Action: https://github.com/${{ github.repository }}/actions/runs/$GITHUB_RUN_ID | |
| " | |
| git push origin | |
| - name: Build Pages | |
| if: ${{ env.SKIP != 'true' }} | |
| run: | | |
| mkdir -p /home/runner/gh-pages/{cleanroom,forge,optifine} | |
| mv ./cleanroom/index.json /home/runner/gh-pages/cleanroom/ | |
| mv ./cleanroom/files /home/runner/gh-pages/cleanroom/ | |
| mv ./fmllibs /home/runner/gh-pages/ | |
| mv ./forge/index.json /home/runner/gh-pages/forge/ | |
| mv ./optifine/index.json /home/runner/gh-pages/optifine/ | |
| - name: Upload Pages | |
| if: ${{ env.SKIP != 'true' }} | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| name: github-pages | |
| path: /home/runner/gh-pages | |
| - name: Deploy Pages | |
| if: ${{ env.SKIP != 'true' }} | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| with: | |
| artifact_name: github-pages |