簡體   English   中英

Github 執行創建文件的 Python 腳本,然后提交並推送該文件

[英]Github action to execute a Python script that create a file, then commit and push this file

我的 repo 包含一個main.py ,它生成一個 html map 並將結果保存在 csv 中。我希望操作:

  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

當我包含第二次uses: actions/checkout@v3和 git 命令。

在此先感謝您的幫助

如果你想運行一個腳本,那么你不需要額外的檢查步驟。 使用工作流的步驟和直接執行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

我用一個虛擬倉庫測試了它,一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM