bayman
bayman

Reputation: 1719

Github Action workflow_run only on push to main branch

I have a CI workflow that runs on PR and PUSH to main branch.

---
name: CI

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]

I have another workflow I'd like to only run after CI is complete and conclusion is success but only when it's pushed to main branch.

---
name: Build

on:
  workflow_run:
    workflows: ["CI"]
    types:
      - completed
jobs:
  build:
    name: Build
    runs-on: self-hosted
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

It runs on both PR and push to main. How do I get the Build workflow to only run on push to main?

Upvotes: 4

Views: 3941

Answers (1)

yut23
yut23

Reputation: 3064

on:
  workflow_run:
    workflows: ["CI"]
    types:
      - completed
    branches:
      - main
jobs:
  build:
    name: Build
    runs-on: self-hosted
    if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }}

Upvotes: 3

Related Questions