armbian-build/.github/workflows/auto-label-pr.yml
Igor Pecovnik 28f5839d08 chore: standardize workflow names
Make all workflow names consistent and action-oriented:
- Use action verb first (Announce, Auto-label, Build, Check, Clean, Help, Label, Lint, Listen, Rewrite, Scan, Sync, Welcome)
- Keep names concise and descriptive
- Remove unnecessary details from the name

Changes:
- Analyze kernel security (was: Kernel Hardening Analysis)
- Announce merge (was: Announce PR merge to Discord)
- Announce PR (was: Announce PR on Discord for review)
- Auto-label PR (was: Automatic Pull Request Labeling)
- Build PR artifacts (was: Generate Artifacts on PR if...)
- Check PR assets (was: Check new board assets exist...)
- Clean workflow logs (was: Clean Workflow Logs)
- Sync Jira (was: Jira Sync)
- Help forks (was: Forked Helper)
- Label PR on approval (was: PR review labeler)
- Lint scripts (was: Lint on Scripts)
- Listen PR review (was: PR review listener)
- Rewrite kernel configs (was: Rewrite kernel configs - same)
- Scan security (was: Scorecards Security Scan)
- Sync board list (was: Update Board Lists)
- Sync labels (was: Sync Labels from YAML)
- Sync maintainers (was: Sync maintainers status)
- Sync tools (was: Update Tools in Scripts)
- Welcome first-time contributor (was: Welcome first-time issue contributor)
- Welcome first-time PR contributor (was: same - kept as is)
2025-12-25 12:00:52 +01:00

114 lines
3.8 KiB
YAML

name: Auto-label PR
# Sets labels automatically based on:
# - PR size (job: label-size)
# - File categories using .github/labeler config (job: label-category)
# - PR creation date for quarterly tracking (job: label-by-date)
# - Removes "Ready to merge" label on PR update (job: label-remove)
run-name: 'Set labels - PR #${{ github.event.pull_request.number }} ("${{ github.event.pull_request.title }}")'
on: pull_request_target
# Grant required permissions globally
permissions:
contents: read # Required for checking changed files
pull-requests: write # Required for labeling PRs
issues: write # Required for adding/removing labels
jobs:
label-remove:
name: "Remove Ready to merge"
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' }}
runs-on: ubuntu-latest
steps:
- name: Checkout the pull request
uses: actions/checkout@v6
- name: Check for label using GH CLI
id: check
run: |
gh pr view ${{ github.event.pull_request.number }} --json labels -q '.labels[].name' | grep -q 'Ready to merge' && echo "has_label=true" >> $GITHUB_OUTPUT || echo "has_label=false" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove "Ready to merge" label
if: steps.check.outputs.has_label == 'true'
uses: PauMAVA/add-remove-label-action@v1.0.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
add: ""
remove: "Ready to merge"
label-category:
name: "Category Labels"
runs-on: ubuntu-latest
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' }}
steps:
# Checks out the repository to read files for matching with labeler config
- uses: actions/checkout@v6
# Applies labels based on the .github/labeler.yml config
- uses: actions/labeler@v6
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
label-size:
name: "Size Label"
runs-on: ubuntu-latest
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' }}
steps:
# Automatically adds size labels based on total changed lines
- name: Label by size
uses: pascalgn/size-label-action@v0.5.5
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
sizes: >
{
"0": "small",
"50": "medium",
"250": "large"
}
label-by-date:
name: "Date label (Quarters)"
runs-on: ubuntu-latest
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' }}
steps:
# Determines the label (02, 05, 08, 11) based on PR creation month
- name: Determine quarter label
env:
PR_CREATED_AT: ${{ github.event.pull_request.created_at }}
run: |
echo "PR created at: $PR_CREATED_AT"
# Extract the numeric month (e.g., 04 for April)
MONTH=$(date -d "$PR_CREATED_AT" +%m | sed 's/^0*//')
echo "Month extracted: $MONTH"
# Determine quarter-end label based on month
if [ "$MONTH" -le 2 ] || [ "$MONTH" -eq 12 ]; then
LABEL="02"
elif [ "$MONTH" -le 5 ]; then
LABEL="05"
elif [ "$MONTH" -le 8 ]; then
LABEL="08"
else
LABEL="11"
fi
# Set as environment variable for next step
echo "LABEL=${LABEL}" >> $GITHUB_ENV
# Adds the quarter label to the PR
- name: Add quarter label
uses: PauMAVA/add-remove-label-action@v1.0.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
add: "${{ env.LABEL }}"