Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Componentisation proof of concept #9154

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
security-events: write
actions: read

packwerk-check:
name: Packwerk check
uses: ./.github/workflows/packwerk.yml

lint-scss:
name: Lint SCSS
uses: ./.github/workflows/lintscss.yml
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/packwerk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Run Packwerk Check

on:
workflow_call:

jobs:
run-packwerk:
name: Run Packwerk Check
runs-on: ubuntu-latest
steps:
- name: Setup MySQL
id: setup-mysql
uses: alphagov/govuk-infrastructure/.github/actions/setup-mysql@main

- name: Setup Redis
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main

- name: Install additional system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ghostscript

- uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Initialize database
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec rails db:setup

- name: Run Packwerk Check
env:
RAILS_ENV: test
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec packwerk check
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ Style/OptionalBooleanParameter:
Lint/MissingSuper:
Exclude:
- 'app/components/**/*.rb'
- 'packages/**/app/components/**/*.rb'

Rails/SaveBang:
Exclude:
- 'Rakefile'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gem "mime-types"
gem "mini_magick"
gem "mysql2"
gem "nokogiri"
gem "packwerk"
gem "pdf-reader"
gem "plek"
gem "ptools"
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
constant_resolver (0.2.0)
crack (1.0.0)
bigdecimal
rexml
Expand Down Expand Up @@ -682,6 +683,17 @@ GEM
opentelemetry-semantic_conventions
opentelemetry-semantic_conventions (1.10.0)
opentelemetry-api (~> 1.0)
packwerk (3.2.1)
activesupport (>= 6.0)
ast
better_html
bundler
constant_resolver (>= 0.2.0)
parallel
parser
prism (>= 0.25.0)
sorbet-runtime (>= 0.5.9914)
zeitwerk (>= 2.6.1)
pact (1.64.0)
pact-mock_service (~> 3.0, >= 3.3.1)
pact-support (~> 1.16, >= 1.16.9)
Expand Down Expand Up @@ -722,6 +734,7 @@ GEM
ruby-rc4
ttfunk
plek (5.2.0)
prism (0.30.0)
prometheus_exporter (2.1.0)
webrick
pry (0.14.2)
Expand Down Expand Up @@ -926,6 +939,7 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
sorbet-runtime (0.5.11429)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -1053,6 +1067,7 @@ DEPENDENCIES
mocha
mysql2
nokogiri
packwerk
pact
pact_broker-client
pdf-reader
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ ENV["LOG_LEVEL"] = "warn"
# sensible coverage reports when running a full test suite,
# without overwriting them when we're just running a single test
ENV["COVERAGE"] = "true"

require "minitest/test_task"
require File.expand_path("config/application", __dir__)

Whitehall::Application.load_tasks

Minitest::TestTask.create do |t|
t.test_globs = %w[test/**/*_test.rb packages/**/test/**/*_test.rb]
end

Rake::Task[:default].clear if Rake::Task.task_defined?(:default)
task default: %i[lint test cucumber jasmine]
4 changes: 2 additions & 2 deletions app/views/admin/shared/_featurable_editions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<%= render "admin/editions/filter_options", filter_by:, filter_action:, anchor: %>
<%= render("admin/editions/filter_options", filter_by:, filter_action:, anchor:) %>
</div>
<div class="govuk-grid-column-two-thirds">
<div class="app-view-features-search-results__table" aria-label="Search results">
<%= render "admin/featurable_editions/search_results", featurable_editions:, paginator:, anchor:, feature_path: %>
<%= render("admin/featurable_editions/search_results", featurable_editions:, paginator:, anchor:, feature_path:) %>
</div>
</div>
</div>
6 changes: 5 additions & 1 deletion bin/minitest-ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
# defined in .github/workflows/minitest.yml.
# It splits the MiniTest suite into randomly-allocated groups
# which are executed across multiple GitHub Actions 'matrix' nodes.
test_files = [
Dir["test/**/*_test.rb"],
Dir["packages/**/test/**/*_test.rb"],
].flatten

tests = Dir["test/**/*_test.rb"].
tests = test_files.
sort.
shuffle(random: Random.new(ENV['GITHUB_SHA'].to_i(16))).
select.
Expand Down
10 changes: 10 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

# Require all Engines inside the `packages` directory
Dir.glob("packages/*/lib/*/engine.rb").each do |engine_path|
require_relative "../#{engine_path}"
end

module Whitehall
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
Expand Down Expand Up @@ -125,5 +130,10 @@ class Application < Rails::Application
# By default, when set to `nil`, strategy loading errors are suppressed in test
# mode. Set to `true` to always raise errors, or `false` to always warn.
config.flipflop.raise_strategy_errors = nil

# Include all routes included in packages
Dir[Rails.root.join("packages/**/config/routes/*.rb")].each do |route_file|
config.paths["config/routes"].push(route_file)
end
end
end
32 changes: 4 additions & 28 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,7 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })
resources :operational_fields, except: [:show]
resources :edition_organisations, only: %i[edit update]

