Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 4

How to trigger a single build on either push or pull_request

Solved! Go to Solution.

I'm already using Azure Pipelines for builds. I'm now trying GitHub Actions for builds side by side, so I can compare them.

 

I subsequently received a PR for one of my projects from dependabot (https://github.com/gitfool/BoardGameGeek.Dungeon/pull/53). Azure Pipelines only triggered one build, as usual and as expected, but GitHub Actions triggered two builds; one for push and one for pull_request:

 

Checks.jpg

 

Is this a bug or do I need to configure the GitHub Actions differently to match Azure Pipelines behaviour? (After merging the pull request there should again be just a single build, but which should not be due to a pull request.)

 

https://github.com/gitfool/BoardGameGeek.Dungeon/blob/master/.azure-pipelines.yml

https://github.com/gitfool/BoardGameGeek.Dungeon/blob/master/.github/workflows/build.yml

3 Replies
Copilot Lvl 3
Message 2 of 4

Re: How to trigger a single build on either push or pull_request

Hello, your workflow is configured with "on: [push, pull_request]" so it gets triggered twice when a commit is pushed to open a pull request. It looks to me like "on: push" would work well for your use case.

Copilot Lvl 3
Message 3 of 4

Re: How to trigger a single build on either push or pull_request

The devil in the details is that pull requests should not publish build artifacts, whereas pushes / merges to master should, so I need to be able to differentiate pull requests from pushes with the GITHUB environment variables:

https://github.com/gitfool/BoardGameGeek.Dungeon/pull/53/checks?check_run_id=228755652#step:6:34

https://github.com/gitfool/BoardGameGeek.Dungeon/pull/53/checks?check_run_id=228755704#step:6:34

 

Azure Pipelines makes this easy and obvious:

https://dev.azure.com/gitfool/BoardGameGeek.Dungeon/_build/results?buildId=304&view=logs&jobId=1c8ce...

Solution
GitHub Staff
Message 4 of 4

Re: How to trigger a single build on either push or pull_request

You can specify the branches that you want builds to run on.  WIth the `on: [push, pull_request]` setting, you'll get any pushes into _any_ branch, and pull requests into _any_ branch.

 

This means that when dependabot creates its branch - in this case,

`dependabot/nuget/Microsoft.NET.Test.Sdk-16.3.0` - that your build will run.  It will then run again when it creates the pull request from that branch.

 

If you only want to run when something has a pull request opened into master, or when something is merged into master, then you can specify this as:

 

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master