-
Notifications
You must be signed in to change notification settings - Fork 5k
[CI] fix triggered by a non-run-ci label #13393
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9085f11
udpate
hnyls2002 c8f18a7
test
hnyls2002 433d80a
fix
hnyls2002 f601d32
debug
hnyls2002 b5c9707
debug
hnyls2002 22a082e
fix
hnyls2002 243786a
revert
hnyls2002 dabf1d5
seperate files
hnyls2002 6182179
update
hnyls2002 9479334
fix
hnyls2002 890368c
update amd
hnyls2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| on: | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| pr-gate: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Fetch latest PR info | ||
| id: pr | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const pr = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number | ||
| }); | ||
| core.setOutput("labels", JSON.stringify(pr.data.labels.map(l => l.name))); | ||
| core.setOutput("draft", pr.data.draft); | ||
| core.setOutput("user", pr.data.user.login); | ||
|
|
||
| - name: Block draft PR | ||
| if: github.event_name == 'pull_request' && fromJson(steps.pr.outputs.draft) | ||
| run: | | ||
| echo "PR is draft. Blocking CI." | ||
| exit 1 | ||
|
|
||
| - name: Require run-ci label | ||
| if: github.event_name == 'pull_request' | ||
| run: | | ||
| labels='${{ steps.pr.outputs.labels }}' | ||
| echo "Labels: $labels" | ||
| if [[ "${{ contains(fromJson(steps.pr.outputs.labels), 'run-ci') }}" == "false" ]]; then | ||
| echo "Missing required label 'run-ci'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Enforce rate limit for low-permission actors | ||
| if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const HOURS = 2; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const eventName = context.eventName; | ||
| const curRun = await github.rest.actions.getWorkflowRun({ | ||
| owner, repo, run_id: context.runId | ||
| }); | ||
| const triggeringActor = curRun.data.triggering_actor?.login || context.actor; | ||
|
|
||
| async function hasHighPermission(username) { | ||
| try { | ||
| const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ owner, repo, username }); | ||
| const perm = data.permission || 'none'; | ||
| return perm === 'write' || perm === 'maintain' || perm === 'admin'; | ||
| } catch (e) { | ||
| if (e.status === 404 || e.status === 403) return false; | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| if (await hasHighPermission(triggeringActor)) { | ||
| core.info(`Triggering user '${triggeringActor}' has high permission. No rate limit applied.`); | ||
| return; | ||
| } | ||
|
|
||
| const cutoff = new Date(Date.now() - HOURS * 60 * 60 * 1000); | ||
| core.info(`Checking for workflow runs since ${cutoff.toISOString()} (last ${HOURS} hours) for event '${eventName}'.`); | ||
|
|
||
| const { data } = await github.rest.actions.listWorkflowRuns({ | ||
| owner, | ||
| repo, | ||
| workflow_id: 'pr-test.yml', | ||
| event: eventName, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const runs = data.workflow_runs || []; | ||
| const recentFound = runs.find((run) => { | ||
| if (String(run.id) === String(context.runId)) return false; | ||
| if (new Date(run.created_at) < cutoff) return false; | ||
| return (run.actor?.login === triggeringActor) || (run.triggering_actor?.login === triggeringActor); | ||
| }); | ||
|
|
||
| if (recentFound) { | ||
| core.setFailed( | ||
| `User '${triggeringActor}' already triggered '${context.workflow}' via '${eventName}' at ${recentFound.created_at}. ` + | ||
| `Please wait ${HOURS} hours before triggering again.` | ||
| ); | ||
| } else { | ||
| core.info(`No recent runs detected within the last ${HOURS} hours; proceeding.`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.