Custom GitHub Status Check

Introduction

When we create a pull request, it allows people to work collaboratively to review and suggest changes, with this, processes like CI - Continuous Integration were created, which is a practice of automating tests to verify if your code can integrate with others contributors’ code.
That is why GitHub Status Check was created, to see if your commits meet the conditions defined in the repository you’re contributing to.

How the Status Check works at Harness?

Currently, every application Build sends a hook to GitHub’s API with the current lifecycle of the task, either: pending; concluded; failed.
In addition, it’s informed which step the pipeline is in and the reference link to the task.

How to create my own Status Check?

Natively, it isn’t yet possible to customize, but Harness it’s always focusing on providing flexibility and ease for its users, with that said, we created a tutorial teaching how to create your own Status Check.

Tutorial

Requirements
1. CI Pipeline
2. GitHub Personal Access Token
3. GitHub repository

Step by step

1. Edit your build pipeline in Pipeline Studio.
2. Add a step of type Run

Upload Artifacts to Restore Cache

3. Configure the step parameters, you need an image that contains curl installed, or you could install it too.

Step Parameters Advanced

4. Include the command below and edit it according to your needs

  curl -i \
  -X POST \
  -H "Authorization: Bearer <+secrets.getValue('account.Github_Access_Token')>" \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/<YOUR_ORGANIZATION>/<+pipeline.properties.ci.codebase.repoName>/statuses/<+codebase.commitSha> \
  -d '{"state":"pending","target_url":"<+pipeline.execution.url>","description":"Test is running","context":"harness-ci/tests"}'

Thank you @Diego_Pereira and @DanFlores for helping with the example above

5. Now you’re ready, sir! Enjoy your customized GitHub Status Check :slight_smile:

8 Likes