diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bf834b7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run tests and linters. +name: "Mythographer CI" +on: + push: + branches: [ "*" ] + pull_request: + branches: [ "main" ] +jobs: + test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12.1-alpine + ports: + - "5432:5432" + # env: + # POSTGRES_DB: mythographer_test + # POSTGRES_USER: rails + # POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + DATABASE_URL: "postgres://postgres@localhost:5432/mythographer_test" + steps: + - name: Checkout code + uses: actions/checkout@v3 + # Add or replace dependency steps here + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + # Add or replace database setup steps here + - name: Set up database schema + run: bin/rails db:setup + # Add or replace test runners here + - name: Run tests + run: bin/rails test:all + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + # Add or replace any other lints here + - name: Security audit dependencies + run: bundle exec bundler-audit --update + - name: Security audit application code + run: bundle exec brakeman -q -w2 + - name: Lint Ruby files + run: bundle exec rubocop --parallel --format progress --format github --color diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..1920588 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,17 @@ +require: + - rubocop-rails + - rubocop-capybara + +AllCops: + NewCops: enable + Exclude: + - node_modules/**/* + - public/**/* + - vendor/**/* + +Rails: + Enabled: true # enable rubocop-rails cops +Rails/I18nLocaleTexts: + Enabled: false # disable this cop because not using locales for now +Bundler/DuplicatedGem: + Enabled: false # ignore duplicated gem errors because we will have duplicated gems when dual booting diff --git a/Gemfile b/Gemfile index 10a5cd2..c176ace 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,10 @@ gem "bootsnap", require: false 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 "rubocop-rails", require: false + gem "rubocop-capybara", require: false + gem "bundler-audit", require: false + gem "brakeman", require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 359ef9f..b6323e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,13 +77,18 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) baran (0.1.10) base64 (0.2.0) bigdecimal (3.1.4) bindex (0.8.1) bootsnap (1.17.0) msgpack (~> 1.2) + brakeman (6.0.1) builder (3.2.4) + bundler-audit (0.9.1) + bundler (>= 1.2.0, < 3) + thor (~> 1.0) capybara (3.39.2) addressable matrix @@ -127,6 +132,7 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.6.3) json-schema (4.0.0) addressable (>= 2.8) langchainrb (0.7.5) @@ -138,6 +144,7 @@ GEM tiktoken_ruby (~> 0.0.5) to_bool (~> 2.0.0) zeitwerk (~> 2.5) + language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -169,6 +176,10 @@ GEM racc (~> 1.4) nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) + parallel (1.23.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc pg (1.5.4) pragmatic_segmenter (0.3.23) unicode @@ -216,6 +227,7 @@ GEM rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) + rainbow (3.1.1) rake (13.1.0) rdoc (6.6.0) psych (>= 4.0.0) @@ -227,10 +239,31 @@ GEM reline (0.4.0) io-console (~> 0.5) rexml (3.2.6) + rubocop (1.57.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-rails (2.22.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-openai (6.1.0) event_stream_parser (>= 0.3.0, < 1.0.0) faraday (>= 1) faraday-multipart (>= 1) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) selenium-webdriver (4.15.0) @@ -266,6 +299,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode (0.4.4.4) + unicode-display_width (2.5.0) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -287,6 +321,8 @@ PLATFORMS DEPENDENCIES bootsnap + brakeman + bundler-audit capybara debug importmap-rails @@ -297,6 +333,8 @@ DEPENDENCIES rack-timeout rails (~> 7.1.2) redis (>= 4.0.1) + rubocop-capybara + rubocop-rails ruby-openai (~> 6.1.0) selenium-webdriver sprockets-rails