From 8e64ffa263a91ba2487260d0cca81a6da0c82cad Mon Sep 17 00:00:00 2001 From: Ethan Mills Date: Wed, 29 Sep 2021 14:19:38 +0100 Subject: [PATCH 1/2] Revert ruby 3 upgrade --- .github/workflows/brakeman-analysis.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/smoke_test.yml | 2 +- .github/workflows/test.yml | 4 ++-- .ruby-version | 2 +- Dockerfile | 4 ++-- Dockerfile.dev | 2 +- README.md | 2 +- app/forms/participants/participant_validation_form.rb | 2 +- app/services/invite_schools.rb | 5 ++--- app/services/record_declarations/base.rb | 2 +- app/validators/notify_email_validator.rb | 6 +++--- lib/tasks/school_urn_generator.rb | 2 +- lib/tasks/trn_generator.rb | 2 +- lib/tasks/valid_test_data_generator.rb | 2 +- 15 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/brakeman-analysis.yml b/.github/workflows/brakeman-analysis.yml index 884db11bee..4f37dcf12f 100644 --- a/.github/workflows/brakeman-analysis.yml +++ b/.github/workflows/brakeman-analysis.yml @@ -25,7 +25,7 @@ jobs: - name: Setup Ruby uses: actions/setup-ruby@v1 with: - ruby-version: '3.0.2' + ruby-version: '2.7.2' - name: Setup Brakeman env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1bee384a76..29280ac0d1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1.82.0 with: - ruby-version: 3.0.2 + ruby-version: 2.7.2 - name: Install dependencies run: bundle install - name: Create mail log file diff --git a/.github/workflows/smoke_test.yml b/.github/workflows/smoke_test.yml index 7b1254f593..3db5897945 100644 --- a/.github/workflows/smoke_test.yml +++ b/.github/workflows/smoke_test.yml @@ -54,7 +54,7 @@ jobs: uses: ruby/setup-ruby@v1.82.0 with: bundler-cache: true - ruby-version: '3.0.2' + ruby-version: '2.7.2' - name: Set up Node uses: actions/setup-node@v2.4.1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb4d798478..46c05d0fe1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: uses: ruby/setup-ruby@v1.82.0 with: bundler-cache: true - ruby-version: '3.0.2' + ruby-version: '2.7.2' - name: Set up Node uses: actions/setup-node@v2.4.1 @@ -154,7 +154,7 @@ jobs: uses: ruby/setup-ruby@v1.82.0 with: bundler-cache: true - ruby-version: '3.0.2' + ruby-version: '2.7.2' - name: Set up Node uses: actions/setup-node@v2.4.1 diff --git a/.ruby-version b/.ruby-version index b502146930..fbafd6b600 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.2 +2.7.2 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 39f9db3e65..867bdeeb63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # To use or update to a ruby version, change {BASE_RUBY_IMAGE} -ARG BASE_RUBY_IMAGE=ruby:3.0.2-alpine3.14 +ARG BASE_RUBY_IMAGE=ruby:2.7.2-alpine # BASE_RUBY_IMAGE_WITH_GEMS_AND_NODE_MODULES will default to early-careers-framework-gems-node-modules # building all layers above it if a value is not specidied during the build ARG BASE_RUBY_IMAGE_WITH_GEMS_AND_NODE_MODULES=early-careers-framework-gems-node-modules @@ -7,7 +7,7 @@ ARG BASE_RUBY_IMAGE_WITH_GEMS_AND_NODE_MODULES=early-careers-framework-gems-node # Stage 1: Download gems and node modules. FROM ${BASE_RUBY_IMAGE} AS builder -ARG BUILD_DEPS="git gcc libc-dev make nodejs yarn postgresql-dev build-base libxml2-dev libxslt-dev ttf-freefont" +ARG BUILD_DEPS="git gcc libc-dev make nodejs yarn postgresql-dev build-base libxml2-dev libxslt-dev ttf-ubuntu-font-family" WORKDIR /app diff --git a/Dockerfile.dev b/Dockerfile.dev index 096a7b0efe..d04892aaa2 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,5 +1,5 @@ # To use or update to a ruby version, change {BASE_RUBY_IMAGE} -ARG BASE_RUBY_IMAGE=ruby:3.0.2-alpine3.14 +ARG BASE_RUBY_IMAGE=ruby:2.7.2-alpine # BASE_RUBY_IMAGE_WITH_GEMS_AND_NODE_MODULES will default to early-careers-framework-gems-node-modules # building all layers above it if a value is not specidied during the build ARG BASE_RUBY_IMAGE_WITH_GEMS_AND_NODE_MODULES=early-careers-framework-gems-node-modules diff --git a/README.md b/README.md index ec2134a7e7..9fd243dbe1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ### Prerequisites -- Ruby 3.0.2 +- Ruby 2.7.2 - PostgreSQL (we deploy on 11.x) - NodeJS 14.16.0 - Yarn 1.12.x diff --git a/app/forms/participants/participant_validation_form.rb b/app/forms/participants/participant_validation_form.rb index c07414e877..01ed099989 100644 --- a/app/forms/participants/participant_validation_form.rb +++ b/app/forms/participants/participant_validation_form.rb @@ -6,7 +6,7 @@ class ParticipantValidationForm include ActiveModel::Model # lifted from https://github.com/dwp/nino-format-validation - NINO_REGEX = /(^(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)[A-Z&&[^DFIQUV]][A-Z&&[^DFIOQUV]][0-9]{6}[A-D]$)/ + NINO_REGEX = /(^(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)[A-Z&&[^DFIQUV]][A-Z&&[^DFIOQUV]][0-9]{6}[A-D]$)/.freeze attr_accessor :step, :do_you_want_to_add_mentor_information_choice, :do_you_know_your_trn_choice, diff --git a/app/services/invite_schools.rb b/app/services/invite_schools.rb index 4368669f9b..8854b5beab 100644 --- a/app/services/invite_schools.rb +++ b/app/services/invite_schools.rb @@ -29,9 +29,8 @@ def run(school_urns) end def reached_limit(school) - EMAIL_LIMITS.find do |args| - args => { max:, within: } - NominationEmail.where(school: school, sent_at: within.ago..Float::INFINITY).count >= max + EMAIL_LIMITS.find do |**kwargs| + NominationEmail.where(school: school, sent_at: kwargs[:within].ago..Float::INFINITY).count >= kwargs[:max] end end diff --git a/app/services/record_declarations/base.rb b/app/services/record_declarations/base.rb index 9037cb9348..083c4a9864 100644 --- a/app/services/record_declarations/base.rb +++ b/app/services/record_declarations/base.rb @@ -9,7 +9,7 @@ class Base implement_class_method :required_params, :valid_declaration_types implement_instance_method :user_profile - RFC3339_DATE_REGEX = /\A\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):(\d{2})([.,]\d+)?(Z|[+-](\d{2})(:?\d{2})?)?\z/i + RFC3339_DATE_REGEX = /\A\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):(\d{2})([.,]\d+)?(Z|[+-](\d{2})(:?\d{2})?)?\z/i.freeze attr_accessor :declaration_date, :declaration_type diff --git a/app/validators/notify_email_validator.rb b/app/validators/notify_email_validator.rb index 0b7fc5b14a..d3ffc774ae 100644 --- a/app/validators/notify_email_validator.rb +++ b/app/validators/notify_email_validator.rb @@ -2,9 +2,9 @@ # Notify email validation https://github.com/alphagov/notifications-utils/blob/acbe764fb7f12c7a8b0696156283fbcb5073fcd7/notifications_utils/recipients.py#L494 class NotifyEmailValidator < ActiveModel::EachValidator - HOSTNAME_PART_REGEX = /\A(xn|[a-z0-9]+)(-?-[a-z0-9]+)*\z/i - TLD_REGEX = /\A([a-z]{2,63}|xn--([a-z0-9]+-)*[a-z0-9]+)\z/i - EMAIL_REGEX = /\A[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~\\-]+@([^.@][^@\s]+)\z/ + HOSTNAME_PART_REGEX = /\A(xn|[a-z0-9]+)(-?-[a-z0-9]+)*\z/i.freeze + TLD_REGEX = /\A([a-z]{2,63}|xn--([a-z0-9]+-)*[a-z0-9]+)\z/i.freeze + EMAIL_REGEX = /\A[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~\\-]+@([^.@][^@\s]+)\z/.freeze def validate_each(record, attribute, value) record.errors.add(attribute, I18n.t("errors.email.invalid")) unless NotifyEmailValidator.valid?(value) diff --git a/lib/tasks/school_urn_generator.rb b/lib/tasks/school_urn_generator.rb index 57ad150e1b..025911d023 100644 --- a/lib/tasks/school_urn_generator.rb +++ b/lib/tasks/school_urn_generator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -ALL_URNS = (1..999_999) unless defined?(ALL_URNS) +ALL_URNS = (1..999_999).freeze unless defined?(ALL_URNS) class SchoolURNGenerator class << self diff --git a/lib/tasks/trn_generator.rb b/lib/tasks/trn_generator.rb index 9529d9cbac..53ebd54d2f 100644 --- a/lib/tasks/trn_generator.rb +++ b/lib/tasks/trn_generator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -ALL_TRNS = (1111..9_999_999) unless defined?(ALL_TRNS) +ALL_TRNS = (1111..9_999_999).freeze unless defined?(ALL_TRNS) class TRNGenerator class << self diff --git a/lib/tasks/valid_test_data_generator.rb b/lib/tasks/valid_test_data_generator.rb index 545069d3db..6fe6d4b612 100644 --- a/lib/tasks/valid_test_data_generator.rb +++ b/lib/tasks/valid_test_data_generator.rb @@ -111,7 +111,7 @@ def weighted_choice(selection:, odds:) class AmbitionSpecificPopulater < LeadProviderPopulater class << self - FIRST_AMBITION_SEED_DATA_TIME = ("2021-08-18 13:43".."2021-08-18 13:49") + FIRST_AMBITION_SEED_DATA_TIME = ("2021-08-18 13:43".."2021-08-18 13:49").freeze def call(name:, total_schools: 3, participants_per_school: 3000) generator = new(name: name) From a0c46912ce8b2caf50dd5c49eb1322cfa7cfb9bc Mon Sep 17 00:00:00 2001 From: Ethan Mills Date: Wed, 29 Sep 2021 14:56:44 +0100 Subject: [PATCH 2/2] Change brakeman to use new ruby action actions/ is deprecated and does not support ruby 2.7.2 --- .github/workflows/brakeman-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/brakeman-analysis.yml b/.github/workflows/brakeman-analysis.yml index 4f37dcf12f..5fd6e7fcd8 100644 --- a/.github/workflows/brakeman-analysis.yml +++ b/.github/workflows/brakeman-analysis.yml @@ -23,7 +23,7 @@ jobs: # Customize the ruby version depending on your needs - name: Setup Ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1.82.0 with: ruby-version: '2.7.2'