This is an automated email from the ASF dual-hosted git repository. xtsong pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/flink-agents.git
commit 48cd1e3f5efde5652d75c9d7b521e574a5991a8f Author: youjin <[email protected]> AuthorDate: Tue Mar 10 15:16:23 2026 +0800 [infra] Use GHA workflow triggers to run pull request labeler workflow --- .github/workflows/document_bot.yml | 44 -------- .../workflows/{labeler.yml => pr_edit_trigger.yml} | 22 ++-- .github/workflows/pr_labeler.js | 121 +++++++++++++++++++++ .github/workflows/pr_labeler.yml | 51 +++++++++ .../{labeler.yml => workflows/pr_open_trigger.yml} | 28 +++-- 5 files changed, 195 insertions(+), 71 deletions(-) diff --git a/.github/workflows/document_bot.yml b/.github/workflows/document_bot.yml deleted file mode 100644 index bf4a8e73..00000000 --- a/.github/workflows/document_bot.yml +++ /dev/null @@ -1,44 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -name: "Documentation Bot" - -on: - pull_request_target: - types: - - opened - - edited - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }} - cancel-in-progress: true - -jobs: - label: - if: (github.repository == 'apache/flink-agents') && (github.event.pull_request.state == 'open') - permissions: - pull-requests: write - runs-on: ubuntu-24.04 - steps: - - name: Labeling - uses: apache/pulsar-test-infra/docbot@8ff059e49446fff5bb9baf2de4a12bc05c2d57ab - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LABEL_WATCH_LIST: 'doc-needed,doc-not-needed,doc-included' - LABEL_MISSING: 'doc-label-missing' diff --git a/.github/workflows/labeler.yml b/.github/workflows/pr_edit_trigger.yml similarity index 76% rename from .github/workflows/labeler.yml rename to .github/workflows/pr_edit_trigger.yml index 33c02afc..3b3e00dc 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/pr_edit_trigger.yml @@ -15,19 +15,17 @@ # specific language governing permissions and limitations # under the License. -name: "Pull Request Labeler" - +name: PR-Edit-Trigger on: - pull_request_target: - types: - - opened + pull_request: + types: [edited] + branches: + - main + - release-* + jobs: - triage: - if: (github.repository == 'apache/flink-agents') - permissions: - contents: read - pull-requests: write - issues: write + label: runs-on: ubuntu-latest steps: - - uses: actions/labeler@v5 \ No newline at end of file + - name: "Do nothing. Just triggers corresponding workflow." + run: echo diff --git a/.github/workflows/pr_labeler.js b/.github/workflows/pr_labeler.js new file mode 100644 index 00000000..f34764df --- /dev/null +++ b/.github/workflows/pr_labeler.js @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = async ({ github, context, core, workflowRunId, triggerWorkflow }) => { + // Retrieve the PR number from the workflow run that triggered this job + const { data: run } = await github.rest.actions.getWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: workflowRunId, + }); + let prNumber = run.pull_requests?.[0]?.number; + + // Fallback for fork PRs: pull_requests is empty for cross-repo workflow runs + if (!prNumber) { + core.info(`No PR in pull_requests array, falling back to search by head branch...`); + const { data: pullRequests } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${run.head_repository.owner.login}:${run.head_branch}`, + }); + prNumber = pullRequests[0]?.number; + } + + if (!prNumber) { + core.setFailed(`No pull request found for workflow run ${workflowRunId}`); + return; + } + core.info(`Found PR #${prNumber} from workflow run ${workflowRunId}`); + + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + }); + + const isOpenTrigger = triggerWorkflow === 'PR-Open-Trigger'; + const labels = []; + + // --- Labels only added on PR open (priority/major, fixVersion) --- + + if (isOpenTrigger) { + labels.push('priority/major'); + + const baseBranch = pr.base.ref; + const fixVersionLabelMap = { + 'main': 'fixVersion/0.3.0', + 'release-0.2': 'fixVersion/0.2.1', + 'release-0.1': 'fixVersion/0.1.1', + }; + const fixVersionLabel = fixVersionLabelMap[baseBranch]; + if (fixVersionLabel) { + labels.push(fixVersionLabel); + } + } + + // --- Documentation labels (evaluated on both open and edit) --- + + const docLabels = ['doc-needed', 'doc-not-needed', 'doc-included']; + const docMissingLabel = 'doc-label-missing'; + const prBody = pr.body || ''; + const checkedDocLabel = docLabels.find(label => { + const pattern = new RegExp(`-\\s*\\[x\\]\\s*\`${label}\``, 'i'); + return pattern.test(prBody); + }); + + // Remove all existing doc labels first + const { data: existingLabels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const allDocLabels = [...docLabels, docMissingLabel]; + for (const existingLabel of existingLabels) { + if (allDocLabels.includes(existingLabel.name)) { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: existingLabel.name, + }); + core.info(`Removed existing doc label '${existingLabel.name}'.`); + } + } + + if (checkedDocLabel) { + labels.push(checkedDocLabel); + core.info(`Documentation checkbox checked: '${checkedDocLabel}'.`); + } else { + labels.push(docMissingLabel); + core.info('No documentation checkbox checked, adding doc-label-missing.'); + } + + // --- Apply all labels --- + + if (labels.length > 0) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: labels, + }); + core.info(`Added labels: ${labels.join(', ')}`); + } else { + core.info('No labels to add.'); + } +}; diff --git a/.github/workflows/pr_labeler.yml b/.github/workflows/pr_labeler.yml new file mode 100644 index 00000000..958fbc9b --- /dev/null +++ b/.github/workflows/pr_labeler.yml @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: "Pull Request Labeler" + +on: + workflow_run: + workflows: [PR-Open-Trigger, PR-Edit-Trigger] + types: [requested] + +concurrency: + group: ${{ github.event.workflow_run.name }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: true + +permissions: + checks: write + contents: read + pull-requests: write + +jobs: + label: + if: github.repository == 'apache/flink-agents' + runs-on: ubuntu-latest + steps: + - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" + uses: actions/checkout@v6 + with: + persist-credentials: false + - name: "Label pull request" + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const script = require('./.github/workflows/pr_labeler.js'); + const workflowRunId = ${{ github.event.workflow_run.id }}; + const triggerWorkflow = '${{ github.event.workflow_run.name }}'; + await script({ github, context, core, workflowRunId, triggerWorkflow }); diff --git a/.github/labeler.yml b/.github/workflows/pr_open_trigger.yml similarity index 59% rename from .github/labeler.yml rename to .github/workflows/pr_open_trigger.yml index a7ee65dd..99a41904 100644 --- a/.github/labeler.yml +++ b/.github/workflows/pr_open_trigger.yml @@ -15,19 +15,17 @@ # specific language governing permissions and limitations # under the License. -# Add 'priority/major' label to any changes within the entire repository -priority/major: - - changed-files: - - any-glob-to-any-file: '**' +name: PR-Open-Trigger +on: + pull_request: + types: [opened] + branches: + - main + - release-* -# Add 'fixVersion/0.3.0' label to any PR that is opened against the `main` branch -fixVersion/0.3.0: - - base-branch: 'main' - -# Add 'fixVersion/0.2.1' label to any PR that is opened against the `release-0.2` branch -fixVersion/0.2.1: - - base-branch: 'release-0.2' - -# Add 'fixVersion/0.1.1' label to any PR that is opened against the `release-0.1` branch -fixVersion/0.1.1: - - base-branch: 'release-0.1' \ No newline at end of file +jobs: + label: + runs-on: ubuntu-latest + steps: + - name: "Do nothing. Just triggers corresponding workflow." + run: echo
