github - 如何从 master 以外的分支运行 GitHub Action?

标签 github github-actions

我在 GitHub 中有一个 repo,我想创建一个 Action 来构建 Docker 镜像并将其推送到 DockerHub。我知道该怎么做,但是:如果我在 master GitHub 以外的分支中创建操作,则不会运行它。
这是一个已知问题( Workflow files only picked up from master? )。
任何想法来解决它?

最佳答案

根据官方 GitHub Actions 文档(About workflow events):

The following steps occur to trigger a workflow run:

  1. An event occurs on your repository, and the resulting event webhook has an associated commit SHA and Git ref.

  2. The .github/workflows directory in your repository is searched for workflow files at the associated commit SHA or Git ref. The workflow files must be present in that commit SHA or Git ref to be considered.

    For example, if the event occurred on a particular repository branch, then the workflow files must be present in the repository on that branch.

  3. The workflow files for that commit SHA and Git ref are inspected, and a new workflow run is triggered for any workflows that have on: values that match the triggering event.

    The workflow runs on your repository's code at the same commit SHA and Git ref that triggered the event. When a workflow runs, GitHub sets the GITHUB_SHA (commit SHA) and GITHUB_REF (Git ref) environment variables in the runner environment. For more information, see "Using environment variables."


因此,为了测试工作流,我们需要在创建的分支中执行 git 操作(即 do push )。

关于github - 如何从 master 以外的分支运行 GitHub Action?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63480433/

相关文章:

github - 如何通过 ssh 将 docker-compose 解决方案从 github 自动部署到 vps?

带有 Github Actions 和 FaSTLane 的 Android CI/CD

terraform - 配置 Terraform AWS Provider 时的 Github Actions 错误

github - 如何在github操作中访问github标签消息

github - github 操作运行名称中的求和表达式

git - 在另一台计算机上使用 Github

Git checkout --补丁

ruby - 使用 Chef 从 Github 存储库安装 Ruby gem?

Git 将功能分支的历史更改为新分支?

git - 使用 Github Action 更新 README 失败