|
| 1 | +name: Sorbet |
| 2 | +on: # yamllint disable-line rule:truthy |
| 3 | + pull_request: |
| 4 | + branches: [main] # Adjust this to the branch you want for creating PRs |
| 5 | + |
| 6 | +jobs: |
| 7 | + check-sorbet-typing-mode: |
| 8 | + name: Sorbet Typing Mode Check |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 16 | + |
| 17 | + - name: Get Changed Files |
| 18 | + id: changed-files |
| 19 | + uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5 |
| 20 | + with: |
| 21 | + files: '**/lib/dependabot/**/*.rb' # Only get changed Ruby files in dependabot directory |
| 22 | + |
| 23 | + - name: Verify Sorbet Typing Mode |
| 24 | + run: | |
| 25 | + echo "Starting Sorbet typing check..." |
| 26 | + missing_sorbet_typing=false |
| 27 | +
|
| 28 | + # Iterate over the changed Ruby files and filter only Ruby files |
| 29 | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do |
| 30 | + echo "Checking $file for Sorbet typing..." |
| 31 | + # Check if the top of the file has `# typed: strict` or `# typed: strong` |
| 32 | + if ! head -n 10 "$file" | grep -E -q '^# typed: (strict|strong)'; then |
| 33 | + echo "No Sorbet typing found at the top of $file" |
| 34 | + missing_sorbet_typing=true |
| 35 | + else |
| 36 | + echo "Sorbet typing found at the top of $file" |
| 37 | + fi |
| 38 | + done |
| 39 | +
|
| 40 | + if [ "$missing_sorbet_typing" = true ]; then |
| 41 | + echo "::error ::One or more Ruby files are missing Sorbet typing at the top." |
| 42 | + echo "::error ::Please ensure you add either '# typed: strict' or '# typed: strong' at the very top of the file." |
| 43 | + echo "::error ::Follow these steps to apply Sorbet typing:" |
| 44 | + echo "::error ::1. Add '# typed: strict' or '# typed: strong' to the top of your Ruby file." |
| 45 | + echo "::error ::2. Use '# typed: strict' for the most strict typing checks, and '# typed: strong' for more flexible checks." |
| 46 | + echo "::error ::3. Add 'extend T::Sig' to your class or module to enable Sorbet signatures." |
| 47 | + echo "::error ::4. Add 'require 'sorbet-runtime'' to enable Sorbet runtime checking." |
| 48 | + echo "::error ::For more details on using Sorbet, check out the following resources:" |
| 49 | + echo "::error ::1. [Getting Started with Sorbet](https://sorbet.org)" |
| 50 | + exit 1 # Fail the job if any file is missing Sorbet typing |
| 51 | + else |
| 52 | + echo "All changed Ruby files have Sorbet typings." |
| 53 | + fi |
0 commit comments