From 7b4a4d9ae0e3a14a39f3150498ef0a9398f6c124 Mon Sep 17 00:00:00 2001 From: DaneEvans Date: Fri, 1 Aug 2025 00:19:23 +1000 Subject: [PATCH] Feat/2586 pr labeler (#2587) --- .github/labeler.yml | 31 +++++++++++++++++++++++ .github/release.yml | 2 ++ .github/workflows/pr_enforce_labels.yml | 24 ++++++++++++++++++ .github/workflows/pull-request-target.yml | 15 +++++++++++ .github/workflows/pull-request.yml | 4 +-- CONTRIBUTING.md | 6 +++++ 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/pr_enforce_labels.yml create mode 100644 .github/workflows/pull-request-target.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..4c01fa00b --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,31 @@ +# Auto Labeler rulse using https://github.com/actions/labeler +# + +# 'fix' in title/branch -> bug +# 'feat' in title/branch -> enhancement +# 'repo' in title/branch OR changes to ~/.github/ -> repo +# 'bug_fallthrough' for everything else except auto +# +# - [ ] need to look at title. waiting on https://github.com/actions/labeler/pull/866 + +# Add 'enhancement' label to any PR where the head branch name contains `feat` +enhancement: + - head-branch: ['feat'] + + # Add 'repo' label to any PR where the head branch name contains `repo` + # or files in the .github dir +repo: +- any: + - head-branch: ['repo'] + - changed-files: + - any-glob-to-any-file: '.github' + + # Add 'bug' label to any PR where the head branch name contains `fix` or `bug` +bugfix: + - head-branch: ['fix', 'bug'] + +# our fallback - bug except repo, feat, or automated pipelines +# bug_fallthrough: +# - all: +# - head-branch: ['^((?!feat).)*$', '^((?!repo).)*$', '^((?!renovate).)*$', '^((?!scheduled).)*$'] + diff --git a/.github/release.yml b/.github/release.yml index 08bf63e50..56b3b91b7 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -18,6 +18,7 @@ changelog: - dependencies - repo - automation + - release - title: 👷Dependencies labels: @@ -30,3 +31,4 @@ changelog: - title: 🤖Automated labels: - automation + - release diff --git a/.github/workflows/pr_enforce_labels.yml b/.github/workflows/pr_enforce_labels.yml new file mode 100644 index 000000000..8a4c0d00d --- /dev/null +++ b/.github/workflows/pr_enforce_labels.yml @@ -0,0 +1,24 @@ +name: Check PR Labels + +on: + pull_request: + types: [opened, edited, labeled, unlabeled, synchronize, reopened] + +permissions: + pull-requests: read + contents: read + +jobs: + check-label: + runs-on: ubuntu-24.04 + steps: + - name: Check for PR labels + uses: actions/github-script@v7 + with: + script: | + const labels = context.payload.pull_request.labels.map(label => label.name); + const requiredLabels = ['bugfix', 'enhancement', 'automation', 'dependencies', 'repo', 'release']; + const hasRequiredLabel = labels.some(label => requiredLabels.includes(label)); + if (!hasRequiredLabel) { + core.setFailed(`PR must have at least one of the following labels before it can be merged: ${requiredLabels.join(', ')}.`); + } diff --git a/.github/workflows/pull-request-target.yml b/.github/workflows/pull-request-target.yml new file mode 100644 index 000000000..cf0325677 --- /dev/null +++ b/.github/workflows/pull-request-target.yml @@ -0,0 +1,15 @@ +name: "Pull Request Labeler" +on: +- pull_request_target +# Do not execute arbitary code on this workflow. +# See warnings at https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - id: label-the-PR + uses: actions/labeler@v5 \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9b8050f2b..38e2322ab 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -28,7 +28,7 @@ jobs: GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }} check-workflow-status: - name: Check Workflow Status # Matches another in merge-queue, and is required. + name: Check Workflow Status runs-on: ubuntu-latest needs: [ @@ -46,4 +46,4 @@ jobs: fi } exit_on_result "build_and_detekt" "${{ needs.build_and_detekt.result }}" - exit_on_result "androidTest" "${{ needs.androidTest.result }}" \ No newline at end of file + exit_on_result "androidTest" "${{ needs.androidTest.result }}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 04aa87f7c..e541e596b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,6 +60,12 @@ Comprehensive testing helps prevent regressions and ensures a stable experience ## Pull Requests +- branches should start with: + - bugfix + - enhancement + - dependencies + - repo + - reserved (release, automation) - Ensure your branch is up to date with the latest `main` branch before submitting a PR. - Provide a meaningful title and description for your PR. - Inlude information on how to test and/or replicate if it is not obvious.