Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run "design approved" check when necessary #336

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

jobs:
build:
if: false # not supported on OffchainLabs fork, ci.yml is used instead
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
Expand Down
40 changes: 31 additions & 9 deletions .github/workflows/merge-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@ on:
branches: [ master ]
types: [synchronize, opened, reopened, labeled, unlabeled]

permissions:
statuses: write

jobs:
design-approved-check:
if: ${{ !contains(github.event.*.labels.*.name, 'design-approved') }}
name: Design Approved Check
check-design-approved:
name: Check if Design Approved
runs-on: ubuntu-latest
steps:
- name: Check for design-approved label
- name: Check if design approved and update status
run: |
echo "Pull request is missing the 'design-approved' label"
echo "This workflow fails so that the pull request cannot be merged"
exit 1


set -x pipefail
status_state="pending"
if ${{ contains(github.event.*.labels.*.name, 'design-approved') }}; then
status_state="success"
else
resp="$(curl -sSL --fail-with-body \
-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")"
if ! jq -e '.[] | select(.context == "Design Approved Check")' > /dev/null <<< "$resp"; then
# Design not approved yet and no status exists
# Keep it without a status to keep the green checkmark appearing
# Otherwise, the commit and PR's CI will appear to be indefinitely pending
# Merging will still be blocked until the required status appears
exit 0
fi
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"'"}'
Loading