[CI] Add input for pr-gate (#13491)
This commit is contained in:
@@ -1,5 +1,14 @@
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
require-run-ci:
|
||||||
|
description: "Whether the PR must have the run-ci label"
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
rate-limit-hours:
|
||||||
|
description: "Rate limit window size in hours; 0 disables rate limiting"
|
||||||
|
type: number
|
||||||
|
default: 2
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pr-gate:
|
pr-gate:
|
||||||
@@ -21,29 +30,39 @@ jobs:
|
|||||||
core.setOutput("draft", pr.data.draft);
|
core.setOutput("draft", pr.data.draft);
|
||||||
core.setOutput("user", pr.data.user.login);
|
core.setOutput("user", pr.data.user.login);
|
||||||
|
|
||||||
|
- name: Log PR info
|
||||||
|
run: |
|
||||||
|
echo "===== PR Info ====="
|
||||||
|
echo "PR Event: ${{ github.event_name }}"
|
||||||
|
echo "PR Labels: ${{ steps.pr.outputs.labels }}"
|
||||||
|
echo "PR Draft: ${{ steps.pr.outputs.draft }}"
|
||||||
|
echo "PR User: ${{ steps.pr.outputs.user }}"
|
||||||
|
echo "Require run-ci: ${{ inputs.require-run-ci }}"
|
||||||
|
echo "Rate limit hours: ${{ inputs.rate-limit-hours }}"
|
||||||
|
echo "==================="
|
||||||
|
|
||||||
- name: Block draft PR
|
- name: Block draft PR
|
||||||
if: github.event_name == 'pull_request' && fromJson(steps.pr.outputs.draft)
|
if: github.event_name == 'pull_request' && fromJson(steps.pr.outputs.draft)
|
||||||
run: |
|
run: |
|
||||||
echo "PR is draft. Blocking CI."
|
echo "PR is draft. Blocking CI."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
- name: Require run-ci label
|
- name: Require run-ci label (optional)
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request' && inputs.require-run-ci == true
|
||||||
run: |
|
run: |
|
||||||
labels='${{ steps.pr.outputs.labels }}'
|
labels='${{ steps.pr.outputs.labels }}'
|
||||||
echo "Labels: $labels"
|
|
||||||
if [[ "${{ contains(fromJson(steps.pr.outputs.labels), 'run-ci') }}" == "false" ]]; then
|
if [[ "${{ contains(fromJson(steps.pr.outputs.labels), 'run-ci') }}" == "false" ]]; then
|
||||||
echo "Missing required label 'run-ci'."
|
echo "Missing required label 'run-ci'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Enforce rate limit for low-permission actors
|
- name: Enforce rate limit for low-permission actors (optional)
|
||||||
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
|
if: (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && inputs.rate-limit-hours != 0
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const HOURS = 2;
|
const HOURS = Number("${{ inputs.rate-limit-hours }}");
|
||||||
const owner = context.repo.owner;
|
const owner = context.repo.owner;
|
||||||
const repo = context.repo.repo;
|
const repo = context.repo.repo;
|
||||||
const eventName = context.eventName;
|
const eventName = context.eventName;
|
||||||
|
|||||||
Reference in New Issue
Block a user