From e0392f248326f8cfdfc606370a864130f7d6d5f1 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:05:43 -0700 Subject: [PATCH 01/18] added rubocop --- Gemfile | 29 ++++++++++++++--------------- Gemfile.lock | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 039ba60..a4b240a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,32 +1,31 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' +gem 'roda', '~> 3.72' -gem "roda", "~> 3.72" +gem 'sequel', '~> 5.72' -gem "sequel", "~> 5.72" +gem 'tilt', '~> 2.2' -gem "tilt", "~> 2.2" +gem 'sqlite3', '~> 1.6' -gem "sqlite3", "~> 1.6" - -gem "erubi", "~> 1.12" +gem 'erubi', '~> 1.12' group :test do + gem 'cucumber', '~> 9.0' - gem "cucumber", "~> 9.0" + gem 'capybara', '~> 3.39' - gem "capybara", "~> 3.39" + gem 'rspec', '~> 3.12' - gem "rspec", "~> 3.12" + gem 'selenium-webdriver', '~> 4.13' - gem "selenium-webdriver", "~> 4.13" - - gem "simplecov" + gem 'simplecov' + gem 'rubocop', require: false end -gem "puma", "~> 6.4" +gem 'puma', '~> 6.4' -gem "rackup", "~> 2.1" +gem 'rackup', '~> 2.1' diff --git a/Gemfile.lock b/Gemfile.lock index 5caf8ec..38e9efe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,8 @@ GEM specs: addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) + base64 (0.1.1) bigdecimal (3.1.4) builder (3.2.4) capybara (3.39.2) @@ -42,6 +44,8 @@ GEM docile (1.4.0) erubi (1.12.0) ffi (1.16.2) + json (2.6.3) + language_server-protocol (3.17.0.3) matrix (0.4.2) mini_mime (1.1.5) mini_portile2 (2.8.4) @@ -50,6 +54,10 @@ GEM nokogiri (1.15.4) mini_portile2 (~> 2.8.2) racc (~> 1.4) + parallel (1.23.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc public_suffix (5.0.3) puma (6.4.0) nio4r (~> 2.0) @@ -60,6 +68,7 @@ GEM rackup (2.1.0) rack (>= 3) webrick (~> 1.8) + rainbow (3.1.1) regexp_parser (2.8.1) rexml (3.2.6) roda (3.72.0) @@ -77,6 +86,21 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) + rubocop (1.57.1) + base64 (~> 0.1.1) + 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.29.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) rubyzip (2.3.2) selenium-webdriver (4.13.1) rexml (~> 3.2, >= 3.2.5) @@ -95,6 +119,7 @@ GEM sys-uname (1.2.3) ffi (~> 1.1) tilt (2.3.0) + unicode-display_width (2.5.0) webrick (1.8.1) websocket (1.2.10) xpath (3.2.0) @@ -111,6 +136,7 @@ DEPENDENCIES rackup (~> 2.1) roda (~> 3.72) rspec (~> 3.12) + rubocop selenium-webdriver (~> 4.13) sequel (~> 5.72) simplecov From 48ffdf560bc299649911c87a6abbc65f1fe6d200 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:06:12 -0700 Subject: [PATCH 02/18] frozen string literal for rubocop --- db/migrations/001_create_links_table.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrations/001_create_links_table.rb b/db/migrations/001_create_links_table.rb index 69fa678..67e16fc 100644 --- a/db/migrations/001_create_links_table.rb +++ b/db/migrations/001_create_links_table.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Sequel.migration do change do create_table :links do From 5abf07d0c7cecc0befecce7f5e09b49ce6382872 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:07:07 -0700 Subject: [PATCH 03/18] rubocop formatting fixes --- spec/create_spec.rb | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/spec/create_spec.rb b/spec/create_spec.rb index 4ef0610..140af0b 100644 --- a/spec/create_spec.rb +++ b/spec/create_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'simplecov' SimpleCov.start require_relative '../.env' -ENV["DB_NAME"] = "test_#{ENV["DB_NAME"]}" +ENV['DB_NAME'] = "test_#{ENV.fetch('DB_NAME', nil)}" require_relative '../app' require 'rubygems' require 'roda' @@ -12,48 +14,47 @@ require 'rack/test' # DB initialization Sequel.extension :migration -Sequel.sqlite("db/#{ENV['DB_NAME']}") do |db| - Sequel::Migrator.apply(db, "db/migrations") +Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}") do |db| + Sequel::Migrator.apply(db, 'db/migrations') end def app App end -describe "Submit API request to create new link" do +describe 'Submit API request to create new link' do include Rack::Test::Methods before :each do - @links = Sequel.sqlite("db/#{ENV['DB_NAME']}")[:links] + @links = Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}")[:links] end after :each do @links.delete end - it "should return link data in json format when a valid url is submitted" do + it 'should return link data in json format when a valid url is submitted' do data = { url: 'http://google.com' } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response).to be_ok response_json = JSON.parse(last_response.body) expect(response_json['url']).to eq(data[:url]) expect(response_json['code']).not_to eq(nil) expect(response_json['link']).to include(response_json['code']) end - + it "should return with a 400 status and 'invalid url parameter' message when an empty url is submitted" do data = { url: '' } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response.status).to eq(400) response_json = JSON.parse(last_response.body) expect(response_json['message']).to eq('invalid url parameter') end it "should return with a 400 status and 'missing url parameter' message when an empty url is submitted" do - data = { - } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + data = {} + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response.status).to eq(400) response_json = JSON.parse(last_response.body) expect(response_json['message']).to eq('missing url parameter') @@ -63,7 +64,7 @@ describe "Submit API request to create new link" do data = { url: 'not-an-url' } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response.status).to eq(400) response_json = JSON.parse(last_response.body) expect(response_json['message']).to eq('invalid url parameter') @@ -73,7 +74,7 @@ describe "Submit API request to create new link" do data = { url: 'http://google.com/example' } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response.status).to eq(400) response_json = JSON.parse(last_response.body) expect(response_json['message']).to eq('url not found') @@ -83,13 +84,14 @@ describe "Submit API request to create new link" do data = { url: 'http://bad.tld' } - post('/links', data.to_json, "CONTENT_TYPE" => "application/json") + post('/links', data.to_json, 'CONTENT_TYPE' => 'application/json') expect(last_response.status).to eq(400) response_json = JSON.parse(last_response.body) expect(response_json['message']).to eq('url does not resolve') end - it "should return with a 400 status and 'not a valid json request' message when a request is made with the wrong content type header" do + it "should return with a 400 status and 'not a valid json request' + message when a request is made with the wrong content type header" do data = { url: 'http://google.com' } From 18e8eac2abd58e818bba110677fc5106a7021f3e Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:12:48 -0700 Subject: [PATCH 04/18] rubocop autofixed formatting --- features/step_definitions/steps.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index 04262a8..0bd3ae6 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true + # BEFORE Before('@db-test') do - @links = Sequel.sqlite("db/#{ENV['DB_NAME']}")[:links] + @links = Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}")[:links] end - # GIVEN Given('I visit the {string} page') do |string| @@ -11,18 +12,17 @@ Given('I visit the {string} page') do |string| end Given('A link already exists with the url {string}') do |string| - @links.insert(url: string, code: "aaaaaa") + @links.insert(url: string, code: 'aaaaaa') end Given('A link already exists with the url {string} and code {string}') do |url, code| - @links.insert(url: url, code: code) + @links.insert(url:, code:) end - # WHEN When('I click the {string} button') do |string| - click_button {string} + click_button { string } end When('I type {string} in the {string} field') do |text, field| @@ -33,7 +33,6 @@ When('I visit the {string} location') do |string| visit string end - # THEN Then('I should see text {string}') do |string| @@ -66,7 +65,6 @@ Then('The status code should be {int}') do |code| page.status_code.should eq(code) end - # AFTER After('@db-test') do From 4f5412451944f6c76e63096ee611a648c6f25165 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:13:27 -0700 Subject: [PATCH 05/18] rubocop autofixed formatting --- app.rb | 69 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/app.rb b/app.rb index b9ef9e5..9bc3c61 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + require 'roda' require 'securerandom' require 'json' require 'sequel' require 'open-uri' +# URL Shortener App class class App < Roda plugin :sessions, secret: ENV.delete('APP_SESSION_SECRET') plugin :render, escape: true @@ -11,92 +14,92 @@ class App < Roda plugin :json_parser plugin :request_headers - DB = Sequel.sqlite("db/#{ENV['DB_NAME']}") + DB = Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}") links = DB[:links] route do |r| r.root do - @message = flash['message'] || "Enter a URL" + @message = flash['message'] || 'Enter a URL' view :home end - r.get String do | url_code | - link = links.filter(:code => url_code) + r.get String do |url_code| + link = links.filter(code: url_code) r.redirect link.first[:url] unless link.first.nil? @message = "Link #{url_code} doesn't exist" response.status = 404 view :home end - r.post "create" do + r.post 'create' do url = r.params['url'] - if url.nil? or url.empty? - flash['message'] = "Please enter a valid URL"; + if url.nil? || url.empty? + flash['message'] = 'Please enter a valid URL' r.redirect '/' end begin OpenURI.open_uri(url) rescue URI::BadURIError - flash['message'] = "Invalid URL" + flash['message'] = 'Invalid URL' r.redirect '/' rescue OpenURI::HTTPError - flash['message'] = "URL not found" + flash['message'] = 'URL not found' r.redirect '/' - rescue SocketError => e - flash['message'] = "URL does not resolve" + rescue SocketError + flash['message'] = 'URL does not resolve' r.redirect '/' end - if links.filter(:url => url).first.nil? + if links.filter(url:).first.nil? code = SecureRandom.urlsafe_base64 4 - links.insert(url: url, code: code) - @message = "Link created" + links.insert(url:, code:) + @message = 'Link created' end - code = links.filter(:url => url).first[:code] - @message ||= "Link exists" - @new_link = 'http://' + request.env['HTTP_HOST'] + '/' + code - view :create + code = links.filter(url:).first[:code] + @message ||= 'Link exists' + @new_link = "http://#{request.env['HTTP_HOST']}/#{code}" + view :create end - r.on "links" do + r.on 'links' do r.post do - if 'application/json' != r.headers['CONTENT_TYPE'] + if r.headers['CONTENT_TYPE'] != 'application/json' response.status = 400 - return {message: "not a valid json request"}.to_json + return { message: 'not a valid json request' }.to_json end url = r.params['url'] if url.nil? response.status = 400 - return {message: "missing url parameter"}.to_json + return { message: 'missing url parameter' }.to_json end - if url.empty? + if url.empty? response.status = 400 - return {message: "invalid url parameter"}.to_json + return { message: 'invalid url parameter' }.to_json end begin OpenURI.open_uri(url) rescue URI::BadURIError response.status = 400 - return {message: "invalid url parameter"}.to_json + return { message: 'invalid url parameter' }.to_json rescue OpenURI::HTTPError response.status = 400 - return {message: "url not found"}.to_json - rescue SocketError => e + return { message: 'url not found' }.to_json + rescue SocketError response.status = 400 - return {message: "url does not resolve"}.to_json + return { message: 'url does not resolve' }.to_json end - if links.filter(:url => url).first.nil? + if links.filter(url:).first.nil? code = SecureRandom.urlsafe_base64 4 - links.insert(url: url, code: code) + links.insert(url:, code:) end - code = links.filter(:url => url).first[:code] - @new_link = 'http://' + request.env['HTTP_HOST'] + '/' + code - return {url: url, code: code, link: @new_link}.to_json + code = links.filter(url:).first[:code] + @new_link = "http://#{request.env['HTTP_HOST']}/#{code}" + return { url:, code:, link: @new_link }.to_json end end end From c505012b003594ea2b81551aeac9c3e763716ff4 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:14:02 -0700 Subject: [PATCH 06/18] rubocop added frozen string literal comment --- config.ru | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.ru b/config.ru index 02b347a..34bbe47 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require './.env' require './app' From 7d35133e437eaae37640f81c09a6d68d76ac8e2c Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:14:23 -0700 Subject: [PATCH 07/18] require capybara and rspec parts needed for tests to run instead of including them. rubocop autofixed formatting --- features/support/env.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 42c1dc5..6f88264 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + require 'simplecov' SimpleCov.start require_relative '../../.env' -ENV["DB_NAME"] = "test_#{ENV["DB_NAME"]}" +ENV['DB_NAME'] = "test_#{ENV.fetch('DB_NAME', nil)}" require_relative '../../app' require 'rubygems' require 'roda' require 'sequel' require 'capybara' require 'capybara/dsl' +require 'capybara/cucumber' require 'rspec' +### +require 'rspec/expectations' +require 'rspec/matchers' # DB initialization Sequel.extension :migration -Sequel.sqlite("db/#{ENV['DB_NAME']}") do |db| - Sequel::Migrator.apply(db, "db/migrations") +Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}") do |db| + Sequel::Migrator.apply(db, 'db/migrations') end # attach app to Capybara Capybara.app = App - -include Capybara::DSL -include RSpec::Expectations -include RSpec::Matchers From bf6ed14b5e433a04bf5eac9dbbec75ba1b678de6 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:15:09 -0700 Subject: [PATCH 08/18] custom parts for rubocop to run. don't worry about block length in many parts. hide extension suggestions --- .rubocop.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..2d4fe7c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +AllCops: + NewCops: enable + SuggestExtensions: false + +Metrics/BlockLength: + AllowedMethods: ['describe', 'context', 'route', 'r.on', 'r.post'] From 282a07c5fb6ae73b7ebe43c4de40b90c9a821110 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:16:20 -0700 Subject: [PATCH 09/18] added rubocop linting section with output for reports and clean up rubocop config --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b0c9ab3..63c4baa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,6 +20,9 @@ pipeline { sh 'sequel -m db/migrations sqlite://db/${DB_NAME}' } } + stage('Code Linting') { + sh 'bundle exec rubocop --format html --out rubocop.html' + } stage('Run tests') { steps { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { @@ -37,9 +40,9 @@ pipeline { alwaysLinkToLastBuild: false, keepAll: true, reportDir: '.', - reportFiles: 'cucumber.html, spec.html, coverage/index.html', + reportFiles: 'rubocop.html, cucumber.html, spec.html, coverage/index.html', reportName: 'Test Results', - reportTitles: 'Cucumber Results, RSpec Results, Test Coverage']) + reportTitles: 'Rubocop Results, Cucumber Results, RSpec Results, Test Coverage']) } } stage('Build production deliverable') { @@ -53,7 +56,7 @@ pipeline { cp .env.rb /tmp/url-shortener/ cp .ruby-version /tmp/url-shortener/ cd /tmp/url-shortener - rm -rf features spec coverage db/*.db .git* Jenkinsfile *.html + rm -rf features spec coverage db/*.db .git* Jenkinsfile *.html .rubocop.yml cd /tmp tar -czvf $ZIP_FILE url-shortener/ mv /tmp/$ZIP_FILE $CUR_DIR/ From f86da2ed6f26f63547e621beff8f0df523e1b475 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:19:30 -0700 Subject: [PATCH 10/18] forgot to wrap the steps in a steps block --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 63c4baa..ca63cd3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,9 @@ pipeline { } } stage('Code Linting') { - sh 'bundle exec rubocop --format html --out rubocop.html' + steps { + sh 'bundle exec rubocop --format html --out rubocop.html' + } } stage('Run tests') { steps { From 3fa1de5e4ed769bb25499241a4aa671af9e1100b Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:27:07 -0700 Subject: [PATCH 11/18] install bundled gems in /vendor, and use bundle exec to run them --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ca63cd3..ab08d27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,7 @@ pipeline { } stage('Build dependencies') { steps { + sh 'bundle config set --local path "vendor"' sh 'bundle install' sh 'sequel -m db/migrations sqlite://db/${DB_NAME}' } @@ -28,10 +29,10 @@ pipeline { stage('Run tests') { steps { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { - sh 'cucumber features --format html --out cucumber.html' + sh 'bundle exec cucumber features --format html --out cucumber.html' } catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { - sh 'rspec spec --format html --out spec.html' + sh 'bundle exec rspec spec --format html --out spec.html' } } } From 7caf25c4d03e87f1fc4cb9c065786e577aaf420c Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:32:39 -0700 Subject: [PATCH 12/18] don't kill it if linting breaks, mark it as unstable --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ab08d27..c550736 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,7 +23,9 @@ pipeline { } stage('Code Linting') { steps { - sh 'bundle exec rubocop --format html --out rubocop.html' + catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { + sh 'bundle exec rubocop --format html --out rubocop.html' + } } } stage('Run tests') { From 795447e02902b36ed3a41f414d7ba7c33c9ac5a9 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:43:12 -0700 Subject: [PATCH 13/18] attempting to clean up the .env.rb file --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c550736..51fe251 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,8 +9,9 @@ pipeline { steps { sh ''' #!/usr/local/bin/bash rbenv local 3.2.2 - echo "ENV[\\\"APP_SESSION_SECRET\\\"] ||= $(ruby -rsecurerandom -e 'puts SecureRandom.base64(64).inspect()')" > .env.rb - echo "ENV[\\\"DB_NAME\\\"] ||= \\\"${DB_NAME}\\\"" >> .env.rb + echo "# frozen_string_literal: true\n" > env.rb + echo "ENV[\\\'APP_SESSION_SECRET\\\'] ||= \\\'$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')\\\'" >> .env.rb + echo "ENV[\\\'DB_NAME\\\'] ||= \\\'${DB_NAME}\\\'" >> .env.rb ''' } } From c51a6782d96f7f2e33d5fb2ac2e47796a87f8142 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 13:50:58 -0700 Subject: [PATCH 14/18] another shot at cleaning up the .env.rb file --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 51fe251..456771e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { sh ''' #!/usr/local/bin/bash rbenv local 3.2.2 echo "# frozen_string_literal: true\n" > env.rb - echo "ENV[\\\'APP_SESSION_SECRET\\\'] ||= \\\'$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')\\\'" >> .env.rb + echo "ENV[\\'APP_SESSION_SECRET\\'] ||= \\'$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')\\'" >> .env.rb echo "ENV[\\\'DB_NAME\\\'] ||= \\\'${DB_NAME}\\\'" >> .env.rb ''' } From bf1fefd1bce1c488021c07d49c1420ab738ad3b5 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 14:05:51 -0700 Subject: [PATCH 15/18] still worknig on env file, and adding logic to not build if the tests fail --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 456771e..15a1c87 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { sh ''' #!/usr/local/bin/bash rbenv local 3.2.2 echo "# frozen_string_literal: true\n" > env.rb - echo "ENV[\\'APP_SESSION_SECRET\\'] ||= \\'$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')\\'" >> .env.rb + echo "ENV['APP_SESSION_SECRET'] ||= '$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')'" >> .env.rb echo "ENV[\\\'DB_NAME\\\'] ||= \\\'${DB_NAME}\\\'" >> .env.rb ''' } @@ -53,6 +53,9 @@ pipeline { } stage('Build production deliverable') { steps { + when { + expression { buildResult != 'FAILURE' } + } catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { sh ''' #!/usr/local/bin/bash ZIP_FILE="url-shortener_${BRANCH_NAME}_$(date "+%Y-%m-%d_%H-%M-%S").tgz" From f81199e31b8b3311aa7fc4cdb4fd1780e1fb0ea7 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 14:15:27 -0700 Subject: [PATCH 16/18] maybe this will clean up a few things --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 15a1c87..56d977a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { rbenv local 3.2.2 echo "# frozen_string_literal: true\n" > env.rb echo "ENV['APP_SESSION_SECRET'] ||= '$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')'" >> .env.rb - echo "ENV[\\\'DB_NAME\\\'] ||= \\\'${DB_NAME}\\\'" >> .env.rb + echo "ENV['DB_NAME'] ||= '${DB_NAME}'" >> .env.rb ''' } } From 950c358ae5465fc72d0559dec6b08c7a1f568509 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 14:55:06 -0700 Subject: [PATCH 17/18] another try --- Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 56d977a..62e0e4f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,9 +9,10 @@ pipeline { steps { sh ''' #!/usr/local/bin/bash rbenv local 3.2.2 - echo "# frozen_string_literal: true\n" > env.rb - echo "ENV['APP_SESSION_SECRET'] ||= '$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')'" >> .env.rb + echo "# frozen_string_literal: true\n" > .env.rb + echo "ENV['APP_SESSION_SECRET'] ||= $(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')" >> .env.rb echo "ENV['DB_NAME'] ||= '${DB_NAME}'" >> .env.rb + cat .env.rb ''' } } @@ -53,9 +54,6 @@ pipeline { } stage('Build production deliverable') { steps { - when { - expression { buildResult != 'FAILURE' } - } catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { sh ''' #!/usr/local/bin/bash ZIP_FILE="url-shortener_${BRANCH_NAME}_$(date "+%Y-%m-%d_%H-%M-%S").tgz" From 3fd8e8c6308ffd3328295b89c7d4946cc7f33400 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 22 Oct 2023 15:00:59 -0700 Subject: [PATCH 18/18] wrap the string in single quotes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 62e0e4f..53889bd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { sh ''' #!/usr/local/bin/bash rbenv local 3.2.2 echo "# frozen_string_literal: true\n" > .env.rb - echo "ENV['APP_SESSION_SECRET'] ||= $(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')" >> .env.rb + echo "ENV['APP_SESSION_SECRET'] ||= '$(ruby -rsecurerandom -e 'puts SecureRandom.base64(64)')'" >> .env.rb echo "ENV['DB_NAME'] ||= '${DB_NAME}'" >> .env.rb cat .env.rb '''