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

问题描述 投票:0回答:3

我的

build_and_test.yml
中的
.github/workflows
文件如下:

name: CI

on:
  push:
    branches:
      - main
      - name-of-my-branch
  pull_request:
    branches:
      - main

jobs:
  build:
    # Code to build

但是,当我推送到

main
分支以外的任何分支时,构建不会触发。有什么想法吗?

github continuous-integration github-actions
3个回答
16
投票

我意识到这个 Github Actions 文件位于主分支上,并且 Github 使用为要推送的分支配置的操作。如果

name-of-my-branch
在其
on: push: branches:
中指定了不同的
.github/workflows/build_and_test.yml
,它不会执行任何操作。因此
branches: name-of-my-branch
分支中的
main
有点具有欺骗性 - 仅当该分支在其自己的
push
中的
.yml
下指定时才会发生构建推送。

我从

main
拉到
name-of-my-branch
以更新
build_and_test.yml
,推送,并触发构建。


0
投票

根据经验,另一种可能是,即使在进行

.github
时,
yaml
目录和其中的
git add *
文件也没有被暂存。因此,当您按下时,不会触发任何操作。

我必须专门做

git add .github/workflows/myaction.yml
才能让它上演。


0
投票

这对我有用 - https://github.com/actions/checkout/discussions/277#discussioncomment-1522374 例如- 功能/分支名称

我的分支名称是feature/mybranch

© www.soinside.com 2019 - 2024. All rights reserved.