Skip to content

Commit 41bdbef

Browse files
committed
Split lint into two jobs for security
Separate the lint workflow into: - lint: read-only job that checks out fork code safely with contents: read permission, runs rubocop without auto-correct - autocorrect: write job that only runs for same-repo PRs, checks out by branch ref, and pushes auto-corrections This prevents fork PRs from executing untrusted code with write-scoped GITHUB_TOKEN.
1 parent 1cc71e4 commit 41bdbef

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ on:
55
workflow_dispatch:
66
merge_group:
77

8-
permissions:
9-
contents: write
10-
checks: write
11-
128
jobs:
139
lint:
1410
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
1513
steps:
1614
- uses: actions/checkout@v6.0.2
1715
with:
@@ -23,12 +21,30 @@ jobs:
2321
with:
2422
bundler-cache: true
2523

24+
- name: Run RuboCop
25+
run: |
26+
bundle exec rubocop
27+
28+
autocorrect:
29+
if: github.event.pull_request.head.repo.full_name == github.repository
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: write
33+
steps:
34+
- uses: actions/checkout@v6.0.2
35+
with:
36+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
37+
38+
- name: Setup Ruby
39+
uses: ruby/setup-ruby@v1.299.0
40+
with:
41+
bundler-cache: true
42+
2643
- name: Run RuboCop with auto-correct
2744
run: |
2845
bundle exec rubocop -A
2946
3047
- name: Check for changes
31-
id: changes
3248
run: |
3349
git config --global user.name "github-actions[bot]"
3450
git config --global user.email "github-actions[bot]@users.noreply.github.com"
@@ -39,11 +55,8 @@ jobs:
3955
fi
4056
4157
- name: Commit and push changes
42-
if: env.changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository
43-
env:
44-
HEAD_REF: ${{ github.event.pull_request.head.ref }}
58+
if: env.changes == 'true'
4559
run: |
46-
git checkout -b "$HEAD_REF"
4760
git add .
4861
git commit -m "chore: auto-corrected with RuboCop"
49-
git push origin "$HEAD_REF"
62+
git push

0 commit comments

Comments
 (0)