Skip to content

Commit

Permalink
Merge pull request #284 from ncbo/251-ruby-v3-support
Browse files Browse the repository at this point in the history
Refactor: upgrade Ruby from 2.7 to 3.0.6
  • Loading branch information
jvendetti authored Sep 12, 2023
2 parents 95eba42 + 12f0c7a commit 70b6296
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 57 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/brakeman-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ jobs:
# Customize the ruby version depending on your needs
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'

- name: Setup Brakeman
env:
BRAKEMAN_VERSION: '5.4.0' # SARIF support is provided in Brakeman version 4.10+
BRAKEMAN_VERSION: '6.0.1' # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.7 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: get-deployment-config
uses: actions/checkout@v3
Expand All @@ -75,7 +74,7 @@ jobs:
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts
shell: bash
- uses: miloserdow/capistrano-deploy@master
- uses: miloserdow/capistrano-deploy@v3
with:
target: ${{ env.TARGET }} # which environment to deploy
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ config/deploy/*
/public/assets/
nohup.out

.ruby-version

# Ignore editor files
.idea
*.swp
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.6
5 changes: 2 additions & 3 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ require 'capistrano/deploy'
# https://github.com/capistrano/rails
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
#require 'capistrano/rails/assets'
#require 'capistrano/rails/migrations'
require 'capistrano/rails'
require 'capistrano/yarn'
require 'capistrano/locally'

require 'capistrano/yarn'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gem 'haml', '~> 5.1'
gem 'i18n'
gem 'iconv'
gem 'multi_json'
gem 'mysql2', '0.5.2'
gem 'mysql2', '0.5.5'
gem 'oj'
gem 'open_uri_redirections'
gem 'pry'
Expand All @@ -44,6 +44,7 @@ gem 'rails_autolink'
gem 'rdoc'
gem 'recaptcha', '~> 5.9.0'
gem 'rest-client'
gem 'rexml', '~> 3'
gem 'stackprof', require: false
gem 'thin'
gem 'will_paginate', '~> 3.0'
Expand All @@ -61,8 +62,9 @@ end
group :development do
# Capistrano Deployment
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0', require: false # https://github.com/miloserdow/capistrano-deploy/issues/42
gem 'capistrano', '~> 3.11', require: false
gem 'capistrano', '~> 3.17', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-rbenv', require: false
gem 'capistrano-locally', require: false
gem 'capistrano-passenger', require: false
gem 'capistrano-rails', '~> 1.4', require: false
Expand Down
42 changes: 26 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ GEM
zeitwerk (~> 2.3)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.1)
airbrussh (1.4.2)
sshkit (>= 1.6.1, != 1.7.0)
ast (2.4.2)
autoprefixer-rails (10.4.13.0)
execjs (~> 2)
base64 (0.1.1)
bcrypt_pbkdf (1.1.0)
bootstrap (4.1.3)
autoprefixer-rails (>= 6.0.3)
popper_js (>= 1.12.9, < 2)
sass (>= 3.5.2)
brakeman (5.4.1)
brakeman (6.0.1)
builder (3.2.4)
capistrano (3.17.3)
airbrussh (>= 1.0.0)
Expand All @@ -105,6 +106,9 @@ GEM
capistrano-rails (1.6.3)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rbenv (2.2.0)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano-yarn (2.0.2)
capistrano (~> 3.0)
capybara (3.39.2)
Expand Down Expand Up @@ -132,7 +136,7 @@ GEM
erubi (1.12.0)
erubis (2.7.0)
eventmachine (1.2.7)
excon (0.100.0)
excon (0.102.0)
execjs (2.8.1)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
Expand All @@ -147,7 +151,7 @@ GEM
flamegraph (0.9.5)
globalid (1.1.0)
activesupport (>= 5.0)
graphql (2.0.25)
graphql (2.0.26)
graphql-client (0.18.0)
activesupport (>= 3.0)
graphql
Expand Down Expand Up @@ -188,14 +192,14 @@ GEM
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.5.0)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
mime-types-data (3.2023.0808)
mini_mime (1.1.5)
minitest (5.19.0)
multi_json (1.15.0)
multipart-post (2.3.0)
mysql2 (0.5.2)
mysql2 (0.5.5)
net-imap (0.3.7)
date
net-protocol
Expand All @@ -209,13 +213,15 @@ GEM
net-protocol
net-ssh (7.2.0)
netrc (0.11.0)
newrelic_rpm (9.3.1)
newrelic_rpm (9.4.2)
nio4r (2.5.9)
nokogiri (1.15.3-x86_64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oj (3.15.1)
oj (3.16.0)
open_uri_redirections (0.2.1)
parallel (1.23.0)
parser (3.2.2.3)
Expand Down Expand Up @@ -297,7 +303,8 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.55.1)
rubocop (1.56.2)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -364,18 +371,20 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-22
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
bcrypt_pbkdf (>= 1.0, < 2.0)
bootstrap (~> 4.1.0)
brakeman
capistrano (~> 3.11)
capistrano (~> 3.17)
capistrano-bundler
capistrano-locally
capistrano-passenger
capistrano-rails (~> 1.4)
capistrano-rbenv
capistrano-yarn
capybara
chart-js-rails
Expand All @@ -392,7 +401,7 @@ DEPENDENCIES
jquery-ui-rails
listen
multi_json
mysql2 (= 0.5.2)
mysql2 (= 0.5.5)
newrelic_rpm
oj
ontologies_api_client!
Expand All @@ -405,6 +414,7 @@ DEPENDENCIES
rdoc
recaptcha (~> 5.9.0)
rest-client
rexml (~> 3)
rspec-rails
rubocop
sass-rails (~> 5.0)
Expand All @@ -415,4 +425,4 @@ DEPENDENCIES
will_paginate (~> 3.0)

BUNDLED WITH
2.3.22
2.4.18
19 changes: 8 additions & 11 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'uri'
require 'open-uri'
require 'net/http'
require 'net/https'
require 'net/ftp'
Expand Down Expand Up @@ -29,6 +28,8 @@ class ApplicationController < ActionController::Base
EXPIRY_RECENT_MAPPINGS = 60 * 60 # 1:00 hours
EXPIRY_ONTOLOGY_SIMPLIFIED = 60 * 1 # 0:01 minute

RETRY_LIMIT = 1

$trial_license_initialized = false

if !$EMAIL_EXCEPTIONS.nil? && $EMAIL_EXCEPTIONS == true
Expand Down Expand Up @@ -579,22 +580,18 @@ def get_apikey()
end

def parse_json(uri)
uri = URI.parse(uri)
begin
response = open(uri, "Authorization" => "apikey token=#{get_apikey}").read
rescue Exception => error
response = Net::HTTP.get(URI(uri), { 'Authorization' => "apikey token=#{get_apikey}" })
rescue StandardError => e
@retries ||= 0
if @retries < 1 # retry once only
@retries += 1
retry
else
raise error
end
raise e unless @retries < RETRY_LIMIT

@retries += 1
retry
end
JSON.parse(response)
end


def get_batch_results(params)
begin
response = RestClient.post REST_URI_BATCH, params.to_json, :content_type => :json, :accept => :json, :authorization => "apikey token=#{get_apikey}"
Expand Down
41 changes: 24 additions & 17 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
class SubmissionsController < ApplicationController
# frozen_string_literal: true

class SubmissionsController < ApplicationController
layout :determine_layout
before_action :authorize_and_redirect, :only=>[:edit,:update,:create,:new]
before_action :authorize_and_redirect, only: [:edit, :update, :create, :new]

def new
@ontology = LinkedData::Client::Models::Ontology.get(CGI.unescape(params[:ontology_id])) rescue nil
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first unless @ontology
begin
# REVIEW: do we really need this double attempt to locate an ontology? I think find_by_acronym (below) should
# be sufficient. It's not evident that we call the new method with a full URI anymore.
@ontology = LinkedData::Client::Models::Ontology.get(CGI.unescape(params[:ontology_id]))
rescue MultiJson::ParseError
nil
end

@ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first
@submission = @ontology.explore.latest_submission
@submission ||= LinkedData::Client::Models::OntologySubmission.new
end
Expand All @@ -16,21 +24,21 @@ def create

@submission = LinkedData::Client::Models::OntologySubmission.new(values: submission_params)
@ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology])

# Update summaryOnly on ontology object
@ontology.summaryOnly = @submission.isRemote.eql?("3")
@ontology.summaryOnly = @submission.isRemote.eql?('3')
@ontology.update
@submission_saved = @submission.save

@submission_saved = @submission.save(cache_refresh_all: false)
if response_error?(@submission_saved)
@errors = response_errors(@submission_saved) # see application_controller::response_errors
if @errors && @errors[:uploadFilePath]
@errors = ["Please specify the location of your ontology"]
@errors = ['Please specify the location of your ontology']
elsif @errors && @errors[:contact]
@errors = ["Please enter a contact"]
@errors = ['Please enter a contact']
end

render "new"
render 'new'
else
redirect_to "/ontologies/success/#{@ontology.acronym}"
end
Expand All @@ -39,7 +47,7 @@ def create
def edit
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first
submissions = @ontology.explore.submissions
@submission = submissions.select {|o| o.submissionId == params["id"].to_i}.first
@submission = submissions.select { |o| o.submissionId == params['id'].to_i }.first
end

def update
Expand All @@ -50,13 +58,13 @@ def update

@ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology])
submissions = @ontology.explore.submissions
@submission = submissions.select {|o| o.submissionId == params["id"].to_i}.first
@submission = submissions.select { |o| o.submissionId == params['id'].to_i }.first

@submission.update_from_params(submission_params)
# Update summaryOnly on ontology object
@ontology.summaryOnly = @submission.isRemote.eql?("3")
@ontology.summaryOnly = @submission.isRemote.eql?('3')
@ontology.update
error_response = @submission.update
error_response = @submission.update(cache_refresh_all: false)
if response_error?(error_response)
@errors = response_errors(error_response) # see application_controller::response_errors
render 'edit'
Expand All @@ -71,9 +79,8 @@ def submission_params
p = params.require(:submission).permit(:ontology, :description, :hasOntologyLanguage, :prefLabelProperty,
:synonymProperty, :definitionProperty, :authorProperty, :obsoleteProperty,
:obsoleteParent, :version, :status, :released, :isRemote, :pullLocation,
:filePath, { contact:[:name, :email] }, :homepage, :documentation,
:filePath, { contact: [:name, :email] }, :homepage, :documentation,
:publication)
p.to_h
end

end
6 changes: 5 additions & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# set :format, :pretty

# Default value for :log_level is :debug
set :log_level, :error
# set :log_level, :error

# Default value for :pty is false
# set :pty, true
Expand Down Expand Up @@ -55,6 +55,10 @@
# If you don't set `:passenger_restart_with_touch`, capistrano-passenger will check what version of passenger you are running
# and use `passenger-config restart-app` if it is available in that version.

# rbenv ruby version
set :rbenv_type, :system
set :rbenv_ruby, File.read('.ruby-version').strip

desc "Check if agent forwarding is working"
task :forwarding do
on roles(:all) do |h|
Expand Down

0 comments on commit 70b6296

Please sign in to comment.