如果您有名称相同的检查和状态,并且选择该名称作为必需状态检查,则检查和状态都是必需的。 更多信息请参阅“检查”。
在启用必需状态检查后,您的分支在合并之前可能需要使用基础分支更新。 这可确保您的分支已经使用基本分支的最新代� �做过测试。 如果您的分支过期,则需要将基本分支合并到您的分支。 更多信息请参阅“关于受保护分支”。
注:您也可以使用 Git 变基以基础分支更新您的分支。 更多信息请参阅“关于 Git 变基”。
在通过所有必需状态检查之前,� 法向受保护分支推送本地更改。 反而会收到类似如下的错误消息。
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Required status check "ci-build" is failing
注:最新且通过必需状态检查的拉取请求可以本地合并,并且推送到受保护分支。 此操作� 需对合并提交本身运行状态检查。
Conflicts between head commit and test merge commit
有时,测试合并提交与头部提交的状态检查结果存在冲突。 如果测试合并提交具有状态,则测试合并提交必须通过。 否则,必须� 递头部提交的状态后才可合并该分支。 有关测试合并提交的更多信息,请参阅“拉取”。
Handling skipped but required checks
Sometimes a required status check is skipped on pull requests due to path filtering. For example, a Node.JS test will be skipped on a pull request that just fixes a typo in your README file and makes no changes to the JavaScript and TypeScript files in the scripts
directory.
If this check is required and it gets skipped, then the check's status is shown as pending, because it's required. In this situation you won't be able to merge the pull request.
示例
In this example you have a workflow that's required to pass.
name: ci
on:
pull_request:
paths:
- 'scripts/**'
- 'middleware/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js $
uses: actions/setup-node@v2
with:
node-version: $
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
If someone submits a pull request that changes a markdown file in the root of the repository, then the workflow above won't run at all because of the path filtering. As a result you won't be able to merge the pull request. You would see the following status on the pull request:
You can fix this by creating a generic workflow, with the same name, that will return true in any case similar to the workflow below :
name: ci
on:
pull_request:
paths-ignore:
- 'scripts/**'
- 'middleware/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: 'echo "No build required" '
Now the checks will always pass whenever someone sends a pull request that doesn't change the files listed under paths
in the first workflow.
注意:
- Make sure that the
name
key and required job name in both the workflow files are the same. For more information, see "Workflow syntax for GitHub Actions". - The example above uses GitHub Actions but this workaround is also applicable to other CI/CD providers that integrate with GitHub.