Run Github workflow on non-default branch

We have the current branch setup for our IaC repository:

  • dev (default branch in Github)
  • int
  • prod

Inside the “int” and “prod” branch, we currently don’t have any Github workflows stored.
On the “dev” branch, we have the workflow .github/workflows/check.yaml with the following event config:

on: 
  workflow_dispatch:
  pull_request:
    branches:
      - dev
      - int
      - prod
    paths:
      - '**/some-config-to-be-tested.json' 

PRs against “dev” branch run the workflow as expected.

Current issue
We also want this workflow to run on PRs against the “int” and “prod” branches without duplicating the workflow.
For example, the workflow should run on a PR to get branch “feature/new-int-config” merged to “int” branch.
However, this is not the case. PRs against “int” and “prod” do not run the workflow. In fact, the
“checks” tab of the PR shows “0”.

Manual trigger:
Furthermore, when trying to manually run the workflow on a branch not containing the workflow (as it was branched off of “int”), I get this error: Workflow does not exist or does not have a workflow_dispatch trigger in this branch.

I probably could work around this by copying the workflow from “dev” to “int” and “prod” but I really like to avoid this duplication and instead have the workflow in a single location.

What are your suggestions ?

GitHub Actions does not support a scenario where you have three independent branches and only one branch has a workflow. If you can not see a workflow on an int or prod branch, the same is true for GitHub Actions. Therefore, that workflow can only run on dev branch.

A better solution would be to create a reusable workflow that is placed on a workflow branch while the three branches have a simple wrapper workflow that invokes the reusable workflow. All logic will be shared across branches without duplication. The wrapper workflows will simply have workflow triggers as you showed in your question and a one-line job that invokes a reusable workflow:

name: dev-workflow

on:
  workflow_dispatch:
  pull_request:
    branches:
      - dev
      - int
      - prod
    paths:
      - '**/some-config-to-be-tested.json'

jobs:
  invoke-check:
    uses: org/repo/.github/workflows/check.yaml@v1
    with:
      branch: dev

A reusable workflow is the same as a regular workflow but with a workflow_call trigger:

name: check

on:
  workflow_call:
    inputs:
      branch:
        required: true
        type: string

jobs:
  ...

This workflow resides on a dedicates branch and is tagged as v1. The tag is progressed as the workflow is modified. A branch called v1 would work just as well without the need to push the tag along. However, the tag allows to release a stable workflow version while the workflow is being developed further.

There is a small catch as well. int-check and prod-check workflows must be present on the default branch (dev in your case) in order to be visible in the UI for manual triggering. These versions of the workflows will never be run. They simply give GitHub Actions a list of workflows that are available in the repo. This list gets displayed in the UI. These workflows can be minimal.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật