-
Notifications
You must be signed in to change notification settings - Fork 2k
Add PR platform labeling #35327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PR platform labeling #35327
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Coverage — Missing A PR closed and reopened (draft→ready cycling, or revived after merge-conflict resolution) will not have its platform labels evaluated. Add types: [opened, synchronize, reopened] |
||
|
|
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [moderate] Safety — Context expressions interpolated directly into shell
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}Then reference
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [moderate] Safety — Context expressions interpolated directly into shell
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}Reference |
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Coverage — No detection for Tizen/Linux platform files The repo has a Consider adding: HAS_TIZEN=$(echo "${FILES}" | grep -ciE '(/Tizen/|\.tizen\.cs)' || true)And: if [ "${HAS_TIZEN}" -gt 0 ]; then
LABELS="${LABELS} platform/linux"
fi
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Coverage — No detection for Tizen/Linux platform files The repo has a Add: HAS_TIZEN=$(echo "${FILES}" | grep -ciE '(/Tizen/|\.tizen\.cs)' || true)And apply |
||
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] Correctness — Per MAUI conventions, The fix requires splitting the detection: HAS_IOS_DIR=$(echo "${FILES}" | grep -ciE '/iOS/' || true)
HAS_IOS_EXT=$(echo "${FILES}" | grep -ciE '\.ios\.cs' || true)Then: if [ "${HAS_IOS_DIR}" -gt 0 ] || [ "${HAS_IOS_EXT}" -gt 0 ]; then
LABELS="${LABELS} platform/ios"
fi
if [ "${HAS_IOS_EXT}" -gt 0 ] || [ "${HAS_CATALYST}" -gt 0 ]; then
LABELS="${LABELS} platform/macos"
fiThis way,
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] Correctness — Per MAUI conventions, Fix by splitting detection: HAS_IOS_DIR=$(echo "${FILES}" | grep -ciE '/iOS/' || true)
HAS_IOS_EXT=$(echo "${FILES}" | grep -ciE '\.ios\.cs' || true)Then apply |
||
| 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}" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Correctness — Labels are only added, never removed on The workflow uses For # Remove platform labels not in current set
for label in platform/android platform/ios platform/macos platform/windows platform/linux; do
if ! echo "${LABELS}" | grep -q "${label}"; then
gh pr edit "${PR_NUMBER}" --repo "${GH_REPO}" --remove-label "${label}" 2>/dev/null || true
fi
done
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Correctness — Labels are only added, never removed on Workflow uses for label in platform/android platform/ios platform/macos platform/windows platform/linux; do
if ! echo "${LABELS}" | grep -q "${label}"; then
gh pr edit "${PR_NUMBER}" --repo "${GH_REPO}" --remove-label "${label}" 2>/dev/null || true
fi
done |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] Coverage — Missing
reopenedtrigger eventA PR closed and then reopened (common after merge conflicts are resolved or after a draft→ready transition that was previously closed) will not have its platform labels evaluated. Add
reopenedto ensure labels are applied: