add rails version to Gemfile.lock

refs DE-523

Previously, the current version would be represented by Gemfile.lock and the next version by Gemfile.lock.next. Replace both with a common format of Gemfile.rails<version>.lock to be able to iterate over the files in a cleaner way.

Change-Id: I35aef3a14e726eb35db8aebc808af4a925552c01
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/288563
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jacob Burroughs <jburroughs@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Product-Review: Aaron Ogata <aogata@instructure.com>
This commit is contained in:
Aaron Ogata 2022-03-30 15:23:24 -07:00
parent c72cacb87b
commit a5cb130154
5 changed files with 27 additions and 40 deletions

3
.gitignore vendored
View File

@ -29,8 +29,7 @@
/db/*sql /db/*sql
docker-compose.override.yml docker-compose.override.yml
/exports/ /exports/
Gemfile.lock Gemfile.*.lock
Gemfile.lock.next
/log/* /log/*
!/log/.keep !/log/.keep
!/log/parallel-runtime-rspec.log !/log/parallel-runtime-rspec.log

View File

@ -12,18 +12,15 @@ RUN --mount=target=/tmp/src \
/tmp/dst && \ /tmp/dst && \
find gems \( \ find gems \( \
-name "Gemfile" -o \ -name "Gemfile" -o \
-name "Gemfile.d" -o \
-name "Gemfile.lock" -o \
-name "Gemfile.lock.next" -o \
-name "*.gemspec" -o \ -name "*.gemspec" -o \
-name "gem_version.rb" -o \ -name "gem_version.rb" -o \
-name "version.rb" \ -name "version.rb" \
\) -exec cp --parents -rf {} /tmp/dst \; && \ \) -exec cp --parents -rf {} /tmp/dst \; && \
find gems/plugins \( \
-name "Gemfile.d" \
\) -exec cp --parents -rf {} /tmp/dst \; && \
find engines \( \ find engines \( \
-name "Gemfile" -o \ -name "Gemfile" -o \
-name "Gemfile.d" -o \
-name "Gemfile.lock" -o \
-name "Gemfile.lock.next" -o \
-name "*.gemspec" -o \ -name "*.gemspec" -o \
-name "gem_version.rb" -o \ -name "gem_version.rb" -o \
-name "version.rb" \ -name "version.rb" \

View File

@ -32,22 +32,19 @@ elsif RUBY_VERSION >= "3.0.0" && RUBY_VERSION < "3.1"
end end
ruby ">= 2.7.0", "< 3.1" ruby ">= 2.7.0", "< 3.1"
# force a different lockfile for next rails # Add the version number to the Gemfile.lock as Gemfile.<version>.lock
if CANVAS_RAILS >= "6.1" Bundler::SharedHelpers.class_eval do
Bundler::SharedHelpers.class_eval do class << self
class << self def default_lockfile
def default_lockfile lockfile = "#{Bundler.default_gemfile}.rails#{CANVAS_RAILS.delete(".")}.lock"
lockfile = +"#{Bundler.default_gemfile}.lock" Pathname.new(lockfile)
lockfile << ".next"
Pathname.new(lockfile)
end
end
end
Bundler::Dsl.class_eval do
def to_definition(_lockfile, unlock)
@sources << @rubygems_source if @sources.respond_to?(:include?) && !@sources.include?(@rubygems_source)
Definition.new(Bundler.default_lockfile, @dependencies, @sources, unlock, @ruby_version)
end end
end end
end end
Bundler::Dsl.class_eval do
def to_definition(_lockfile, unlock)
@sources << @rubygems_source if @sources.respond_to?(:include?) && !@sources.include?(@rubygems_source)
Definition.new(Bundler.default_lockfile, @dependencies, @sources, unlock, @ruby_version)
end
end

View File

@ -8,10 +8,8 @@ unless defined?(Spring)
require 'rubygems' require 'rubygems'
require 'bundler' require 'bundler'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) rails_version = ENV["CANVAS_RAILS"] || "6.0"
default_lockfile = Bundler.default_lockfile lockfile_name = Bundler.default_lockfile.dirname + "Gemfile.rails#{rails_version.delete(".")}.lock"
next_lockfile = default_lockfile.dirname + "Gemfile.lock.next"
lockfile_name = [next_lockfile, default_lockfile].find(&:exist?)
lockfile = Bundler::LockfileParser.new(lockfile_name.read) lockfile = Bundler::LockfileParser.new(lockfile_name.read)
spring = lockfile.specs.detect { |spec| spec.name == 'spring' } spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
if spring if spring

View File

@ -2,19 +2,15 @@
set -ex set -ex
TEST_FILE="" for TEST_FILE in Gemfile.*.lock; do
echo "checking $TEST_FILE with snyk"
if test -f "Gemfile.lock"; then npx snyk auth $SNYK_TOKEN
TEST_FILE="Gemfile.lock" npx snyk test --severity-threshold=low --file=$TEST_FILE --org=instructure --project-name=canvas-lms:ruby --packageManager=rubygems || true
elif test -f "Gemfile.lock.next"; then npx snyk monitor --severity-threshold=low --file=$TEST_FILE --org=instructure --project-name=canvas-lms:ruby --packageManager=rubygems
TEST_FILE="Gemfile.lock.next" done
else
if [[ -z "$TEST_FILE" ]]; then
echo "could not find any supported file to check" echo "could not find any supported file to check"
exit 1 exit 1
fi fi
echo "checking $TEST_FILE with snyk"
npx snyk auth $SNYK_TOKEN
npx snyk test --severity-threshold=low --file=$TEST_FILE --org=instructure --project-name=canvas-lms:ruby --packageManager=rubygems || true
npx snyk monitor --severity-threshold=low --file=$TEST_FILE --org=instructure --project-name=canvas-lms:ruby --packageManager=rubygems