Files
rocm-systems/.github/workflows/pr-auto-label.yml
T
Joseph Macaranas bac3beada7 [GitHub Actions] Change Auto-Label Trigger (#228)
- The execution of applying labels is now in a dispatched workflow that executes from the default branch and has access to the GitHub App to be able to write labels.
- New GitHub Actions to enable/toggle workflows from activating during import of subprojects.
- Workflows to add new subtrees to develop and release branches.
2025-08-09 21:59:57 -04:00

96 строки
3.5 KiB
YAML

# 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