Only run "design approved" check when necessary [NIT-2667] #647
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Merge Checks | |
on: | |
pull_request: | |
branches: [ master ] | |
types: [synchronize, opened, reopened, labeled, unlabeled] | |
permissions: | |
statuses: write | |
jobs: | |
check-design-approved: | |
name: Check if Design Approved | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if design approved and update status | |
run: | | |
set -x pipefail | |
status_state="pending" | |
if ${{ contains(github.event.*.labels.*.name, 'design-approved') }}; then | |
status_state="success" | |
elif ! curl -sSL --fail-with-body \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/repos/$GITHUB_REPOSITORY/commits/${{ github.event.pull_request.head.sha }}/statuses" \ | |
| jq -e '.[] | select(.context == "Design Approved Check")' > /dev/null | |
then | |
# Design not approved yet and no status exists | |
# Keep it without a status | |
exit 0 | |
fi | |
curl -sSL --fail-with-body \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ github.event.pull_request.head.sha }}" \ | |
-d '{"context":"Design Approved Check","state":"'"$status_state"'"}' |