|
1 | | -# name: Lint |
2 | | -# |
3 | | -# on: |
4 | | -# pull_request_target: |
5 | | -# workflow_dispatch: |
6 | | -# merge_group: |
7 | | -# |
8 | | -# jobs: |
9 | | -# lint: |
10 | | -# runs-on: ubuntu-latest |
11 | | -# permissions: |
12 | | -# contents: read |
13 | | -# steps: |
14 | | -# - uses: actions/checkout@v6.0.2 |
15 | | -# with: |
16 | | -# ref: ${{ github.event.pull_request.head.sha || github.ref }} |
17 | | -# repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
18 | | -# |
19 | | -# - name: Setup Ruby |
20 | | -# uses: ruby/setup-ruby@v1.306.0 |
21 | | -# with: |
22 | | -# bundler-cache: false |
23 | | -# |
24 | | -# - name: Install dependencies |
25 | | -# run: bundle install |
26 | | -# |
27 | | -# - name: Run RuboCop |
28 | | -# run: | |
29 | | -# bundle exec rubocop |
30 | | -# |
31 | | -# autocorrect: |
32 | | -# if: github.event.pull_request.head.repo.full_name == github.repository |
33 | | -# runs-on: ubuntu-latest |
34 | | -# permissions: |
35 | | -# contents: write |
36 | | -# steps: |
37 | | -# - uses: actions/checkout@v6.0.2 |
38 | | -# with: |
39 | | -# ref: ${{ github.event.pull_request.head.ref || github.ref }} |
40 | | -# |
41 | | -# - name: Setup Ruby |
42 | | -# uses: ruby/setup-ruby@v1.306.0 |
43 | | -# with: |
44 | | -# bundler-cache: true |
45 | | -# |
46 | | -# - name: Run RuboCop with auto-correct |
47 | | -# run: | |
48 | | -# bundle exec rubocop -A |
49 | | -# |
50 | | -# - name: Check for changes |
51 | | -# run: | |
52 | | -# git config --global user.name "github-actions[bot]" |
53 | | -# git config --global user.email "github-actions[bot]@users.noreply.github.com" |
54 | | -# if git status --porcelain | grep .; then |
55 | | -# echo "changes=true" >> $GITHUB_ENV |
56 | | -# else |
57 | | -# echo "changes=false" >> $GITHUB_ENV |
58 | | -# fi |
59 | | -# |
60 | | -# - name: Commit and push changes |
61 | | -# if: env.changes == 'true' |
62 | | -# run: | |
63 | | -# git add . |
64 | | -# git commit -m "chore: auto-corrected with RuboCop" |
65 | | -# git push |
| 1 | +name: Lint |
| 2 | + |
| 3 | +on: |
| 4 | + # Use `pull_request` (not `pull_request_target`): this workflow checks out and |
| 5 | + # runs untrusted PR code, so it must not run with access to repository secrets. |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | + merge_group: |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v6.0.2 |
| 17 | + |
| 18 | + - name: Setup Ruby |
| 19 | + uses: ruby/setup-ruby@afeafc3d1ab54a631816aba4c914a0081c12ff2f # v1.310.0 |
| 20 | + with: |
| 21 | + bundler-cache: false |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: bundle install |
| 25 | + |
| 26 | + - name: Run RuboCop |
| 27 | + run: | |
| 28 | + bundle exec rubocop |
| 29 | +
|
| 30 | + autocorrect: |
| 31 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v6.0.2 |
| 37 | + with: |
| 38 | + ref: ${{ github.event.pull_request.head.ref || github.ref }} |
| 39 | + |
| 40 | + - name: Setup Ruby |
| 41 | + uses: ruby/setup-ruby@afeafc3d1ab54a631816aba4c914a0081c12ff2f # v1.310.0 |
| 42 | + with: |
| 43 | + bundler-cache: true |
| 44 | + |
| 45 | + - name: Run RuboCop with auto-correct |
| 46 | + run: | |
| 47 | + bundle exec rubocop -A |
| 48 | +
|
| 49 | + - name: Check for changes |
| 50 | + run: | |
| 51 | + git config --global user.name "github-actions[bot]" |
| 52 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | + if git status --porcelain | grep .; then |
| 54 | + echo "changes=true" >> $GITHUB_ENV |
| 55 | + else |
| 56 | + echo "changes=false" >> $GITHUB_ENV |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Commit and push changes |
| 60 | + if: env.changes == 'true' |
| 61 | + run: | |
| 62 | + git add . |
| 63 | + git commit -m "chore: auto-corrected with RuboCop" |
| 64 | + git push |
0 commit comments