Skip to content

fix: sync editor value to server when same value is typed again #13

fix: sync editor value to server when same value is typed again

fix: sync editor value to server when same value is typed again #13

name: NpmPackage 24h gate
# Posts the @NpmPackage version-bump block on a PR, then automatically dismisses
# it and approves the PR 24 hours later. Triggered by validation.yml via a
# repository_dispatch when it detects an added @NpmPackage version.
#
# The 24h wait is implemented with an Environment named "24h-gate" that has a
# Wait timer of 1440 minutes (Settings -> Environments). A job waiting on a wait
# timer does not consume runner minutes, so this costs nothing while it waits,
# and it sidesteps the 6h single-job limit (the timer runs before the job does).
#
# This lives in its own workflow on purpose: validation.yml uses
# `cancel-in-progress: true`, which would cancel the pending 24h job on the next
# push to the PR.
on:
repository_dispatch:
types: [npm-package-blocked]
concurrency:
# One gate per PR; never cancel, or we'd kill a pending 24h waiter.
group: npm-package-gate-${{ github.event.client_payload.pr }}
cancel-in-progress: false
env:
MARKER: '<!-- vaadin-flow-components:npm-package-bump-review -->'
jobs:
block:
name: Request changes
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Request changes on PR
env:
GH_TOKEN: ${{ secrets.VAADIN_REVIEW_BOT }}
PR_NUMBER: ${{ github.event.client_payload.pr }}
REPO: ${{ github.repository }}
run: |
existing=$(gh api "repos/$REPO/pulls/$PR_NUMBER/reviews" \
--jq "[.[] | select(.state == \"CHANGES_REQUESTED\") | select(.body | contains(\"$MARKER\"))] | length")
if [ "$existing" -gt 0 ]; then
echo "Existing CHANGES_REQUESTED review found, skipping."
exit 0
fi
BODY=$(sed 's/^ //' <<'EOF'
<!-- vaadin-flow-components:npm-package-bump-review -->
This PR updates the `@NpmPackage` version. Because the default value of `vaadin.npm.minimumFrontendPackageAgeDays` is 1, I'm blocking it for now to avoid producing a failed snapshot for other projects.
**No action needed — this is fully automated:**
- I posted this block automatically when CI detected the `@NpmPackage` version bump.
- **24 hours after this message**, I will automatically dismiss this review, approve the PR, and enable auto-merge (squash) so it merges as soon as all required checks pass.
**What affects the 24h timer:**
- New commits / pushes **do not** reset it — the countdown is anchored to this message, so it keeps running no matter how many times you push.
- The timer only restarts if this block review is **manually dismissed** and a later CI run detects an `@NpmPackage` bump again (that posts a fresh block).
- If the PR is **merged or closed** before the 24 hours elapse, the auto-unblock simply does nothing.
EOF
)
gh api -X POST "repos/$REPO/pulls/$PR_NUMBER/reviews" \
-f event=REQUEST_CHANGES \
-f body="$BODY"
wait-and-unblock:
name: Auto-unblock after 24h
needs: block
runs-on: ubuntu-latest
# The Wait timer configured on this environment pauses the job for 24h
# before it starts running.
environment: 24h-gate
permissions:
contents: read
steps:
- name: Dismiss block and approve
env:
GH_TOKEN: ${{ secrets.VAADIN_REVIEW_BOT }}
PR_NUMBER: ${{ github.event.client_payload.pr }}
REPO: ${{ github.repository }}
run: |
# Re-check current state: skip if the PR was merged/closed meanwhile.
state=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.state')
if [ "$state" != "open" ]; then
echo "PR #$PR_NUMBER is '$state', nothing to unblock."
exit 0
fi
# Find the active block review carrying our marker (skip if already
# dismissed manually).
review_id=$(gh api "repos/$REPO/pulls/$PR_NUMBER/reviews" \
--jq "[.[] | select(.state == \"CHANGES_REQUESTED\") | select(.body | contains(\"$MARKER\"))] | last | .id // empty")
if [ -z "$review_id" ]; then
echo "No active block review found, nothing to dismiss."
exit 0
fi
echo "Dismissing block review $review_id on PR #$PR_NUMBER"
gh api -X PUT "repos/$REPO/pulls/$PR_NUMBER/reviews/$review_id/dismissals" \
-f message="24 hours have passed since the @NpmPackage block. Auto-unblocking and approving." \
-f event=DISMISS
echo "Approving PR #$PR_NUMBER"
gh api -X POST "repos/$REPO/pulls/$PR_NUMBER/reviews" \
-f event=APPROVE \
-f body="Automatically approved 24 hours after the @NpmPackage version bump block."
echo "Enabling auto-merge for PR #$PR_NUMBER"
gh pr merge "$PR_NUMBER" --repo "$REPO" --auto --squash \
|| echo "::warning::Could not enable auto-merge for PR #$PR_NUMBER (already merged, or no pending required checks)."