From 939a6922e94c50baf1a7c7f892a6daa80e85216f Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 6 May 2026 18:31:43 +0200 Subject: [PATCH] Add PR platform labeling --- .github/workflows/platform-label.yml | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/platform-label.yml diff --git a/.github/workflows/platform-label.yml b/.github/workflows/platform-label.yml new file mode 100644 index 000000000000..ab5ce81f271c --- /dev/null +++ b/.github/workflows/platform-label.yml @@ -0,0 +1,61 @@ +# Auto-label PRs with platform/android, platform/ios, platform/macos, and/or platform/windows +# based on changed file paths. Applies all matching labels. +# If no platform-specific files are detected, no labels are applied. + +name: Platform Label + +on: + pull_request: + types: [opened, synchronize] + +permissions: + contents: read + pull-requests: write + +jobs: + label: + runs-on: ubuntu-latest + steps: + - name: Detect platform from changed files + env: + GH_TOKEN: ${{ github.token }} + run: | + PR_NUMBER="${{ github.event.pull_request.number }}" + + FILES=$(gh api "repos/${{ github.repository }}/pulls/${PR_NUMBER}/files" --paginate --jq '.[].filename' 2>/dev/null || true) + if [ -z "${FILES}" ]; then + echo "No files found or API error — skipping." + exit 0 + fi + + HAS_ANDROID=$(echo "${FILES}" | grep -ciE '(/Android/|\.android\.cs)' || true) + HAS_IOS=$(echo "${FILES}" | grep -ciE '(/iOS/|\.ios\.cs)' || true) + HAS_CATALYST=$(echo "${FILES}" | grep -ciE '(/MacCatalyst/|\.maccatalyst\.cs)' || true) + HAS_WINDOWS=$(echo "${FILES}" | grep -ciE '(/Windows/|\.windows\.cs)' || true) + + echo "Platform file counts — Android: ${HAS_ANDROID}, iOS: ${HAS_IOS}, MacCatalyst: ${HAS_CATALYST}, Windows: ${HAS_WINDOWS}" + + LABELS="" + if [ "${HAS_ANDROID}" -gt 0 ]; then + LABELS="${LABELS} platform/android" + fi + if [ "${HAS_IOS}" -gt 0 ]; then + LABELS="${LABELS} platform/ios" + fi + if [ "${HAS_CATALYST}" -gt 0 ]; then + LABELS="${LABELS} platform/macos" + fi + if [ "${HAS_WINDOWS}" -gt 0 ]; then + LABELS="${LABELS} platform/windows" + fi + + LABELS=$(echo "${LABELS}" | xargs) + if [ -z "${LABELS}" ]; then + echo "No platform-specific files detected — no labels applied." + exit 0 + fi + + # Convert space-separated to comma-separated for gh cli + LABEL_CSV=$(echo "${LABELS}" | tr ' ' ',') + echo "Applying labels: ${LABELS}" + gh pr edit "${PR_NUMBER}" --repo "${{ github.repository }}" --add-label "${LABEL_CSV}"