diff --git a/.github/workflows/check_skip_ci.yml b/.github/workflows/check_skip_ci.yml index 518f7219..0ca3822e 100644 --- a/.github/workflows/check_skip_ci.yml +++ b/.github/workflows/check_skip_ci.yml @@ -54,50 +54,56 @@ jobs: - name: scan label, description, and comments id: check - if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | - const trusted = ['OWNER', 'MEMBER', 'COLLABORATOR']; - // The control string is honored only when it is alone on a line - // by itself, so that prose mentioning it does not accidentally - // skip CI. - const control = /^\[skip-ci\]$/i; - const hasControlLine = text => - (text || '').split(/\r?\n/) - .some(line => control.test(line.trim())); - const pr = context.payload.pull_request; - - // 1. The skip-ci label, set by a repository member. - if (pr.labels.some(label => label.name === 'skip-ci')) { - core.notice('CI skipped: the "skip-ci" label is present.'); - core.setOutput('skip', 'true'); - return; + async function hasSkipLabelOnPr(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; + } + return false; } - // 2. The control string in the pull request description. - if (trusted.includes(pr.author_association) && - hasControlLine(pr.body)) { - core.notice('CI skipped: control string in the description.'); - core.setOutput('skip', 'true'); + if (github.event_name === 'pull_request') { + const pr = context.payload.pull_request; + if (!pr) { + core.setOutput('skip', 'false'); + return; + } + const shouldSkip = await hasSkipLabelOnPr(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) { + if (await hasSkipLabelOnPr(p.number)) { + core.setOutput('skip', 'true'); + return; + } + } + + core.setOutput('skip', 'false'); return; } diff --git a/.github/workflows/profiling.yml b/.github/workflows/profiling.yml index 4d38364c..88540103 100644 --- a/.github/workflows/profiling.yml +++ b/.github/workflows/profiling.yml @@ -1,17 +1,19 @@ name: profiling on: - push: - pull_request: schedule: - cron: '34 17 * * *' + workflow_dispatch: + push: + pull_request: jobs: profile: - # 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' }} + # Run profiling on schedule or when MMGH_FORCE_PROFILE is set to 'enable'. + # MMGH_FORCE_PROFILE can force profiling for push and pull_request events. + # See: https://docs.github.com/en/actions/learn-github-actions/variables#organization-and-repository-variables + if: ${{ vars.MMGH_NIGHTLY == 'enable' || vars.MMGH_FORCE_PROFILE == 'enable' }} name: profile_${{ matrix.os }}