Skip to content

Brakeman2 #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 78 additions & 75 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,102 +1,105 @@
name: RSpec CI
permissions: write-all
on:
push:
branches:
- 'main'
- '*-maintenance'
- '*-dev'
- 'pr-*'
# push:
pull_request:
branches:
- '*'
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
rubocop:
name: Rubocop
runs-on: 'ubuntu-20.04'
setup:
name: "unit #${{ matrix.ci_node_index }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
- uses: ruby/setup-ruby@v1.170.0
with:
ruby-version: '3.0'
- run: script/update_rubygems_and_install_bundler
- run: bundle install --standalone
- run: bundle binstubs --all
- run: script/run_rubocop

test:
name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.env.RAILS_VERSION }}'
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: "unit #${{ matrix.ci_node_index }}"
strategy:
fail-fast: false
matrix:
include:
# Edge Rails (?) builds >= 2.7
- ruby: 3.2
env:
RAILS_VERSION: 'main'
- ruby: 3.1
env:
RAILS_VERSION: 'main'

# Rails 7.1 builds >= 2.7
- ruby: 3.2
env:
RAILS_VERSION: '~> 7.1.0'
- ruby: 3.1
env:
RAILS_VERSION: '~> 7.1.0'
- ruby: '3.0'
env:
RAILS_VERSION: '~> 7.1.0'
- ruby: 2.7
env:
RAILS_VERSION: '~> 7.1.0'

# Rails 7.0 builds >= 2.7
- ruby: 3.2
env:
RAILS_VERSION: '~> 7.0.0'
- ruby: 3.1
env:
RAILS_VERSION: '~> 7.0.0'
- ruby: '3.0'
env:
RAILS_VERSION: '~> 7.0.0'
- ruby: 2.7
env:
RAILS_VERSION: '~> 7.0.0'
ci_node_total: [2]
ci_node_index: [1, 2]

# Rails 6.1 builds >= 2.5
- ruby: 3.1
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: '3.0'
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.7
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.6
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.5
env:
RAILS_VERSION: '~> 6.1.0'

env: ${{ matrix.env }}
# env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
- uses: ruby/setup-ruby@v1.170.0
with:
ruby-version: ${{ matrix.ruby }}
- run: script/update_rubygems_and_install_bundler
- run: script/clone_all_rspec_repos
- run: bundle install --binstubs
- run: script/run_build
continue-on-error: ${{ matrix.allow_failure || false }}
- run: mkdir -p /tmp/test_results/
- name: RUN TESTS
timeout-minutes: 20
run: "./bin/ci --index=${{ matrix.ci_node_index }} --total=${{ matrix.ci_node_total }} --hash=${{ github.sha }}"
- run: ls -lh ./coverage/
- run: mv -v coverage/coverage.json /tmp/test_results/coverage-${{ matrix.ci_node_index }}.json
- run: mv -v coverage/.resultset.json /tmp/test_results/resultset-${{ matrix.ci_node_index }}.json
- name: UPLOAD TEST RESULT
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: "test-report-${{ matrix.ci_node_index }}"
path: |
/tmp/test_results/coverage-${{ matrix.ci_node_index }}.json
/tmp/test_results/resultset-${{ matrix.ci_node_index }}.json
/tmp/test_results/report-${{ matrix.ci_node_index }}.xml
compression-level: 0 # no compression
retention-days: 1
- run: ls -lh /tmp/test_results/
aggregate:
runs-on: ubuntu-latest
needs: test
if: success() || failure()
steps:
- name: DOWNLOAD TEST RESULTS
uses: actions/download-artifact@v4
with:
pattern: test-report-*
path: /tmp/aggregated_results/
merge-multiple: true
- name: Display downloaded files
run: ls -R /tmp/aggregated_results/
- uses: actions/checkout@v4
- uses: ruby/[email protected]
with:
ruby-version: '3.0'
- run: script/update_rubygems_and_install_bundler
- run: bundle install --standalone
- run: bundle binstubs --all
- name: COVERAGE REPORT
run: bundle exec rake coverage:report
- run: ls -lh ./coverage/
- run: ls -lh /tmp/aggregated_results/

- name: Simplecov Report
if: success() || failure() # Recommended to forcefully comment on the PR even if RSpec returns a non-zero status code.
uses: shettytejas/simplecov-reporter@v1
with:
# More options as given above.
result-path: coverage/coverage.json
# working-directory: .
token: ${{ secrets.GITHUB_TOKEN }}

- name: Brakeman Report
uses: artplan1/[email protected]
with:
flags: "--color"

- name: UPLOAD AGGREGATED RESULT
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: "Aggregated Test Results"
path: coverage/
compression-level: 0 # no compression
retention-days: 1
14 changes: 0 additions & 14 deletions .github/workflows/depsreview.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)

eval_gemfile 'Gemfile-rails-dependencies'

gem 'rspec_junit_formatter'
gem 'simplecov', require: false, group: :test
gem 'simplecov_json_formatter', github: 'shettytejas/simplecov_json_formatter', require: false
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,18 @@ task :verify_private_key_present do
end

task build: :verify_private_key_present

namespace :coverage do
desc "Collates all result sets generated by the different test runners"
task :report do
require 'simplecov'
require 'simplecov_json_formatter'

SimpleCov.collate Dir["/tmp/aggregated_results/resultset*"] do
formatter SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
])
end
end
end
38 changes: 38 additions & 0 deletions bin/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env ruby

require "optparse"

options = {}
op = OptionParser.new do |opts|
opts.banner = "Usage: ci [options]"
opts.on("--index=INDEX", Integer, "Current CI node index (1..total)")
opts.on("--total=TOTAL", Integer, "Total number of CI nodes")
opts.on("--hash=HASH", String, "SHA1 hash of the current commit")
opts.on("--seed=[SEED]", Integer, "RSpec seed (optional, will be generated if not provided)")
end

op.parse!(into: options)

unless %i(index total hash).all? { |key| options.key?(key) }
puts op.help
exit 1
end

options[:seed] ||= rand(0xFFFF)

random = Random.new(options[:hash].to_i(16))

tests = Dir["spec/**/*_spec.rb"].sort.shuffle(random: random).select.with_index do |_, i|
i % options[:total] == options[:index] - 1
end

STDERR.puts "To reproduce locally, run \"bin/ci --index=#{options[:index]} --total=#{options[:total]} --hash=#{options[:hash]} --seed=#{options[:seed]}\""
STDERR.puts "Running #{tests.size} tests on node #{options[:index]} of #{options[:total]}:"
tests.each { |test| STDERR.puts test }
STDERR.puts "\n\n"

# exec "bundle exec rspec --seed #{options[:seed]} #{tests.join(" ")}"
exec "bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test_results/report-#{options[:index]}.xml \
--seed #{options[:seed]} #{tests.join(' ')}"
5 changes: 5 additions & 0 deletions coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"result": {
"line": 95.34
}
}
Loading