Skip to content

Commit 7d7fb2c

Browse files
committed
ci(workflow): 添加 Brakeman 安全扫描并优化测试流程
- 在 CI 工作流中添加 Brakeman 安全扫描任务 - 更新测试任务依赖关系,使其在 lint 和安全扫描之后运行 - 优化测试任务输出信息,说明使用 Minitest 并行化的原因和边界条件
1 parent de7749c commit 7d7fb2c

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@ jobs:
2121
bundle exec rubocop --format progress --format clang
2222
echo "::endgroup::"
2323
24+
security-scan:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4.1.0
28+
29+
- name: Set up Ruby
30+
uses: ruby/setup-ruby@v1
31+
with:
32+
ruby-version: 3.4
33+
bundler-cache: true
34+
35+
- name: Run Brakeman Security Scan
36+
run: |
37+
echo "::group::Brakeman Security Scan"
38+
bundle exec brakeman --exit-on-warn --no-progress -f plain
39+
echo "::endgroup::"
40+
2441
test:
2542
runs-on: ubuntu-latest
26-
needs: lint
43+
needs: [lint, security-scan]
2744
steps:
2845
- uses: actions/checkout@v4.1.0
2946

@@ -45,9 +62,17 @@ jobs:
4562
bundle exec rails ci:health RAILS_ENV=test
4663
echo "::endgroup::"
4764
48-
- name: Run tests
65+
- name: Run tests with Minitest parallelize
4966
run: |
50-
echo "::group::Running Tests"
67+
echo "::group::Running Tests (with Minitest parallelize)"
68+
echo "Parallelization: Using Minitest parallelize with :number_of_processors workers"
69+
echo "Reason: Project has ~18 test files (controllers + models). Minitest parallelize is"
70+
echo " sufficient and simpler than multi-job matrix for this scale."
71+
echo "Boundaries:"
72+
echo " - All tests share the same GitHub Actions runner"
73+
echo " - Limited by single runner's CPU cores (typically 2-4 on GitHub-hosted runners)"
74+
echo " - Tests must be thread-safe (use transactions or proper database isolation)"
75+
echo ""
5176
bundle exec rails test RAILS_ENV=test --verbose
5277
echo "::endgroup::"
5378

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ gem 'lockbox', '=1.3.3'
3737

3838
group :development, :test do
3939
gem 'byebug'
40+
gem 'brakeman', require: false
4041
gem 'rubocop', require: false
4142
gem 'rubocop-rails', require: false
4243
gem 'rubocop-performance', require: false

0 commit comments

Comments
 (0)