|
| 1 | +name: Validate Proposal Naming |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - 'docs/proposals/**' |
| 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-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 |
| 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=${{ inputs.pr_number }}" >> $GITHUB_ENV |
| 32 | + echo "Using PR number from manual input: ${{ inputs.pr_number }}" |
| 33 | + else |
| 34 | + echo "PR_NUMBER=${{ 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 changed files in docs/proposals |
| 41 | + CHANGED_FILES=$(git diff --name-only --diff-filter A origin/${{ github.base_ref }}...HEAD | grep '^docs/proposals/') |
| 42 | +
|
| 43 | + # This is here to avoid errors when running this workflow manually without a PR |
| 44 | + if [ -z "$CHANGED_FILES" ]; then |
| 45 | + echo "ℹ️ No proposal files changed in this PR" |
| 46 | + exit 0 |
| 47 | + fi |
| 48 | +
|
| 49 | + echo "Checking proposal file naming convention..." |
| 50 | + echo "Files to check:" |
| 51 | + echo "$CHANGED_FILES" |
| 52 | +
|
| 53 | + VALIDATION_FAILED=false |
| 54 | +
|
| 55 | + # Check each changed file |
| 56 | + while IFS= read -r file; do |
| 57 | + if [ -n "$file" ] && [ -f "$file" ]; then |
| 58 | + filename=$(basename "$file") |
| 59 | + echo "Checking file: $filename" |
| 60 | +
|
| 61 | + # Check if the filename follows the THV-####-name pattern with the current PR number |
| 62 | + if echo "$filename" | grep -qE "^THV-${PR_NUMBER}-.*\.md$"; then |
| 63 | + echo "✅ $filename follows the correct naming convention" |
| 64 | + else |
| 65 | + echo "❌ $filename does not follow the correct naming convention" |
| 66 | + echo " Expected format: THV-${PR_NUMBER}-name-of-your-proposal.md" |
| 67 | + echo " Where ${PR_NUMBER} is the current PR number" |
| 68 | + VALIDATION_FAILED=true |
| 69 | + fi |
| 70 | + fi |
| 71 | + done <<< "$CHANGED_FILES" |
| 72 | +
|
| 73 | + # Check if any validation failed |
| 74 | + if [ "$VALIDATION_FAILED" = "true" ]; then |
| 75 | + echo "" |
| 76 | + echo "❌ Validation failed! Some proposal files do not follow the naming convention." |
| 77 | + echo "" |
| 78 | + echo "Proposal files must follow this naming pattern:" |
| 79 | + echo " THV-${PR_NUMBER}-name-of-your-proposal.md" |
| 80 | + echo "" |
| 81 | + echo "Where:" |
| 82 | + echo " - THV- is the prefix" |
| 83 | + echo " - ${PR_NUMBER} is the current PR number" |
| 84 | + echo " - name-of-your-proposal is a descriptive name in kebab-case" |
| 85 | + echo " - .md is the file extension" |
| 86 | + echo "" |
| 87 | + echo "Example of valid name for this PR:" |
| 88 | + echo " - THV-${PR_NUMBER}-new-feature-proposal.md" |
| 89 | + echo "" |
| 90 | + exit 1 |
| 91 | + else |
| 92 | + echo "" |
| 93 | + echo "✅ All proposal files follow the correct naming convention!" |
| 94 | + fi |
0 commit comments