Skip to content

Update Exchange Rate #21

Update Exchange Rate

Update Exchange Rate #21

name: Update Exchange Rate
on:
schedule:
- cron: '30 1 * * *' # 每天UTC时间01:30,相当于北京时间09:30
workflow_dispatch: # 手动触发
permissions:
contents: write
jobs:
update-exchange-rate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install requests
- name: Fetch exchange rate from Alpha Vantage
env:
ALPHA_VANTAGE_API_KEY: ${{ secrets.ALPHA_VANTAGE_API_KEY }}
run: |
python update_exchange_rate.py
- name: Check for changes
id: check_changes
run: |
git fetch
git diff --exit-code > /dev/null || echo "has_changes=true" >> $GITHUB_ENV
- name: Commit and push changes
if: env.has_changes == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add exchange_rate.json
git commit -m "Update exchange rate"
git push origin HEAD:main