diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml new file mode 100644 index 0000000..ac72028 --- /dev/null +++ b/.github/workflows/validate-pr.yml @@ -0,0 +1,61 @@ +name: PR Title and Label Validation + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Validate PR Title + shell: bash + run: | + PR_TITLE="${{ github.event.pull_request.title }}" + regex='^\[([A-Za-z0-9-]+)\]:\s(\S+)\s(.+)$' + if [[ ! "$PR_TITLE" =~ $regex ]]; then + echo "โŒ PR title does not match the required format: [ClickUp Task ID]: [emoji] [Task Name]" + echo "Example: [86c4em56j]: โ›ฉ๏ธ PR Title Validations Workflow or [DEV-1234]: ๐Ÿงจ Testing" + exit 1 + fi + + - name: Validate PR Labels + shell: bash + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + REPO: ${{ github.repository }} + run: | + labels=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels -q '.labels[].name' | tr '\n' ' ') + echo "Labels: $labels" + + fail=0 + + # Type + if ! echo "$labels" | grep -Eq '\b(feature|fix|refactor|hotfix)\b'; then + echo "โŒ Missing Type label (feature, fix, refactor, hotfix)" + fail=1 + fi + + # Version introduced: accept any x.xx + if ! echo "$labels" | grep -Eq '\b[0-9]+\.[0-9]{2}\b'; then + echo "โŒ Missing Version introduced label (e.g. 2.49, 3.07, etc.)" + fail=1 + fi + + # Stream/Team + if ! echo "$labels" | grep -Eq '\b(rewards|vector|reliability)\b'; then + echo "โŒ Missing Stream/Team label (rewards, vector, reliability)" + fail=1 + fi + + if [ "$fail" -eq 1 ]; then + exit 1 + fi + + - name: Success + if: ${{ success() }} + run: echo "โœ… PR title and labels are valid!" \ No newline at end of file