Skip to content

Commit

Permalink
Merge pull request #9 from nickel/packwerk
Browse files Browse the repository at this point in the history
Packwerk integration
  • Loading branch information
nickel authored Mar 8, 2024
2 parents 2382be9 + b91b1f6 commit 3296909
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 50 deletions.
71 changes: 22 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,6 @@ on:
branches: [ main ]

jobs:
check-security:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Scan for security vulnerabilities
run: bin/check-security

check-style:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Lint code for consistent style
run: bin/check-style

check-libraries:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Lint code for consistent style
run: bin/check-libraries

test:
runs-on: ubuntu-latest
services:
Expand All @@ -77,10 +31,29 @@ jobs:
ruby-version: .ruby-version
bundler-cache: true

- name: Configure DB
env:
RAILS_ENV: "test"
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/pictoplan_test"
run: bin/rails db:setup

- name: Scan for security vulnerabilities
run: bin/check-security

- name: Lint code for consistent style
run: bin/check-style

- name: Audit dependencies
run: bin/check-libraries

- name: Prevent packages' boundaries violations
env:
RAILS_ENV: "test"
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/pictoplan_test"
run: bin/check-packages

- name: Run Tests
env:
RAILS_ENV: "test"
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/pictoplan_test"
run: |
bin/rails db:setup
bin/rails test:all
run: bin/rails test:all
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ group :development do
gem "brakeman"
gem "bundler-audit"
gem "rubocop"
gem "spring"
gem "web-console"
end

group :test do
gem "capybara"
gem "selenium-webdriver"
end

gem "packwerk", "~> 3.2"
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
better_html (2.0.2)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
bigdecimal (3.1.6)
bindex (0.8.1)
bootsnap (1.18.3)
Expand All @@ -100,6 +107,7 @@ GEM
xpath (~> 3.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
constant_resolver (0.2.0)
crass (1.0.6)
date (3.3.4)
debug (1.9.1)
Expand Down Expand Up @@ -152,11 +160,23 @@ GEM
racc (~> 1.4)
nokogiri (1.16.2-x86_64-linux)
racc (~> 1.4)
packwerk (3.2.0)
activesupport (>= 6.0)
ast
better_html
bundler
constant_resolver (>= 0.2.0)
parallel
parser
prism (>= 0.24.0)
sorbet-runtime (>= 0.5.9914)
zeitwerk (>= 2.6.1)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pg (1.5.6)
prism (0.24.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
Expand Down Expand Up @@ -228,6 +248,9 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
smart_properties (1.17.0)
sorbet-runtime (0.5.11287)
spring (4.1.3)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -277,11 +300,13 @@ DEPENDENCIES
debug
importmap-rails
jbuilder
packwerk (~> 3.2)
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)
rubocop
selenium-webdriver
spring
sprockets-rails
stimulus-rails
tailwindcss-rails
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
append_view_path(Dir.glob(Rails.root.join("app/packages/*/views")))
end
3 changes: 3 additions & 0 deletions bin/check-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

bundle exec packwerk check ${@}
27 changes: 27 additions & 0 deletions bin/packwerk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'packwerk' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("packwerk", "packwerk")
1 change: 1 addition & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
load File.expand_path("spring", __dir__)
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"
14 changes: 14 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

# This file loads Spring without loading other gems in the Gemfile in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
require "bundler"

Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem "spring", spring.version
require "spring/binstub"
end
end
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Application < Rails::Application
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w(assets tasks))

config.paths.add "app/packages", glob: "{*,*/concerns}", eager_load: true

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
3 changes: 2 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.cache_classes = false

# While tests run files are not watched, reloading is not necessary.
config.enable_reloading = false
config.enable_reloading = true

# Eager loading loads your entire application. When running a single test locally,
# this is usually not necessary, and can slow down your test suite. However, it's
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ services:
- .:/rails
ports:
- "3000:3000"
environment:
DATABASE_URL: postgres://postgres:postgres@postgres/pictoplan_test
depends_on:
postgres:
condition: service_healthy
11 changes: 11 additions & 0 deletions package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file represents the root package of the application
# Please validate the configuration using `packwerk validate` (for Rails applications) or running the auto generated
# test case (for non-Rails projects). You can then use `packwerk check` to check your code.

# Change to `true` to turn on dependency checks for this package
enforce_dependencies: true

# A list of this package's dependencies
# Note that packages in this list require their own `package.yml` file
# dependencies:
# - "packages/billing"
23 changes: 23 additions & 0 deletions packwerk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See: Setting up the configuration file
# https://github.com/Shopify/packwerk/blob/main/USAGE.md#configuring-packwerk

# List of patterns for folder paths to include
# include:
# - "**/*.{rb,rake,erb}"

# List of patterns for folder paths to exclude
# exclude:
# - "{bin,node_modules,script,tmp,vendor}/**/*"

# Patterns to find package configuration files
# package_paths: "**/"

# List of custom associations, if any
# custom_associations:
# - "cache_belongs_to"

# Whether or not you want the cache enabled (disabled by default)
# cache: true

# Where you want the cache to be stored (default below)
# cache_directory: 'tmp/cache/packwerk'

0 comments on commit 3296909

Please sign in to comment.