Github 操作,执行创建文件的 Python 脚本,然后提交并推送该文件

sho*_*ora 4 python github-actions

我的存储库包含main.py生成 html 地图并将结果保存在 csv 中的 a。我希望该行动:

  1. 执行python脚本(->这似乎没问题)
  2. 生成的文件将位于存储库中,因此生成的文件将被添加、提交并推送到主分支,以便在与存储库关联的页面中可用。

name: refresh map

on:
  schedule:
    - cron: "30 11 * * *"    #runs at 11:30 UTC everyday

jobs:
  getdataandrefreshmap:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo content
        uses: actions/checkout@v3 # checkout the repository content to github runner.
      - name: setup python
        uses: actions/setup-python@v4
        with:
          python-version: 3.8 #install the python needed
      - name: Install dependencies
        run: |
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: execute py script
        uses: actions/checkout@v3
        run: |
          python main.py
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add .
          git commit -m "crongenerated"
          git push
Run Code Online (Sandbox Code Playgroud)

uses: actions/checkout@v3当我包含第二个和 git 命令时,github-action 不会通过。

在此先感谢您的帮助

小智 5

如果您想运行脚本,则不需要额外的签出步骤。使用工作流的步骤和直接执行 shell 脚本的步骤之间存在差异。你可以在这里读更多关于它的内容。

在您的配置文件中,您在最后一步中混合了两者。您不需要额外的签出步骤,因为第一步中的存储库仍会签出。因此,您可以使用以下工作流程:

name: refresh map

on:
  schedule:
    - cron: "30 11 * * *"    #runs at 11:30 UTC everyday

jobs:
  getdataandrefreshmap:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo content
        uses: actions/checkout@v3 # checkout the repository content to github runner.
      - name: setup python
        uses: actions/setup-python@v4
        with:
          python-version: 3.8 #install the python needed
      - name: Install dependencies
        run: |
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: execute py script
        run: |
          python main.py
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add .
          git commit -m "crongenerated"
          git push

Run Code Online (Sandbox Code Playgroud)

我用虚拟仓库对其进行了测试,一切正常。