【问题标题】:Github protected branch hook declined even with allow force pushes即使允许强制推送,Github 保护的分支钩子也会下降
【发布时间】:2022-11-13 08:31:34
【问题描述】:

我的测试分支有一个分支保护,但我需要执行每个拉取请求合并一个操作以更新软件版本并在测试分支中提交。

即使有标签 - 力量出现错误:

INPUT_TAGGING_MESSAGE: 
No tagging message supplied. No tag will be added.
INPUT_PUSH_OPTIONS: --force
remote: error: GH006: Protected branch update failed for refs/heads/test.        
remote: error: Changes must be made through a pull request.        
 ! [remote rejected] HEAD -> test (protected branch hook declined)
error: failed to push some refs to 'https://github.com/***/***'
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

我允许每个人在这个分支中用力推动:

我的工作流程操作:

name: Version Update

on:
  pull_request:
    branches: 
      - master
      - test
    types: [closed]

jobs:
  version_update:
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.1'
    - name: Get branch name
      id: branch-name
      uses: tj-actions/branch-names@v6
    - uses: actions/checkout@v3
      with:
        ref: ${{ steps.branch-name.outputs.base_ref_branch }}
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Generate key
      run: php artisan key:generate
    - name: Update Patch Version
      if: steps.branch-name.outputs.current_branch != 'test'
      run: php artisan version:patch
    - name: Update Minor Version
      if: steps.branch-name.outputs.current_branch == 'test'
      run: php artisan version:minor
    - name: Update Timestamp
      run: php artisan version:timestamp
    - name: Update Commit
      run: php artisan version:absorb
    - name: Commit changes
      uses: stefanzweifel/git-auto-commit-action@v4
      with:
        commit_message: "version: update patch"
        branch: ${{ steps.branch-name.outputs.base_ref_branch }}
        push_options: '--force'

【问题讨论】:

  • 推送时消息的剩余部分是什么?通常,您会看到原因为什么那里。
  • 错误消息是:“必须通过拉取请求进行更改。”
  • 我猜这必须为分支设置某个地方。
  • 这些 GitHub 设置对我来说很合适,但我不是 GitHub 专家。请注意,您无法设置任何内容吉特为此,这完全是在 Git 上中心事情的一面。

标签: github github-actions git-branch


【解决方案1】:

如果分支保护处于活动状态并且选项“合并前需要拉取请求”被标记,这将阻止任何推送,即使使用 --force 去你的受保护分支。

在 github 中,使用“合并前需要拉取请求”选项来推送分支是不可能的

我对这个问题的解决方案是在没有这个选项的情况下工作。

【讨论】:

    【解决方案2】:

    在“合并前需要拉取请求”下嵌套了一个“允许指定的参与者绕过所需的拉取请求”选项。启用它并输入用于运行操作的用户,因为异常对我有用。

    请注意,我们将 GitHub 应用程序身份创建为“异常用户”,将其添加到异常列表并使用它来运行工作流(我们使用 https://github.com/getsentry/action-github-app-token 从 GitHub 应用程序加载令牌以运行工作流),因为我们不知道如何引用“用于运行操作工作流的默​​认用户”。

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 1970-01-01
      • 2021-06-11
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多