How to trigger a single build on either push or pull_request

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 ( 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:

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.)

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.

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:

Azure Pipelines makes this easy and obvious:

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:

    - master
    - master