diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000000..b3ae34e3f0 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,79 @@ +"project: aqlprofile": +- changed-files: + - any-glob-to-any-file: 'projects/aqlprofile/**/*' + +"project: clr": +- changed-files: + - any-glob-to-any-file: 'projects/clr/**/*' + +"project: hip": +- changed-files: + - any-glob-to-any-file: 'projects/hip/**/*' + +"project: hipother": +- changed-files: + - any-glob-to-any-file: 'projects/hipother/**/*' + +"project: hip-tests": +- changed-files: + - any-glob-to-any-file: 'projects/hip-tests/**/*' + +"project: rdc": +- changed-files: + - any-glob-to-any-file: 'projects/rdc/**/*' + +"project: rocm-core": +- changed-files: + - any-glob-to-any-file: 'projects/rocm-core/**/*' + +"project: rocminfo": +- changed-files: + - any-glob-to-any-file: 'projects/rocminfo/**/*' + +"project: rocm-smi-lib": +- changed-files: + - any-glob-to-any-file: 'projects/rocm-smi-lib/**/*' + +"project: rocprofiler": +- changed-files: + - any-glob-to-any-file: 'projects/rocprofiler/**/*' + +"project: rocprofiler-compute": +- changed-files: + - any-glob-to-any-file: 'projects/rocprofiler-compute/**/*' + +"project: rocprofiler-register": +- changed-files: + - any-glob-to-any-file: 'projects/rocprofiler-register/**/*' + +"project: rocprofiler-sdk": +- changed-files: + - any-glob-to-any-file: 'projects/rocprofiler-sdk/**/*' + +"project: rocprofiler-systems": +- changed-files: + - any-glob-to-any-file: 'projects/rocprofiler-systems/**/*' + +"project: roctracer": +- changed-files: + - any-glob-to-any-file: 'projects/roctracer/**/*' + +documentation: +- changed-files: + - any-glob-to-any-file: + - docs/**/* + - '**/docs/**/*' + - '*.md' + +External CI: +- changed-files: + - any-glob-to-any-file: + - .azuredevops/**/* + +github action: +- changed-files: + - any-glob-to-any-file: + - .github/workflows/**/* + - .github/scripts/**/* + - .github/*.json + - .github/*.yml diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000000..893f40450d --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,14 @@ +name: Auto Label PR +on: + pull_request_target: + types: [opened, synchronize, reopened] + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-24.04 + steps: + - id: label-the-PR + uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 diff --git a/.github/workflows/pr-auto-label-dispatcher.yml b/.github/workflows/pr-auto-label-dispatcher.yml deleted file mode 100644 index bb2ca5c752..0000000000 --- a/.github/workflows/pr-auto-label-dispatcher.yml +++ /dev/null @@ -1,37 +0,0 @@ -# Auto Label PR Dispatcher -# ------------------------ -# This workflow is triggered by pull request events and sends a repository_dispatch event -# to the pr-auto-label workflow to handle label management. -# This allows the workflow to support pull requests from forks and main repository branches. - -name: Auto Label PR Trigger - -on: - pull_request_target: - types: - - opened - - synchronize - - reopened - - ready_for_review - branches: - - develop - - release/rocm-rel-7.* - -concurrency: - group: pr-auto-label-dispatcher-${{ github.event.pull_request.number }} - cancel-in-progress: false - -jobs: - trigger-dispatch: - runs-on: ubuntu-24.04 - permissions: - contents: read - actions: write - steps: - - name: Send repository_dispatch to run labeling logic - env: - GH_TOKEN: ${{ github.token }} - run: | - gh api repos/${{ github.repository }}/dispatches \ - -f event_type="pr-auto-label" \ - -f client_payload='{"pr":"${{ github.event.pull_request.number }}"}' diff --git a/.github/workflows/pr-auto-label.yml b/.github/workflows/pr-auto-label.yml deleted file mode 100644 index a40271f745..0000000000 --- a/.github/workflows/pr-auto-label.yml +++ /dev/null @@ -1,96 +0,0 @@ -# Auto Label PR -# ------------- -# This GitHub Actions workflow automatically adds or removes labels on a pull request -# based on a custom Python script that analyzes the PR content and paths. -# This workflow is triggered by a repository_dispatch event, which is sent from another workflow. -# -# Steps: -# - Run pr_category_label.py to determine which category labels to add/remove -# - Update labels on the PR using GitHub CLI (gh) -# - Check if the PR creator is a member of the specified organization and add/remove labels accordingly - -name: Auto Label PR - -on: - repository_dispatch: - types: [pr-auto-label] -# ensure that the workflow is not running for the same PR multiple times at once -concurrency: - group: pr-auto-label-${{ github.event.client_payload.pr }} - cancel-in-progress: false - -env: - ORG_TO_CHECK: ROCm - ORG_LABEL: "organization: ROCm" - EXTERNAL_LABEL: "external contribution" - -jobs: - auto-label-pr: - runs-on: ubuntu-24.04 - permissions: - contents: read - pull-requests: write - steps: - - name: Generate GitHub App token - id: generate-token - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 - with: - app-id: ${{ secrets.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - owner: ${{ github.repository_owner }} - - - name: Checkout workflows - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - sparse-checkout: '.github' - token: ${{ steps.generate-token.outputs.token }} - # ref will be default branch of the repository - - - name: Set up Python - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 - with: - python-version: '3.12' - - - name: Install python dependencies - run: | - python -m pip install --upgrade pip - pip install pydantic requests - - - name: Set up Git user - run: | - git config user.name "systems-assistant[bot]" - git config user.email "systems-assistant[bot]@users.noreply.github.com" - - - name: Compute Category Labels for PR - id: compute_labels - env: - GH_TOKEN: ${{ steps.generate-token.outputs.token }} - run: | - python .github/scripts/pr_category_label.py \ - --repo ${{ github.repository }} \ - --pr "${{ github.event.client_payload.pr }}" - - - name: Update labels - env: - GH_TOKEN: ${{ steps.generate-token.outputs.token }} - run: | - if [ -n "${{ steps.compute_labels.outputs.label_add }}" ]; then - gh pr edit "${{ github.event.client_payload.pr }}" --add-label "${{ steps.compute_labels.outputs.label_add }}" - fi - - - name: Check if PR creator is in org or collaborator and label accordingly - env: - GH_TOKEN: ${{ steps.generate-token.outputs.token }} - run: | - if gh pr view "${{ github.event.client_payload.pr }}" --json labels -q '.labels[].name' | grep -qFx "imported pr"; then - echo "Skipping org membership labeling for imported pull request." - exit 0 - fi - - PR_USER=$(gh pr view "${{ github.event.client_payload.pr }}" --json author -q .author.login) - if gh api orgs/${{ env.ORG_TO_CHECK }}/members/$PR_USER --silent; then - gh pr edit "${{ github.event.client_payload.pr }}" --add-label "${{ env.ORG_LABEL }}" - else - gh pr edit "${{ github.event.client_payload.pr }}" --add-label "${{ env.EXTERNAL_LABEL }}" - fi - fi \ No newline at end of file diff --git a/.github/workflows/pr-org-label.yml b/.github/workflows/pr-org-label.yml new file mode 100644 index 0000000000..443c1efe92 --- /dev/null +++ b/.github/workflows/pr-org-label.yml @@ -0,0 +1,63 @@ +# Label PRs by Author Org Membership +# ------------- +# This workflow is designed to automatically label pull requests based on the author's membership in the ROCm organization. +name: "Label PRs by Author Org Membership" + +on: + workflow_dispatch: + schedule: + - cron: "*/30 * * * *" # every 30 minutes + +jobs: + label-prs: + if: github.repository == 'ROCm/rocm-systems' + runs-on: ubuntu-24.04 + permissions: + contents: read + pull-requests: write + env: + ORG_TO_CHECK: ROCm + ORG_LABEL: "organization: ROCm" + EXTERNAL_LABEL: "external contribution" + steps: + - name: Generate GitHub App token + id: generate-token + uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + owner: ${{ github.repository_owner }} + + - name: Get open PR numbers + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + gh pr list --state open --json number,labels \ + --jq '[.[] | select( + ([.labels[].name] | index(env.ORG_LABEL) | not) and + ([.labels[].name] | index(env.EXTERNAL_LABEL) | not) + ) | .number] | .[]' \ + > pr_numbers.txt + + - name: Label PRs based on author membership + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + while read pr; do + echo "Checking PR #$pr" + + labels=$(gh pr view "$pr" --json labels --jq '.labels[].name') + + if echo "$labels" | grep -qFx "${{ env.ORG_LABEL }}" || echo "$labels" | grep -qFx "${{ env.EXTERNAL_LABEL }}"; then + echo "PR #$pr already labeled, skipping." + continue + fi + + author=$(gh pr view "$pr" --json author --jq '.author.login') + + if gh api orgs/${{ env.ORG_TO_CHECK }}/members/$author --silent; then + gh pr edit "$pr" --add-label "${{ env.ORG_LABEL }}" + else + gh pr edit "$pr" --add-label "${{ env.EXTERNAL_LABEL }}" + fi + done < pr_numbers.txt