resources :topical_events, path: "topical-events" do
resource :topical_event_about_pages, path: "about"
resources :topical_event_featurings, path: "featurings" do
get :reorder, on: :collection
put :order, on: :collection
get :confirm_destroy, on: :member
end
resources :topical_event_organisations, path: "organisations" do
get :reorder, on: :collection
put :order, on: :collection
get :toggle_lead, on: :member
end
resources :offsite_links do
get :confirm_destroy, on: :member
end
get :confirm_destroy, on: :member
end
draw(:topical_events)

resources :worldwide_organisations do
member do
Expand Down Expand Up @@ -410,20 +394,12 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })

post "preview" => "preview#preview"

scope "/get-involved" do
root to: "get_involved#index", as: :get_involved, via: :get
resources :take_part_pages, except: [:show] do
post :reorder, on: :collection
get :confirm_destroy, on: :member
get :update_order, on: :collection
end
end
draw(:get_involved)

resources :sitewide_settings
resource :emergency_banner, controller: "emergency_banner" do
get :confirm_destroy
end
post "/link-checker-api-callback" => "link_checker_api#callback"

draw(:emergency_banner)
end
end

Expand Down
5 changes: 5 additions & 0 deletions package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enforce_dependencies: true
dependencies:
- packages/base


86 changes: 86 additions & 0 deletions package_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This file contains a list of dependencies that are not part of the long term plan for the
# '.' package.
# We should generally work to reduce this list over time.
#
# You can regenerate this file using the following command:
#
# bin/packwerk update-todo
---
packages/get_involved:
"::PublishingApi::TakePartPresenter":
violations:
- dependency
files:
- test/unit/app/presenters/publishing_api_presenters_test.rb
"::TakePartPage":
violations:
- dependency
files:
- app/presenters/search_api_presenters.rb
- features/step_definitions/take_part_pages_steps.rb
- test/unit/app/presenters/publishing_api_presenters_test.rb
packages/topical_events:
"::PublishingApi::PayloadBuilder::TopicalEvents":
violations:
- dependency
files:
- app/presenters/publishing_api/call_for_evidence_presenter.rb
- app/presenters/publishing_api/consultation_presenter.rb
- app/presenters/publishing_api/detailed_guide_presenter.rb
- app/presenters/publishing_api/document_collection_presenter.rb
- app/presenters/publishing_api/news_article_presenter.rb
- app/presenters/publishing_api/publication_presenter.rb
- test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb
- test/unit/app/presenters/publishing_api/payload_builder/topical_events_test.rb
"::PublishingApi::TopicalEventPresenter":
violations:
- dependency
files:
- test/unit/app/presenters/publishing_api_presenters_test.rb
"::TopicalEvent":
violations:
- dependency
files:
- app/controllers/admin/features_controller.rb
- app/controllers/admin/offsite_links_controller.rb
- app/controllers/admin/organisations_controller.rb
- app/controllers/admin/world_location_news_controller.rb
- app/helpers/admin/taggable_content_helper.rb
- app/models/admin/edition_filter.rb
- app/models/concerns/edition/topical_events.rb
- app/models/feature.rb
- app/models/organisation.rb
- app/presenters/search_api_presenters.rb
- app/views/admin/editions/_topical_event_fields.html.erb
- app/views/admin/offsite_links/confirm_destroy.html.erb
- app/views/admin/organisations/_form.html.erb
- db/data_migration/20230411085954_restore_coronation_topical_event.rb
- features/step_definitions/topical_event_featurings_steps.rb
- features/step_definitions/topical_event_steps.rb
- features/support/topical_events_helper.rb
- lib/tasks/reslugging.rake
- lib/tasks/search.rake
- test/unit/app/models/edition/topical_events_test.rb
- test/unit/app/models/simple_workflow_test.rb
- test/unit/app/models/speech_test.rb
- test/unit/app/presenters/publishing_api_presenters_test.rb
"::TopicalEventFeaturing":
violations:
- dependency
files:
- app/models/concerns/edition/topical_events.rb
- app/models/edition.rb
- test/unit/app/models/edition/topical_events_test.rb
"::TopicalEventMembership":
violations:
- dependency
files:
- app/models/concerns/edition/topical_events.rb
- test/unit/app/models/edition/topical_events_test.rb
"::TopicalEventOrganisation":
violations:
- dependency
files:
- app/models/organisation.rb
- db/data_migration/20230518160200_reinstate_independent_agricultural_appeals_panel_organisation.rb
- test/unit/app/models/organisation_test.rb
2 changes: 2 additions & 0 deletions packages/base/lib/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Base
end
4 changes: 4 additions & 0 deletions packages/base/lib/base/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Base
class Engine < ::Rails::Engine
end
end
1 change: 1 addition & 0 deletions packages/base/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enforce_dependencies: true
Loading
Loading