|
| 1 | +name: Validate Proposal Naming |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - '**' |
| 9 | + types: [opened, synchronize] |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + pr_number: |
| 13 | + description: 'The PR number to validate the naming convention for' |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +jobs: |
| 18 | + validate-proposal-naming: |
| 19 | + runs-on: ubuntu-slim |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Set PR number |
| 27 | + run: | |
| 28 | + # Set PR_NUMBER based on context: use inputs.pr_number for manual dispatch, |
| 29 | + # otherwise use github.event.number for pull request events |
| 30 | + if [ -n "${{ inputs.pr_number }}" ]; then |
| 31 | + echo "PR_NUMBER=printf \"%04d\n\" ${{ inputs.pr_number }}" >> $GITHUB_ENV |
| 32 | + echo "Using PR number from manual input: ${{ inputs.pr_number }}" |
| 33 | + else |
| 34 | + echo "PR_NUMBER=printf \"%04d\n\" ${{ github.event.number }}" >> $GITHUB_ENV |
| 35 | + echo "Using PR number from event: ${{ github.event.number }}" |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Validate proposal naming |
| 39 | + run: | |
| 40 | + # Get the list of NEW files added (not modifications to existing files) |
| 41 | + CHANGED_FILES=$(git diff --name-only --diff-filter=A origin/${{ github.base_ref }}...HEAD | grep '^THV-' || true) |
| 42 | +
|
| 43 | + # Skip validation if no new proposal files are being added |
| 44 | + # (modifications to existing proposals don't need naming validation) |
| 45 | + if [ -z "$CHANGED_FILES" ]; then |
| 46 | + echo "ℹ️ No new proposal files added in this PR (only modifications to existing proposals or manual trigger)" |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | +
|
| 50 | + echo "Checking proposal file naming convention..." |
| 51 | + echo "Files to check:" |
| 52 | + echo "$CHANGED_FILES" |
| 53 | +
|
| 54 | + VALIDATION_FAILED=false |
| 55 | +
|
| 56 | + # Check each changed file |
| 57 | + while IFS= read -r file; do |
| 58 | + if [ -n "$file" ] && [ -f "$file" ]; then |
| 59 | + filename=$(basename "$file") |
| 60 | + echo "Checking file: $filename" |
| 61 | +
|
| 62 | + # Check if the filename follows the THV-####-name pattern with the current PR number |
| 63 | + if echo "$filename" | grep -qE "^THV-${PR_NUMBER}-.*\.md$"; then |
| 64 | + echo "✅ $filename follows the correct naming convention" |
| 65 | + else |
| 66 | + echo "❌ $filename does not follow the correct naming convention" |
| 67 | + echo " Expected format: THV-${PR_NUMBER}-name-of-your-proposal.md" |
| 68 | + echo " Where ${PR_NUMBER} is the current PR number" |
| 69 | + VALIDATION_FAILED=true |
| 70 | + fi |
| 71 | + fi |
| 72 | + done <<< "$CHANGED_FILES" |
| 73 | +
|
| 74 | + # Check if any validation failed |
| 75 | + if [ "$VALIDATION_FAILED" = "true" ]; then |
| 76 | + echo "" |
| 77 | + echo "❌ Validation failed! Some proposal files do not follow the naming convention." |
| 78 | + echo "" |
| 79 | + echo "Proposal files must follow this naming pattern:" |
| 80 | + echo " THV-${PR_NUMBER}-name-of-your-proposal.md" |
| 81 | + echo "" |
| 82 | + echo "Where:" |
| 83 | + echo " - THV- is the prefix" |
| 84 | + echo " - ${PR_NUMBER} is the current PR number" |
| 85 | + echo " - name-of-your-proposal is a descriptive name in kebab-case" |
| 86 | + echo " - .md is the file extension" |
| 87 | + echo "" |
| 88 | + echo "Example of valid name for this PR:" |
| 89 | + echo " - THV-${PR_NUMBER}-new-feature-proposal.md" |
| 90 | + echo "" |
| 91 | + exit 1 |
| 92 | + else |
| 93 | + echo "" |
| 94 | + echo "✅ All proposal files follow the correct naming convention!" |
| 95 | + fi |
0 commit comments