【问题标题】:Committing python generated graphs to repo using github actions使用 github 操作将 python 生成的图提交到 repo
【发布时间】:2020-06-08 14:24:21
【问题描述】:

我正在尝试创建一个运行 python 脚本(输出三个图表)的 GitHub 工作流,将这些图表添加到 readme.md 然后将更改提交到 repo 并在自述文件页面上显示图表。我想触发新的推动。

作为一个 bash 脚本,它看起来像这样:

git pull
python analysis_1.py
git add .
git commit -m "triggered on action"
git push

我不确定从哪里开始或如何设置操作。我尝试设置一个,但它不会做出任何改变。

【问题讨论】:

  • 你能补充一些关于你到目前为止所尝试的细节吗?我认为您正在寻找的工具是一个“提交挂钩”,但有关您迄今为止的尝试的更多详细信息会有所帮助。
  • 是的,到目前为止,我一直在尝试使用 bash 脚本执行此操作,它会通过一个定时循环然后重复。该存储库包含几乎每天更新的 Python 脚本和其他数据,并且该脚本会根据我们希望始终保持最新的数据生成图表。问题在于它必须托管在某个地方。我的老板确实说过有一种方法可以在 github 中完成这一切,但我们都不知道该怎么做
  • 是的,Github 可以做到。我只是做了一个模糊的类似的事情。在推送时,我更改了 Jupyter 笔记本中的设置,并在最后添加了一些单元格。请参阅here,但公平的警告看起来很复杂,因为我在不同的分支中进行更改。请参阅here,了解我只是在复制笔记本并对其进行更改之前,但那是在我意识到我不需要 dockerfile 来运行 Python 脚本之前。

标签: python git github github-actions


【解决方案1】:

请参阅this answer,了解如何在工作流程中提交回您的存储库。

在您的情况下,它可能看起来像这样。必要时进行调整。

on:
  push:
    branches:
      - master
jobs:
  updateGraphs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v1
        with:
          python-version: '3.x'

      - name: Generate graphs
        run: python analysis_1.py

      - name: Update graphs
        run: |
          git config --global user.name 'Your Name'
          git config --global user.email 'your-username@users.noreply.github.com'
          git commit -am "Update graphs"
          git push

或者,使用create-pull-request 操作提出拉取请求,而不是立即提交。

on:
  push:
    branches:
      - master
jobs:
  updateGraphs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v1
        with:
          python-version: '3.x'

      - name: Generate graphs
        run: python analysis_1.py

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Update graphs
          title: Update graphs
          branch: update-graphs

【讨论】:

  • 设置这些后,我不断收到错误,它在第 1 行失败
猜你喜欢
  • 2021-07-07
  • 2012-03-13
  • 2020-11-17
  • 1970-01-01
  • 2013-10-13
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
相关资源
最近更新 更多