diff --git a/.github/actions/get-workflow-origin b/.github/actions/get-workflow-origin new file mode 160000 index 000000000..1b5a8a677 --- /dev/null +++ b/.github/actions/get-workflow-origin @@ -0,0 +1 @@ +Subproject commit 1b5a8a677b9ac6b10ffe7c275ebb0f9c8cff62bb diff --git a/.github/workflows/document_bot.yml b/.github/workflows/document_bot.yml deleted file mode 100644 index bf4a8e735..000000000 --- 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 33c02afca..3b3e00dce 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 000000000..98bba4600 --- /dev/null +++ b/.github/workflows/pr_labeler.js @@ -0,0 +1,100 @@ +/* + * 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, prNumber, triggerWorkflow }) => { + if (!prNumber) { + core.warning('No PR number found, skipping labeling.'); + return; + } + + 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.2', + }; + 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 000000000..7169b1438 --- /dev/null +++ b/.github/workflows/pr_labeler.yml @@ -0,0 +1,58 @@ +# 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 + submodules: recursive + - name: "Get information about the original trigger of the run" + uses: ./.github/actions/get-workflow-origin + id: source-run-info + with: + token: ${{ secrets.GITHUB_TOKEN }} + sourceRunId: ${{ github.event.workflow_run.id }} + - name: "Add labels to pull request" + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const script = require('./.github/workflows/pr_labeler.js'); + const prNumber = parseInt('${{ steps.source-run-info.outputs.pullRequestNumber }}'); + const triggerWorkflow = '${{ github.event.workflow_run.name }}'; + await script({ github, context, core, prNumber, 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 a7ee65dd6..99a419040 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 diff --git a/.gitmodules b/.gitmodules index 6cb7e5ce6..250c8dff1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "docs/themes/book"] path = docs/themes/book url = https://github.com/alex-shpak/hugo-book +[submodule ".github/actions/get-workflow-origin"] + path = .github/actions/get-workflow-origin + url = https://github.com/potiuk/get-workflow-origin