This file contains 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' | |
jobs: | |
update_forge-metadata: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@main | |
- name: Set time | |
shell: bash | |
run: | | |
sudo timedatectl set-timezone 'Asia/Shanghai' | |
- name: Set up Python | |
uses: actions/setup-python@main | |
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 | |
id: fetch_forge_changes | |
shell: bash | |
run: | | |
cd ./forge/scripts | |
python3 xml_to_json.py | |
python3 list.py | |
python3 install.py | |
python3 gettime.py | |
cp index.json ../ | |
cd ../.. | |
- name: Fetch optifine-metadata changes | |
id: fetch_optifine_changes | |
shell: bash | |
run: | | |
cd ./optifine/scripts | |
python3 main.py | |
cp index.json ../ | |
cd ../.. | |
- name: Save changes | |
id: save_changes | |
shell: bash | |
run: | | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git add -A | |
if git diff-index --quiet HEAD; then | |
# No changes | |
echo 'changed=false' >> $GITHUB_OUTPUT | |
else | |
# Changes detected | |
echo 'changed=true' >> $GITHUB_OUTPUT | |
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 | |
" | |
fi | |
- name: Push changes | |
if: steps.save_changes.outputs.changed == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} |