Ensure skip-ci label workable and simplify profiling job conditions#877
Ensure skip-ci label workable and simplify profiling job conditions#877rockleona wants to merge 3 commits into
Conversation
| async function checkPrNumber(prNumber) { | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| }); | ||
|
|
||
| if (pr.labels && pr.labels.some(label => label.name === 'skip-ci')) { | ||
| core.notice(`CI skipped: the "skip-ci" label is present on PR #${pr.number}.`); | ||
| return true; | ||
| } | ||
|
|
||
| if (trusted.includes(pr.author_association) && hasControlLine(pr.body)) { | ||
| core.notice(`CI skipped: control string in the description of PR #${pr.number}.`); | ||
| return true; | ||
| } | ||
|
|
||
| const comments = await github.paginate( | ||
| github.rest.issues.listComments, | ||
| { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| per_page: 100, | ||
| }); | ||
| const hit = comments.find( | ||
| comment => trusted.includes(comment.author_association) && hasControlLine(comment.body)); | ||
| if (hit) { | ||
| core.notice(`CI skipped: control string in a comment on PR #${pr.number}.`); | ||
| return true; | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
This helper function will check the content in specific PR, and return boolean of true if it needs to skip.
| if (github.event_name === 'pull_request') { | ||
| const pr = context.payload.pull_request; | ||
| if (!pr) { | ||
| core.setOutput('skip', 'false'); | ||
| return; | ||
| } | ||
| const shouldSkip = await checkPrNumber(pr.number); | ||
| core.setOutput('skip', shouldSkip ? 'true' : 'false'); | ||
| return; | ||
| } | ||
|
|
||
| // 3. The control string in a comment from a member. | ||
| const comments = await github.paginate( | ||
| github.rest.issues.listComments, | ||
| { | ||
| else if (github.event_name === 'push') { | ||
| const sha = context.sha || context.payload.after; | ||
| if (!sha) { | ||
| core.setOutput('skip', 'false'); | ||
| return; | ||
| } | ||
|
|
||
| const assoc = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| per_page: 100, | ||
| commit_sha: sha, | ||
| }); | ||
| const hit = comments.find( | ||
| comment => trusted.includes(comment.author_association) && | ||
| hasControlLine(comment.body)); | ||
| if (hit) { | ||
| core.notice('CI skipped: control string in a comment.'); | ||
| core.setOutput('skip', 'true'); | ||
|
|
||
| const prs = assoc.data || []; | ||
| for (const p of prs) { | ||
| const num = p.number; | ||
| if (await checkPrNumber(num)) { | ||
| core.setOutput('skip', 'true'); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| core.setOutput('skip', 'false'); | ||
| return; | ||
| } |
There was a problem hiding this comment.
check_skip_ci will call by other action (workflow), it will check what triggered the action and check if the push commit is related to any PR, then call the helper function checkPrNumber.
| push: | ||
| pull_request: |
There was a problem hiding this comment.
Removed these 2 triggers
|
|
||
| # Run profiling only on schedule or when MMGH_FORCE_PROFILE is set to 'enable' | ||
| # You can refer to https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables to set MMGH_FORCE_PROFILE in the fork repository settings for testing purposes. | ||
| if: ${{ (github.event_name == 'schedule' && vars.MMGH_NIGHTLY == 'enable') || vars.MMGH_FORCE_PROFILE == 'enable' }} |
There was a problem hiding this comment.
So no need to check event_name since the trigger is clean.
There was a problem hiding this comment.
If removing push and pull_request from on, MMGH_FORCE_PROFILE will not work when on is not schedule. We need to allow to use MMGH_FORCE_PROFILE to force profiling on push and pull_request.
yungyuc
left a comment
There was a problem hiding this comment.
- Need to allow to use
MMGH_FORCE_PROFILEto force profiling onpushandpull_request. - Reduce patch complexity if possible.
|
|
||
| # Run profiling only on schedule or when MMGH_FORCE_PROFILE is set to 'enable' | ||
| # You can refer to https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables to set MMGH_FORCE_PROFILE in the fork repository settings for testing purposes. | ||
| if: ${{ (github.event_name == 'schedule' && vars.MMGH_NIGHTLY == 'enable') || vars.MMGH_FORCE_PROFILE == 'enable' }} |
There was a problem hiding this comment.
If removing push and pull_request from on, MMGH_FORCE_PROFILE will not work when on is not schedule. We need to allow to use MMGH_FORCE_PROFILE to force profiling on push and pull_request.
| core.notice('CI skipped: the "skip-ci" label is present.'); | ||
| core.setOutput('skip', 'true'); | ||
| return; | ||
| async function checkPrNumber(prNumber) { |
There was a problem hiding this comment.
The patch looks overly complex. I am not sure why a simple conditional check need to use async. If it is necessary, explain in PR annotation. If it is not, use minimal diff for the fix.
|
@ExplorerRay @chestercheng please help take a look. |
|
The requirement in #858 seems to be:
So, I wonder if we can simplify this design. Maybe we can make the Then labels become the only CI gate:
This may make the behavior easier to understand and maintain. |
Issue #858 is just about the
It sounds like a good simplification for |
Simplify profiling job conditions and ensure the skip-ci label is honored for push-triggered updates so CI runs are not noisy or duplicated.
This PR removes push/pull_request triggers from the profiling workflow and updates check_skip_ci to detect and respect skip-ci on push-triggered runs so profiling jobs run only when intended.
Related to #858.