From 9586c400be28ab4644cf48ad31d00c962fb4de14 Mon Sep 17 00:00:00 2001 From: Aidan Cornelius-Bell Date: Wed, 1 Jan 2025 07:10:27 +1030 Subject: [PATCH] Fixed some test stuff; fiddling with github CI --- .github/workflows/ci.yml | 46 ++++++++------------------------- .rubocop.yml | 23 +++++++++++++++++ config/credentials/test.yml.enc | 1 + config/environments/test.rb | 8 ++++-- 4 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 config/credentials/test.yml.enc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd2ce72..da7f229 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,76 +1,47 @@ name: CI - on: - pull_request: push: - branches: [ main ] - + branches: [main] + pull_request: + 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: bin/brakeman --no-pager - scan_js: - 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 security vulnerabilities in JavaScript dependencies - run: bin/importmap audit - 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: bin/rubocop -f github test: runs-on: ubuntu-latest - services: mysql: - image: mysql + image: mysql:8.0 env: MYSQL_ALLOW_EMPTY_PASSWORD: true ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - # redis: - # image: redis - # ports: - # - 6379:6379 - # options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 - steps: - name: Install packages run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl default-mysql-client libjemalloc2 libvips @@ -84,12 +55,17 @@ jobs: ruby-version: .ruby-version bundler-cache: true - - name: Run tests + - name: Setup test database and run tests env: RAILS_ENV: test DATABASE_URL: mysql2://127.0.0.1:3306 # REDIS_URL: redis://localhost:6379/0 - run: bin/rails db:test:prepare test test:system + ENCRYPTION_PRIMARY_KEY: ${{ secrets.ENCRYPTION_PRIMARY_KEY || 'test_primary_key_1234567890' }} + ENCRYPTION_DETERMINISTIC_KEY: ${{ secrets.ENCRYPTION_DETERMINISTIC_KEY || 'test_deterministic_key_1234567890' }} + ENCRYPTION_KEY_DERIVATION_SALT: ${{ secrets.ENCRYPTION_KEY_DERIVATION_SALT || 'test_derivation_salt_1234567890' }} + run: | + bin/rails db:test:prepare + bin/rails test test:system - name: Keep screenshots from failed system tests uses: actions/upload-artifact@v4 diff --git a/.rubocop.yml b/.rubocop.yml index f9d86d4..f25c8c2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,3 +6,26 @@ inherit_gem: { rubocop-rails-omakase: rubocop.yml } # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` # Layout/SpaceInsideArrayLiteralBrackets: # Enabled: false + +AllCops: + NewCops: enable + TargetRubyVersion: 3.2 + +# Disable checks for trailing empty lines +Layout/TrailingEmptyLines: + Enabled: false + +# Disable checks for comment spacing +Layout/LeadingCommentSpace: + Enabled: false + +# Allow both tabs and spaces +Layout/IndentationStyle: + Enabled: false + +# You might want to disable more rules that you don't care about +Style/Documentation: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc new file mode 100644 index 0000000..b64fd13 --- /dev/null +++ b/config/credentials/test.yml.enc @@ -0,0 +1 @@ +Nf8qnLmxZNpwpE2SpsKIvVPcc5Xgefgejov6iuF5+2AGUxNPu8ZirAaQddphdxoxC2PEkETv1tcFWANDMX5o6Pc3YjEDU8rSbRkuCVuuYS6AkYgDN9Iw12ix6g5t6+e/dkuQHiqdkHGN/vvofCZ0sRPbHujDb3ImaWx4Bs72og2kVFJkIfMZK5PEB2ihmwwVfzAiEFV8+hh1ZVLzxMSFMDvm/oKV8H6vE5EC70ZW9IzHPjHo9PPw3iDHvPKLviN3m5IB9y4MaCgUo7eATxa9W09ZHoRuh8cMCgRXyO3uf6zvErImEpAda0tPTaM9PJoXmTM/rmGYBWjt/cH4baNWBNBoNFmXrJTqEir+uwUMFrEPhoQLFD6qjbVAOdMfQNFOExnJ1Cbqad3JJLhcwXmj6czwhcxah8jPZdlDei2ywXaQjCTM/dAUC1twBEQWniOygQKdbHN17OZmrps9v09xPY1cjHYwdcy/7pe1H9AXxW14Ob9StIiRnEh5eqQyQ+8tg2ZioY+jPPzufFnbhEZ6IrArVgpFDYTU1kNINRNJXAztNuU=--+lV4znQQFC0LuJsa--6BoUpOAGHCy5MQC98vXCFA== \ No newline at end of file diff --git a/config/environments/test.rb b/config/environments/test.rb index 59c6723..8545c39 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,6 +8,10 @@ require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + config.active_record.encryption.primary_key = ENV.fetch('ENCRYPTION_PRIMARY_KEY') { 'test' * 8 } + config.active_record.encryption.deterministic_key = ENV.fetch('ENCRYPTION_DETERMINISTIC_KEY') { 'test' * 8 } + config.active_record.encryption.key_derivation_salt = ENV.fetch('ENCRYPTION_KEY_DERIVATION_SALT') { 'test' * 8 } + # While tests run files are not watched, reloading is not necessary. config.enable_reloading = false @@ -55,10 +59,10 @@ Rails.application.configure do # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] - + # Turn off captcha stuff for localhost config.hcaptcha_enabled = false - + # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true -- 2.39.5