Github 操作不会提交更改

Github Actions won't commit changes

我正在尝试实现一个 Github 操作,它将 运行 一个创建 Markdown 文件的 python 脚本,将更改提交到一个新分支并最终创建一个拉取从这个新分支请求到 main。

现在它创建 MD 文件,创建分支但没有提交更改。

我不知道工作流程有什么问题,也许有人可以帮助我。

name: get_repo_admins_list

on: [push]
  # schedule:
  #   - cron: '0 08 * * 1' # runs at 08:00 UTC on Mondays

jobs:
  updatelist:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Install reqs
        run: pip install -r requirements.pip

      - name: Run script
        shell: bash
        run: ./devops/scripts/get_repo_admins.py -at ${{ secrets.GITHUB_TOKEN }}

      - name: Create new Branch
        uses: EndBug/add-and-commit@v9
        with:
          default_author: github_actions
          message: '[Misc] Update repository admin list documentation'
          new_branch: scriptupdate/updated-admin-list
          
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "[Misc] Update repository admin list documentation"
          committer: GitHub <noreply@github.com>
          author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
          signoff: false
          base: main
          branch: scriptupdate/updated-admin-list
          title: '[Misc] Update repository admin list documentation'
          body: |
            Workflow script has made changes to admin list
          reviewers: someuser
          draft: false

python脚本运行正常,但如果有人需要检查,我可以post它。

尝试将此添加到您的结帐步骤:

- name: Checkout Repository
  uses: actions/checkout@v3
  with:
    repository: ${{ github.event.pull_request.head.repo.full_name }}
    ref: ${{ github.event.pull_request.head.ref }}

根据 their documentation,您需要指定一个 ref 才能在 non-detached 状态下检出您的存储库。

另外,通过阅读他们的文档,我建议添加 push 输入:

push: origin scriptupdate/updated-admin-list --set-upstream --force

如果你打算使用这个分支multiple times

谢谢大家的解答!

因为用peter-evans/create-pull-request@v4动作实现不了,所以用CURL实现了。

感谢 Ondrej Tuma 的回答。它对我的提交和添加操作帮助很大!

这是我的最终代码:

name: get_repo_admins_list

on: [push]
  # schedule:
  #   - cron: '0 08 * * 1' # runs at 08:00 UTC on Mondays

jobs:
  updatelist:
    runs-on: ubuntu-latest

steps:
  - name: Checkout Repository
    uses: actions/checkout@v3
    with:
      repository: ${{ github.event.pull_request.head.repo.full_name }}
      ref: ${{ github.event.pull_request.head.ref }}

  - name: Install reqs
    run: pip install -r requirements.pip         

  - name: Run script
    shell: bash
    run: ./devops/scripts/get_repo_admins.py -at ${{ secrets.GITHUB_TOKEN }}

  - name: Create branch and commit
    uses: EndBug/add-and-commit@v9
    with:
      add: './REPOADMINS.md'
      default_author: github_actions
      message: '[Misc] Update repository admin list documentation'
      new_branch: scriptupdate/updated-admin-list
      push: origin scriptupdate/updated-admin-list --set-upstream --force

  - name: Create Pull Request
    shell: bash
    run: |
      curl \
      -X POST \
      -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
      -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/repos/(USER)/(REPO)/pulls \
      -d '{"title":"[Misc] Update repository admin list documentation","body":"Adminlist updated!","head":"scriptupdate/updated-admin-list","base":"main"}