From dac56fc9fa0937034612e48e0a2243e690bd8145 Mon Sep 17 00:00:00 2001 From: qqhsx <56535272+qqhsx@users.noreply.github.com> Date: Sat, 25 May 2024 09:16:24 +0800 Subject: [PATCH] Update main.yml --- .github/workflows/main.yml | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index df9d905d..87faebe8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,24 +1,25 @@ -name: Run Python Script +name: Run Python Script and Commit CSV on: push: branches: - - main + - main # 触发动作的分支 schedule: - # 每天运行一次,可以按需调整 + # 每天UTC时间00:00运行,按需调整 - cron: '0 0 * * *' jobs: - build: + build-and-commit-csv: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.8' # 你使用的 Python 版本 - + python-version: '3.8' # 你的 Python 版本 + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -28,8 +29,18 @@ jobs: run: | python -c "import pywencai; res = pywencai.get(question='退市股票', loop=True); res.to_csv('问财.csv', index=False, encoding='utf-8-sig'); print(res)" - - name: Upload result + - name: Upload CSV as Artifact uses: actions/upload-artifact@v2 with: name: wencai-results path: 问财.csv + + - name: Commit and Push CSV to Repository + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -f 问财.csv + git commit -m 'Automatically update and commit 问财.csv' || echo "No changes to commit" + git push origin HEAD:${{ github.ref }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}