Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

ci(deja): require a replay result on the latest PR commit (#14786)

Uzair Khan6a2723fffe0c
diff --git a/.github/workflows/pr-convention-checks.yml b/.github/workflows/pr-convention-checks.yml
index 9464cc2b43..b5b2ea9f5a 100644
--- a/.github/workflows/pr-convention-checks.yml
+++ b/.github/workflows/pr-convention-checks.yml
@@ -14,6 +14,7 @@ on:
- reopened
- ready_for_review
- synchronize
+ - labeled
merge_group:
types:
@@ -193,3 +194,116 @@ jobs:
else
gh --repo ${{ github.event.repository.full_name }} pr edit --remove-label 'M-api-contract-changes' ${{ github.event.pull_request.number }}
fi
+
+ deja_art_latest_head_check:
+ name: Verify latest commit has a Deja ART replay result
+ if: ${{ github.event_name == 'pull_request_target' || github.event_name == 'merge_group' }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 130
+ concurrency:
+ # Metadata events must not cancel an active or pending replay waiter.
+ # New commits and explicit replay requests can still replace one another.
+ group: >-
+ deja-art-gate-${{ github.event.pull_request.number || github.run_id }}-${{
+ (github.event.action == 'synchronize' ||
+ (github.event.action == 'labeled' && github.event.label.name == 'deja-art')) &&
+ 'request' || github.run_id }}
+ cancel-in-progress: true
+ permissions:
+ checks: read
+ pull-requests: write
+
+ steps:
+ - name: Verify latest commit has a Deja ART replay result
+ if: ${{ github.event_name == 'pull_request_target' }}
+ shell: bash
+ env:
+ GH_TOKEN: ${{ github.token }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ CHECK_NAME: Deja ART Replay
+ STARTED_BY_LABEL: ${{ github.event.action == 'labeled' && github.event.label.name == 'deja-art' }}
+ REPLAY_REQUESTED: ${{ (github.event.action == 'labeled' && github.event.label.name == 'deja-art') || contains(github.event.pull_request.labels.*.name, 'deja-art') }}
+ EVENT_AT: ${{ github.event.pull_request.updated_at }}
+ REPLAY_STARTS_WITHIN_SECONDS: 600
+ COME_BACK_WITHIN_SECONDS: 6000
+ POLL_SECONDS: 30
+ run: |
+ short="${HEAD_SHA:0:10}"
+ runs() {
+ gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/check-runs?check_name=${CHECK_NAME// /%20}&filter=all&per_page=100" \
+ --jq '[.check_runs[] | select(.app.slug == "hyperswitch-bot")]'
+ }
+ state() {
+ runs | jq -r --arg since "$EVENT_AT" --arg fresh "$STARTED_BY_LABEL" \
+ 'map(select($fresh != "true" or .started_at >= $since)
+ | . + {verdict: (.status == "completed" and ((.output.title // "") | test(": (FAILED|TIMED_OUT)$") | not))})
+ | if any(.verdict) then "result\t" + ([.[] | select(.verdict)] | sort_by(.completed_at) | last | "\(.output.title)\t\(.conclusion)")
+ elif any(.status != "completed") then "running"
+ elif length == 0 then "none"
+ else "noverdict\t" + (sort_by(.completed_at) | last | .output.title)
+ end'
+ }
+
+ # Metadata events can arrive before Jenkins publishes the new check.
+ # While the request label is present, follow startup too; an older
+ # failed attempt is not evidence that the requested replay started.
+ if [ "$REPLAY_REQUESTED" = "true" ]; then
+ echo "A Deja ART replay was requested: waiting for a replay of ${short} to start..."
+ waited=0
+ s="$(state)"
+ until [[ "$s" == "running" || "$s" == result$'\t'* ||
+ ( "$STARTED_BY_LABEL" == "true" && "$s" == noverdict$'\t'* ) ]]; do
+ if [ "$waited" -ge "$REPLAY_STARTS_WITHIN_SECONDS" ]; then
+ echo "::error::Adding the deja-art label did not start a Deja ART replay on ${short} within $((REPLAY_STARTS_WITHIN_SECONDS / 60)) minutes. Add the label again to retry."
+ exit 1
+ fi
+ sleep "$POLL_SECONDS"; waited=$((waited + POLL_SECONDS))
+ s="$(state)"
+ done
+ echo "Replay found; waiting for its result..."
+ fi
+
+ # An edit or automatic label observes the same replay without
+ # replacing the request's waiter or failing while it is running.
+ waited=0
+ s="$(state)"
+ while [ "$s" = "running" ]; do
+ if [ "$waited" -ge "$COME_BACK_WITHIN_SECONDS" ]; then
+ echo "::error::The Deja ART replay on ${short} has not come back after $((COME_BACK_WITHIN_SECONDS / 60)) minutes. See the 'Deja ART Replay' check; add the label again to retry."
+ exit 1
+ fi
+ sleep "$POLL_SECONDS"; waited=$((waited + POLL_SECONDS))
+ s="$(state)"
+ done
+
+ IFS=$'\t' read -r word title conclusion <<< "$s"
+ case "$word" in
+ result)
+ echo "Deja ART replay result is back for ${short}: ${title} (conclusion: ${conclusion})."
+ echo "The gate passes once a result exists, regardless of verdict."
+ ;;
+ running)
+ echo "::error::A Deja ART replay of ${short} is still running. Re-run this check when it has finished."
+ exit 1
+ ;;
+ noverdict)
+ echo "::error::The Deja ART replay on ${short} did not reach a verdict (${title##*: }). See the 'Deja ART Replay' check; add the deja-art label to run it again."
+ exit 1
+ ;;
+ *)
+ echo "::error::No Deja ART replay has run on the latest commit ${short}. When this commit is the one to merge, add the deja-art label: it replays this commit and this check follows."
+ exit 1
+ ;;
+ esac
+
+ - name: Remove the deja-art label
+ if: ${{ always() && github.event_name == 'pull_request_target' && github.event.action == 'labeled' && github.event.label.name == 'deja-art' }}
+ shell: bash
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: gh api --method DELETE "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels/deja-art" > /dev/null || echo "The label was already gone."
+
+ - name: Nothing to verify in the merge queue
+ if: ${{ github.event_name == 'merge_group' }}
+ run: echo "Merge group - the replay was verified on the pull request."
diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md
index 907b473c9a..068a29b005 100644
--- a/docs/CONTRIBUTING.md
+++ b/docs/CONTRIBUTING.md
@@ -202,6 +202,14 @@ Before making a large change, it is usually a good idea to first open an issue
describing the change to solicit feedback and guidance.
This will increase the likelihood of the PR getting merged.
+### Deja ART replay
+
+When the pull request's final commit is ready, add the `deja-art` label to
+request a replay. The gate checks for a replay result on that commit, not for
+the label itself; any completed verdict counts, including a divergence. The
+label is removed after the request so adding it again retries the replay.
+A later push needs a new replay result on the new commit.
+
### Cargo Commands
Due to the extensive use of features in hyperswitch, you will often need to add