From 7611c966cba0ffbd3de4a9717a86f85a862fb1d7 Mon Sep 17 00:00:00 2001 From: FlandreDaisuki Date: Tue, 22 Oct 2024 08:20:49 +0800 Subject: [PATCH] ci: add ci workflow --- .github/workflows/ci.yaml | 55 +++++++++++++++++++++++++++++++++++++++ Gemfile | 8 +++++- Gemfile.lock | 20 ++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1be0d28 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,55 @@ +name: CI + +on: + pull_request: + push: + branches: [ main ] + +jobs: + scan_ruby: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Scan for common Rails security vulnerabilities using static analysis + run: bundle exec brakeman --no-pager + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Lint code for consistent style + run: bundle exec rubocop -f github || true # 等修好再移除 || true + + rspec_test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Run rspec + env: + RAILS_ENV: test + run: bundle exec rspec diff --git a/Gemfile b/Gemfile index eee66e2..48bcd84 100644 --- a/Gemfile +++ b/Gemfile @@ -52,7 +52,13 @@ gem 'rack-cors' group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem 'debug', platforms: %i[mri windows] + gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" + + # Static analysis for security vulnerabilities [https://brakemanscanner.org/] + gem "brakeman", require: false + + # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] + gem "rubocop-rails-omakase", require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index b27dfdf..e721c89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,6 +84,8 @@ GEM bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) + brakeman (6.2.2) + racc builder (3.3.0) concurrent-ruby (1.3.3) connection_pool (2.4.1) @@ -262,6 +264,22 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.3) parser (>= 3.3.1.0) + rubocop-minitest (0.36.0) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-performance (1.22.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.26.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.52.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails-omakase (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails ruby-progressbar (1.13.0) sprockets (4.2.1) concurrent-ruby (~> 1.0) @@ -317,6 +335,7 @@ PLATFORMS DEPENDENCIES bcrypt (~> 3.1.7) bootsnap + brakeman debug htmlbeautifier (~> 1.4) importmap-rails @@ -331,6 +350,7 @@ DEPENDENCIES rspec-rails (~> 6.1) rswag (~> 2.13) rubocop (~> 1.64) + rubocop-rails-omakase sprockets-rails stimulus-rails tailwindcss-rails