githubcontinuous-integrationazure-pipelinesazure-pipelines-yamlgithub-check-run

Make contextual github checks required to pass


I have 4 Azure Pipelines that perform checks when a PR is created. They are configured such that certain checks are excluded/included based on the changes made. For example, if the PR only contains frontend code changes, there is no reason to run the check pipeline associated with checking backend code changes.

In the GitHub branches configuration, there is an option "Require status checks to pass before merging" but when you check that you have to select which pipelines must pass. Doing so sets it so that the pipeline you selected must run and pass in order to merge, but with our configuration, it may not have a reason to run so the PR would be stuck forever.

Is there a way to have GitHub status checks required to pass before merging, but the status checks that must pass are determined at the time of the PR creation, not beforehand?


Solution

  • Based on my test, I could reproduce this situation.

    When I create multiple status check(Azure Pipeline) in Github, these checks only accept the build status after the Pull Request was created.

    Therefore, due to some configuration (such as path filter), if the related pipeline does not run, then this PR will be stuck.

    enter image description here

    In this situation, you could use API to send the existing Azure Pipeline Status to Status check.

    API URL:

    Post https://api.github.com/repos/{owner}/{repo}/statuses/{sha}
    

    Reuqest Body:

    {
      "state": "success",
      "target_url": "Build Status badge Url",
      "description": "Build verify",
      "context": "Staus Check name"
    }
    

    Then you could pass the status check in Github.