问题描述
我在.github/workflows
中的build_and_test.yml
文件如下:
name: CI
on:
push:
branches:
- main
- name-of-my-branch
pull_request:
branches:
- main
jobs:
build:
# Code to build
但是,当我推送到main
分支以外的任何分支时,构建不会触发.任何想法为什么会这样?
However, when I push to any branch other than the main
branch, the build doesn't trigger. Any ideas why this might be?
推荐答案
我意识到此Github Actions文件位于主分支上,并且Github 使用为要推送的分支配置的操作强>.如果name-of-my-branch
在其.github/workflows/build_and_test.yml
中指定了不同的on: push: branches:
,则不会执行任何操作.因此,main
分支中的branches: name-of-my-branch
有点欺骗性-仅当该分支在其自己的.yml
中的push
下指定时,才会发生推入式构建.
I realized that this Github Actions file was on the main branch, and Github uses the actions that are configured for the branch that is getting pushed. It doesn't do anything if name-of-my-branch
has different on: push: branches:
specified in its .github/workflows/build_and_test.yml
. So branches: name-of-my-branch
in the main
branch is a bit deceptive - a build-on-push will only occur if that branch is specified under push
in its own .yml
.
我从main
拉到name-of-my-branch
以更新build_and_test.yml
,然后推入,并触发了构建.
I pulled from main
to name-of-my-branch
to update the build_and_test.yml
, pushed, and the build was triggered.
这篇关于推送至分支时未触发Github操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!