Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:excid3/jumpstart
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 16, 2024
2 parents b9be922 + 74f6fa3 commit 4521c5e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
8 changes: 8 additions & 0 deletions github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://github.com/andyw8/setup-rails for more information

name: Verify
on: [push]

jobs:
verify:
uses: andyw8/setup-rails/.github/workflows/verify.yml@v1
61 changes: 36 additions & 25 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ def add_template_repository_to_source_path
end
end

def read_gemfile?
File.open("Gemfile").each_line do |line|
return true if line.strip.start_with?("rails") && line.include?("6.")
end
end

def rails_version
@rails_version ||= Gem::Version.new(Rails::VERSION::STRING)
@rails_version ||= Gem::Version.new(Rails::VERSION::STRING) || read_gemfile?
end

def rails_6_or_newer?
Gem::Requirement.new(">= 6.0.0.alpha").satisfied_by? rails_version
def rails_7_or_newer?
Gem::Requirement.new(">= 7.0.0.alpha").satisfied_by? rails_version
end

unless rails_7_or_newer?
say "\nJumpstart requires Rails 7 or newer. You are using #{rails_version}.", :green
say "Please remove partially installed Jumpstart files #{original_app_name} and try again.", :green
exit 1
end

def add_gems
Expand Down Expand Up @@ -69,13 +81,11 @@ def add_users

# Set admin default to false
in_root do
migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
migration = Dir.glob("db/migrate/*").max_by { |f| File.mtime(f) }
gsub_file migration, /:admin/, ":admin, default: false"
end

if Gem::Requirement.new("> 5.2").satisfied_by? rails_version
gsub_file "config/initializers/devise.rb", / # config.secret_key = .+/, " config.secret_key = Rails.application.credentials.secret_key_base"
end
gsub_file "config/initializers/devise.rb", / # config.secret_key = .+/, " config.secret_key = Rails.application.credentials.secret_key_base"

inject_into_file("app/models/user.rb", "omniauthable, :", after: "devise :")
end
Expand Down Expand Up @@ -120,21 +130,21 @@ def add_sidekiq
environment "config.active_job.queue_adapter = :sidekiq"

insert_into_file "config/routes.rb",
"require 'sidekiq/web'\n\n",
before: "Rails.application.routes.draw do"
"require 'sidekiq/web'\n\n",
before: "Rails.application.routes.draw do"

content = <<~RUBY
authenticate :user, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
namespace :madmin do
resources :impersonates do
post :impersonate, on: :member
post :stop_impersonating, on: :collection
end
end
end
RUBY
authenticate :user, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
namespace :madmin do
resources :impersonates do
post :impersonate, on: :member
post :stop_impersonating, on: :collection
end
end
end
RUBY
insert_into_file "config/routes.rb", "#{content}\n", after: "Rails.application.routes.draw do\n"
end

Expand Down Expand Up @@ -171,7 +181,7 @@ def add_whenever

def add_friendly_id
generate "friendly_id"
insert_into_file( Dir["db/migrate/**/*friendly_id_slugs.rb"].first, "[5.2]", after: "ActiveRecord::Migration")
insert_into_file(Dir["db/migrate/**/*friendly_id_slugs.rb"].first, "[5.2]", after: "ActiveRecord::Migration")
end

def add_sitemap
Expand Down Expand Up @@ -201,6 +211,10 @@ def add_esbuild_script
end
end

def add_github_actions_ci
copy_file "github/workflows/verify.yml", ".github/workflows/verify.yml"
end

def add_gem(name, *options)
gem(name, *options) unless gem_exists?(name)
end
Expand All @@ -209,10 +223,6 @@ def gem_exists?(name)
IO.read("Gemfile") =~ /^\s*gem ['"]#{name}['"]/
end

unless rails_6_or_newer?
puts "Please use Rails 6.0 or newer to create a Jumpstart application"
end

# Main setup
add_template_repository_to_source_path
default_to_esbuild
Expand All @@ -232,6 +242,7 @@ def gem_exists?(name)
add_whenever
add_sitemap
add_announcements_css
add_github_actions_ci
rails_command "active_storage:install"

# Make sure Linux is in the Gemfile.lock for deploying
Expand Down
7 changes: 6 additions & 1 deletion test/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ def teardown
end

def test_generator_succeeds
output, err = capture_subprocess_io do
output, _err = capture_subprocess_io do
system("DISABLE_SPRING=1 SKIP_GIT=1 rails new test_app -m template.rb")
end
assert_includes output, "Jumpstart app successfully created!"

output, _err = capture_subprocess_io do
system("cd test_app && yarn build")
end
assert_includes output, "Done in "
end

# TODO: Fix these tests on CI so they don't fail on db:create
Expand Down

0 comments on commit 4521c5e

Please sign in to comment.