ci: make nightly merge opt-out and simplify Docbot labels (#10601)

* ci: make nightly merge opt-out and simplify Docbot labels

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* ci: scope nightly label migration and sync to main

Use the saved nightly preference only for PRs targeting main at both
snapshot and apply time. Clean up docs-not-required across all bases.

Restore the skip label when it is removed while the opt-out box is
checked.

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* ci: honor cleared nightly opt-outs on retry

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

---------

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
shuiyisong
2026-11-24 10:42:29 +00:00
committed by GitHub
parent 21d6a25dfb
commit 81e60511b5
9 changed files with 594 additions and 122 deletions
+9 -4
View File
@@ -3,12 +3,17 @@ on:
pull_request_target:
types: [opened, edited, closed]
concurrency:
group: ${{ github.workflow }}-${{ github.event.action }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
docbot:
# An unrelated edit must not displace a pending docs checkbox change.
if: >-
github.event.action != 'edited' ||
(github.event.changes.body &&
contains(github.event.changes.body.from, '[x] This PR requires documentation updates.') !=
contains(github.event.pull_request.body, '[x] This PR requires documentation updates.'))
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.action == 'closed' && 'close' || 'labels' }}
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
pull-requests: write
+51 -25
View File
@@ -3,7 +3,8 @@ name: Nightly Merge
on:
pull_request_target:
types: [opened, edited, reopened]
branches: [main]
types: [opened, edited, reopened, unlabeled]
schedule:
# Hourly from 02:10 through 08:10 Asia/Shanghai (UTC+8), inclusive.
# GitHub may delay scheduled runs.
@@ -19,44 +20,68 @@ permissions: {}
jobs:
sync-label:
if: github.repository == 'GreptimeTeam/greptimedb' && github.event_name == 'pull_request_target'
if: >-
github.repository == 'GreptimeTeam/greptimedb' && github.event_name == 'pull_request_target' &&
(github.event.action != 'unlabeled' || github.event.label.name == 'skip nightly merge')
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
# PR label mutations require pull-request write permission.
contents: read
pull-requests: write
issues: write
concurrency:
group: nightly-merge-label-${{ github.event.pull_request.number }}
cancel-in-progress: false
steps:
# No checkout: PR contents are untrusted data, never executable code.
# On pull_request_target github.sha identifies trusted base-repository code.
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
sparse-checkout: .github/scripts/nightly-merge.cjs
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: actions/github-script@v7
with:
script: |
const { skipChecked, skipLabel } = require('./.github/scripts/nightly-merge.cjs');
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const checkbox = /^- \[([ xX])\] Merge during the nightly window <!-- nightly-merge -->\s*$/m.exec(pr.body || '');
// PRs without the template manage their opt-in through the label.
if (!checkbox) return;
const selected = checkbox[1].toLowerCase() === 'x';
const label = 'merge nightly';
const labeled = pr.labels.some(item => item.name === label);
if (selected && !labeled) {
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [label] });
} else if (!selected && labeled) {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name: label });
if (pr.state !== 'open' || pr.base.ref !== 'main') return;
const selected = skipChecked(pr.body);
const labeled = pr.labels.some(item => item.name === skipLabel);
if (selected === labeled) return;
if (selected) {
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [skipLabel] });
} else {
// Only undo the bot's own label. A maintainer may have applied a hold since the edit.
const events = await github.paginate(github.rest.issues.listEvents, { owner, repo, issue_number, per_page: 100 });
const [last] = events.filter(event => event.label?.name === skipLabel &&
(event.event === 'labeled' || event.event === 'unlabeled'))
.sort((a, b) => b.created_at.localeCompare(a.created_at) || b.id - a.id);
if (last?.event === 'labeled' && last.actor?.login === 'github-actions[bot]') {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name: skipLabel });
}
}
enqueue:
if: github.repository == 'GreptimeTeam/greptimedb' && github.event_name != 'pull_request_target'
if: >-
github.repository == 'GreptimeTeam/greptimedb' && github.event_name != 'pull_request_target' &&
(vars.NIGHTLY_MERGE_ENABLED == 'true' || (github.event_name == 'workflow_dispatch' && inputs.dry_run))
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
concurrency:
group: nightly-merge-enqueue
cancel-in-progress: false
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
sparse-checkout: .github/scripts/nightly-merge.cjs
sparse-checkout-cone-mode: false
persist-credentials: false
# Reuses the automation credential used by backport and compat updates.
# A PAT (or App token) lets subsequent merge_group workflows run.
- uses: actions/github-script@v7
@@ -65,25 +90,20 @@ jobs:
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
const { eligibleForNightly } = require('./.github/scripts/nightly-merge.cjs');
const { owner, repo } = context.repo;
const dryRun = process.env.DRY_RUN === 'true';
const candidates = await github.paginate(github.rest.issues.listForRepo, {
owner, repo, state: 'open', labels: 'merge nightly',
const candidates = await github.paginate(github.rest.pulls.list, {
owner, repo, state: 'open', base: 'main',
sort: 'created', direction: 'asc', per_page: 100
});
const rows = [];
let enqueued = 0;
for (const candidate of candidates) {
if (!candidate.pull_request || enqueued >= 5) continue;
if (enqueued >= 5) break;
if (!eligibleForNightly(candidate)) continue;
const number = candidate.number;
try {
// Fetch current labels and PR state, not the earlier list snapshot.
const { data: current } = await github.rest.pulls.get({ owner, repo, pull_number: number });
if (current.state !== 'open' || current.draft || current.base.ref !== 'main' ||
!current.labels.some(label => label.name === 'merge nightly')) {
rows.push([String(number), 'Skipped: not opted in, draft, closed, or not targeting main']);
continue;
}
const { repository: { pullRequest: pr } } = await github.graphql(`
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
@@ -120,6 +140,12 @@ jobs:
rows.push([String(number), 'Skipped: unresolved review threads']);
continue;
}
// An opt-out may have arrived while checking reviews and threads.
const { data: current } = await github.rest.pulls.get({ owner, repo, pull_number: number });
if (!eligibleForNightly(current)) {
rows.push([String(number), 'Skipped: opted out, draft, closed, or not targeting main']);
continue;
}
if (!dryRun) {
// GitHub enforces branch rules; never bypass or enable auto-merge.
try {