From 3104a4ebf443d7f27291b17b3cc01ade81acc269 Mon Sep 17 00:00:00 2001 From: Ronit Sabhaya Date: Sun, 24 May 2026 18:20:55 -0500 Subject: [PATCH] added the labeler github action Co-authored-by: Renish Patel --- .github/labeler.yml | 23 +++++++ .github/labels.yml | 47 +++++++++++++ .github/workflows/label-sync.yml | 26 +++++++ .github/workflows/labeler.yml | 112 +++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 .github/labeler.yml create mode 100644 .github/labels.yml create mode 100644 .github/workflows/label-sync.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000000..27a273cc7db --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,23 @@ +"component/server": + - "fdbserver/**/*" + +"component/client": + - "fdbclient/**/*" + +"component/flow": + - "flow/**/*" + +"component/rpc": + - "fdbrpc/**/*" + +"component/test": + - "tests/**/*" + - "fdbserver/workloads/**/*" + - "bindings/c/test/**/*" + +"component/bindings": + - "bindings/**/*" + +"component/documentation": + - "documentation/**/*" + - "**/*.md" diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 00000000000..09555a09b02 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,47 @@ +- name: "size/XS" + color: "3cbf46" + description: "XS Pull Request (<10 lines change)" + +- name: "size/S" + color: "5cd667" + description: "S Pull Request (10-49 lines change)" + +- name: "size/M" + color: "ffc107" + description: "M Pull Request (50-199 lines change)" + +- name: "size/L" + color: "fd7e14" + description: "L Pull Request (200-499 lines change)" + +- name: "size/XL" + color: "dc3545" + description: "XL Pull Request (>=500 lines change)" + +- name: "component/server" + color: "007bff" + description: "Server-side modifications (fdbserver)" + +- name: "component/client" + color: "17a2b8" + description: "Client-side modifications (fdbclient)" + +- name: "component/flow" + color: "6f42c1" + description: "Flow asynchronous framework changes" + +- name: "component/rpc" + color: "e83e8c" + description: "RPC / network protocol changes" + +- name: "component/test" + color: "20c997" + description: "Tests and simulation workload changes" + +- name: "component/bindings" + color: "6610f2" + description: "Language binding changes" + +- name: "component/documentation" + color: "6c757d" + description: "Documentation changes" diff --git a/.github/workflows/label-sync.yml b/.github/workflows/label-sync.yml new file mode 100644 index 00000000000..d3a8e31e671 --- /dev/null +++ b/.github/workflows/label-sync.yml @@ -0,0 +1,26 @@ +name: "Label Sync" + +on: + push: + branches: + - main + paths: + - '.github/labels.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Sync GitHub Labels + uses: crazy-max/ghaction-github-labeler@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + yaml-file: .github/labels.yml + skip-delete: false # Set to true if you don't want to delete manually created labels that are missing from labels.yml diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 00000000000..28f2e5385c0 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,112 @@ +name: PR Label Analysis + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + +jobs: + analyze: + name: Analyze PR for labeling + runs-on: ubuntu-latest + + steps: + - name: Save PR metadata + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + mkdir -p ./pr-metadata + echo "${PR_NUMBER}" > ./pr-metadata/pr-number.txt + + - name: Upload PR metadata as artifact + uses: actions/upload-artifact@v4 + with: + name: pr-metadata-${{ github.event.pull_request.number }} + path: pr-metadata/ + retention-days: 1 + +--- + +name: PR Label Apply + +on: + workflow_run: + workflows: ["PR Label Analysis"] + types: + - completed + +permissions: + contents: read + +jobs: + apply-labels: + name: Apply labels to PR + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download PR metadata artifact + uses: actions/download-artifact@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + pattern: pr-metadata-* + merge-multiple: true + + - name: Read PR number + id: pr-number + run: | + PR_NUMBER=$(cat "pr-number.txt") + echo "number=${PR_NUMBER}" >> $GITHUB_OUTPUT + echo "PR Number: ${PR_NUMBER}" + + - name: Apply Path-Based Labels + uses: actions/labeler@v5 + with: + pr-number: ${{ steps.pr-number.outputs.number }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/labeler.yml + sync-labels: true + + - name: Calculate and Apply Size Label + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ steps.pr-number.outputs.number }} + run: | + PR_DATA=$(curl -s -H "Authorization: token $GH_TOKEN" \ + https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER) + + ADDITIONS=$(echo "$PR_DATA" | jq '.additions') + DELETIONS=$(echo "$PR_DATA" | jq '.deletions') + TOTAL=$((ADDITIONS + DELETIONS)) + + if [ $TOTAL -lt 10 ]; then + SIZE_LABEL="size/XS" + elif [ $TOTAL -lt 50 ]; then + SIZE_LABEL="size/S" + elif [ $TOTAL -lt 200 ]; then + SIZE_LABEL="size/M" + elif [ $TOTAL -lt 500 ]; then + SIZE_LABEL="size/L" + else + SIZE_LABEL="size/XL" + fi + + CURRENT_LABELS=$(echo "$PR_DATA" | jq -r '.labels[].name') + + for label in $CURRENT_LABELS; do + if [[ "$label" =~ ^size/ ]] && [ "$label" != "$SIZE_LABEL" ]; then + gh pr edit $PR_NUMBER --remove-label "$label" || true + fi + done + + if ! echo "$CURRENT_LABELS" | grep -q "^$SIZE_LABEL$"; then + gh pr edit $PR_NUMBER --add-label "$SIZE_LABEL" + fi