|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +name: TODO Check |
| 18 | + |
| 19 | +on: |
| 20 | + pull_request: |
| 21 | + branches: [main] |
| 22 | + push: |
| 23 | + branches: [main] |
| 24 | + |
| 25 | +jobs: |
| 26 | + check-todos: |
| 27 | + name: Check TODOs have issue links |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Check for TODOs without issue links |
| 34 | + run: | |
| 35 | + #!/bin/bash |
| 36 | + set -euo pipefail |
| 37 | +
|
| 38 | + echo "🔍 Checking for TODOs without issue links..." |
| 39 | + echo "" |
| 40 | +
|
| 41 | + # Define patterns for valid TODOs with issue links |
| 42 | + # Valid formats: |
| 43 | + # // TODO(#123): description |
| 44 | + # // TODO(https://github.com/org/repo/issues/123): description |
| 45 | + # # TODO(#123): description |
| 46 | + # # TODO(https://...): description |
| 47 | +
|
| 48 | + # Find all TODO comments that DON'T have an issue reference |
| 49 | + # Pattern explanation: |
| 50 | + # - Match TODO comments without parentheses containing # or http |
| 51 | + # - Exclude: TODO(#123), TODO(https://...) |
| 52 | +
|
| 53 | + INVALID_TODOS=$(grep -rn \ |
| 54 | + --include="*.py" \ |
| 55 | + --include="*.ts" \ |
| 56 | + --include="*.js" \ |
| 57 | + --include="*.go" \ |
| 58 | + --include="*.rs" \ |
| 59 | + --include="*.java" \ |
| 60 | + --include="*.kt" \ |
| 61 | + --include="*.sh" \ |
| 62 | + --include="*.yaml" \ |
| 63 | + --include="*.yml" \ |
| 64 | + -E '(#|//)\s*TODO[^(]|TODO\(\s*\)|TODO\([^#h][^)]*\)' \ |
| 65 | + --exclude-dir=node_modules \ |
| 66 | + --exclude-dir=.git \ |
| 67 | + --exclude-dir=target \ |
| 68 | + --exclude-dir=dist \ |
| 69 | + --exclude-dir=build \ |
| 70 | + --exclude-dir=.cache \ |
| 71 | + --exclude-dir=bazel-* \ |
| 72 | + --exclude-dir=vendor \ |
| 73 | + --exclude-dir=site \ |
| 74 | + --exclude-dir=.venv \ |
| 75 | + --exclude-dir=venv \ |
| 76 | + --exclude-dir=__pycache__ \ |
| 77 | + . 2>/dev/null || true) |
| 78 | +
|
| 79 | + # Filter out documentation examples (in .md files showing TODO syntax) |
| 80 | + INVALID_TODOS=$(echo "$INVALID_TODOS" | grep -v "\.md:" || true) |
| 81 | + # Filter out this workflow file itself |
| 82 | + INVALID_TODOS=$(echo "$INVALID_TODOS" | grep -v "todo-check.yml" || true) |
| 83 | +
|
| 84 | + if [ -n "$INVALID_TODOS" ]; then |
| 85 | + echo "❌ Found TODOs without issue links:" |
| 86 | + echo "" |
| 87 | + echo "$INVALID_TODOS" |
| 88 | + echo "" |
| 89 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 90 | + echo "" |
| 91 | + echo "📝 TODOs must reference a GitHub issue. Valid formats:" |
| 92 | + echo "" |
| 93 | + echo " Python/Bash/YAML:" |
| 94 | + echo " # TODO(#123): description" |
| 95 | + echo " # TODO(https://github.com/google/dotprompt/issues/123): description" |
| 96 | + echo "" |
| 97 | + echo " JavaScript/TypeScript/Java/Rust/Go:" |
| 98 | + echo " // TODO(#123): description" |
| 99 | + echo " // TODO(https://github.com/google/dotprompt/issues/123): description" |
| 100 | + echo "" |
| 101 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 102 | + echo "" |
| 103 | + echo "💡 To create an issue for your TODO:" |
| 104 | + echo " gh issue create --title 'Your TODO title' --body 'Description'" |
| 105 | + echo "" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + echo "✅ All TODOs have proper issue links!" |
0 commit comments