推送至分支时未触发Github操作

推送至分支时未触发Github操作

本文介绍了推送至分支时未触发Github操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.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操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:07