decidim-cdtb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e29cddba26f79365ef28173d20a58ee1ae85d6a5cd8bc247c6652812497e96dd
4
- data.tar.gz: 655282c8af0fa533ddf28ce34a913ca3e4e1ff49787cf266ded32054f2d7045b
3
+ metadata.gz: d908d1cc4021da9869dd10cacb1fe06b360301d4e13f1a70a55fdc90a2712b6a
4
+ data.tar.gz: e7a0c808803bbbd6dc75e5bdfaee7b3acfb1311c085f17eb41a9de32fc7795fa
5
5
  SHA512:
6
- metadata.gz: b79a03dd6ffe799944966da2d357abb75ebe99d543aa9ad916c45999a2bc07bf8632c732565d1501e7572055d7172f90f85efdf640737165baa940ecc8724446
7
- data.tar.gz: e59ad9f9295e1c4db656a2793e4ce4f002f1c25e75e2dc37d99c8bd819a9dc29f0497438bd6c32d1f41f4af654d8094f39c3876825b1bc0216a621751b5460d6
6
+ metadata.gz: 20ddde6eddf59ab12b7ca8d6f489692a04183331f0c1ef496b199b4350cdd103d2b23ca94329199d36f2a9e7222ea0c3269da25648ec0acb47bdde6b38666b92
7
+ data.tar.gz: 2dd41a8a1f79ffd4506c6b18d58393d3a88d8a021e0acf05cfbd4e4ac1dcc22250294c8de29d7168c2fce29bf2d2df71c0b9905414a3df1e28991aa665be8d36
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.2] - 2023-06-02
3
+ ## [0.1.3] - 2023-06-23 (Tan iguals com especials)
4
+
5
+ - Validate migrations task
6
+
7
+ ## [0.1.2] - 2023-06-02 (Empastifada amb melmelada)
4
8
 
5
9
  - Add anonymize rake task
6
10
 
data/Gemfile CHANGED
@@ -25,4 +25,5 @@ end
25
25
 
26
26
  group :test do
27
27
  gem "rspec", "~> 3.0"
28
+ gem "sqlite3"
28
29
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-cdtb (0.1.2)
4
+ decidim-cdtb (0.1.3)
5
5
  decidim (>= 0.26.2)
6
6
  rails (>= 6)
7
7
  ruby-progressbar
@@ -700,6 +700,7 @@ GEM
700
700
  actionpack (>= 5.2)
701
701
  activesupport (>= 5.2)
702
702
  sprockets (>= 3.0.0)
703
+ sqlite3 (1.6.3-x86_64-linux)
703
704
  ssrf_filter (1.1.1)
704
705
  system_test_html_screenshots (0.2.0)
705
706
  actionpack (>= 5.2, < 6.1.a)
@@ -771,6 +772,7 @@ DEPENDENCIES
771
772
  rake (~> 13.0)
772
773
  rspec (~> 3.0)
773
774
  rubocop
775
+ sqlite3
774
776
 
775
777
  BUNDLED WITH
776
778
  2.3.6
data/README.md CHANGED
@@ -8,16 +8,16 @@ This is CodiTramuntana's Decidim Toolbelt (cdtb), a gem to help managing Decidim
8
8
  Install the gem and add to the application's Gemfile by executing:
9
9
 
10
10
  $ bundle add decidim-cdtb
11
+ $ bundle install
11
12
 
12
- If bundler is not being used to manage dependencies, install the gem by executing:
13
+ Install CI tests on your app with:
13
14
 
14
- $ gem install decidim-cdtb
15
+ $ bin/rails generate cdtb:validate_migrations_ci
15
16
 
16
- ## Usage
17
17
 
18
- ### Rake tasks
18
+ ## Usage
19
19
 
20
- #### Organizations information
20
+ ### Organizations information
21
21
 
22
22
  Returns information regarding the organizations in a multitenant installation that match a search term ignorecase.
23
23
 
@@ -36,7 +36,7 @@ bin/rake cdtb:org_by_host_like[vila]
36
36
  host: localhost, time_zone: Madrid, locales: ca + [ca, es, oc], available authorizations: [postal_letter, members_picker_authorization_handler]
37
37
  ```
38
38
 
39
- #### Fix nicknames
39
+ ### Fix nicknames
40
40
 
41
41
  In a previous version than Decidim v0.25 a validation to the `Decidim::User.nickname` was added with a migration to fix existing nicknames. But the migration was only taking into acocunt managed (impersonated) users.
42
42
 
@@ -48,27 +48,21 @@ To execute the task run:
48
48
  bin/rake cdtb:fix_nicknames
49
49
  ```
50
50
 
51
- #### Anonymize production dump
51
+ ### Anonymize production dump
52
52
 
53
53
  Anonymize rake task was taken from https://github.com/AjuntamentdeBarcelona/decidim-barcelona
54
54
 
55
55
  Available rake tasks:
56
56
 
57
- ```bin/rake cdtb:anonymize:check``` allows you to check if you can anonymize production dump
58
-
59
- ```bin/rake cdtb:anonymize:all``` anonymizes whole production dump (without proposals)
60
-
61
- ```bin/rake cdtb:anonymize:users``` anonymizes users
62
-
63
- ```bin/rake cdtb:anonymize:proposals``` anonymizes proposals
57
+ - `bin/rake cdtb:anonymize:check` allows you to check if you can anonymize production dump
58
+ - `bin/rake cdtb:anonymize:all` anonymizes whole production dump (without proposals)
59
+ - `bin/rake cdtb:anonymize:users` anonymizes users
60
+ - `bin/rake cdtb:anonymize:proposals` anonymizes proposals
61
+ - `bin/rake cdtb:anonymize:user_groups` anonymizes user groups
62
+ - `bin/rake cdtb:anonymize:system_admins` anonymizes system admins
63
+ - `bin/rake cdtb:anonymize:paper_trail` anonymizes paper trails
64
64
 
65
- ```bin/rake cdtb:anonymize:user_groups``` anonymizes user groups
66
-
67
- ```bin/rake cdtb:anonymize:system_admins``` anonymizes system admins
68
-
69
- ```bin/rake cdtb:anonymize:paper_trail``` anonymizes paper trails
70
-
71
- #### Migrate ActiveStorage service from S3 to local
65
+ ### Migrate ActiveStorage service from S3 to local
72
66
 
73
67
  To migrate from S3 to local storage, the identified steps will be:
74
68
 
@@ -82,6 +76,26 @@ To migrate from S3 to local storage, the identified steps will be:
82
76
  `bin/rake cache:clear`
83
77
  5. Restart the Rails server
84
78
 
79
+ ### Upgrades:
80
+
81
+ #### Upgrade modules
82
+
83
+ Upgrades the gems with engines in them. All, Decidim modules and standard Rails engines.
84
+
85
+ TO-DO To be finished
86
+
87
+ #### Validate migrations
88
+
89
+ Validates that migrations from all gems in the Gemfile have already been installed.
90
+
91
+ ```
92
+ bin/rake cdtb:upgrades:validate_migrations
93
+ ```
94
+
95
+ See the [Installation](#installation) chapter to install a GitHub Action on your app that will run this validation on your CI.
96
+
97
+ TO-DO also check that all migrations have been executed and the schema.rb does not change
98
+
85
99
  ## Development
86
100
 
87
101
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -107,7 +121,7 @@ bundle exec rspec spec
107
121
 
108
122
  ## Contributing
109
123
 
110
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/decidim-cdtb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/decidim-cdtb/blob/master/CODE_OF_CONDUCT.md).
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/CodiTramuntana/decidim-cdtb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/CodiTramuntana/decidim-cdtb/blob/master/CODE_OF_CONDUCT.md).
111
125
 
112
126
  ## License
113
127
 
@@ -115,4 +129,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
115
129
 
116
130
  ## Code of Conduct
117
131
 
118
- Everyone interacting in the Decidim::Cdtb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/decidim-cdtb/blob/master/CODE_OF_CONDUCT.md).
132
+ Everyone interacting in the Decidim::Cdtb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/CodiTramuntana/decidim-cdtb/blob/master/CODE_OF_CONDUCT.md).
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- # Census have no public app (see AdminEngine)
5
+ # This module's engine
6
6
  class Engine < ::Rails::Engine
7
7
  isolate_namespace Decidim::Cdtb
8
8
 
@@ -30,9 +30,9 @@ module Decidim
30
30
  locales: "#{org.default_locale} + [#{org.available_locales&.join(", ")}]",
31
31
  available_authorizations: org.available_authorizations&.join(", ")
32
32
  }
33
- do_log(h.to_yaml)
33
+ do_log_info(h.to_yaml)
34
34
  end
35
- do_log("---------------------------------------------------------")
35
+ do_log_info("---------------------------------------------------------")
36
36
  end
37
37
  end
38
38
 
@@ -47,7 +47,7 @@ module Decidim
47
47
  end
48
48
 
49
49
  def show_full_info(org)
50
- do_log(org.attributes.to_yaml)
50
+ do_log_info(org.attributes.to_yaml)
51
51
  end
52
52
 
53
53
  def show_summary_info(org)
@@ -57,7 +57,7 @@ module Decidim
57
57
  locales: "#{org.default_locale} + [#{org.available_locales&.join(", ")}]",
58
58
  available_authorizations: org.available_authorizations&.join(", ")
59
59
  }
60
- do_log(h.to_yaml)
60
+ do_log_info(h.to_yaml)
61
61
  end
62
62
  end
63
63
  end
@@ -22,21 +22,21 @@ module Decidim
22
22
  def init
23
23
  log_task_title(@title)
24
24
  @start_time= Time.zone.now
25
- do_log("▶️ Starting at #{@start_time}")
25
+ do_log_info("▶️ Starting at #{@start_time}")
26
26
  end
27
27
 
28
28
  def execute!
29
29
  init
30
30
  ctx= {}
31
- ctx[:progress_bar]= ProgressBar.create(total: total_items, title: title) if has_progress?
32
31
  prepare_execution(ctx)
32
+ ctx[:progress_bar]= ProgressBar.create(total: total_items, title: title) if has_progress?
33
33
  do_execution(ctx)
34
34
  end_execution(ctx)
35
35
  finish
36
36
  end
37
37
 
38
38
  def finish
39
- do_log("⏱️ Took #{Time.zone.now - @start_time} seconds")
39
+ do_log_info("⏱️ Took #{Time.zone.now - @start_time} seconds")
40
40
  log_task_end
41
41
  end
42
42
 
@@ -6,3 +6,4 @@ require "decidim/cdtb/fixes/nickname_fixer"
6
6
  require "decidim/cdtb/multitenants/org_by_host_like"
7
7
  require "decidim/cdtb/storage/local_sharding"
8
8
  require "decidim/cdtb/storage/set_local_on_blobs"
9
+ require "decidim/cdtb/upgrades/validate_migrations_task"
@@ -10,26 +10,40 @@ module Decidim
10
10
  Rails.logger
11
11
  end
12
12
 
13
- def do_log(msg)
13
+ def do_log_info(msg)
14
14
  puts msg
15
15
  logger.info(msg)
16
16
  end
17
17
 
18
+ def do_log_error(msg)
19
+ puts msg
20
+ logger.error(msg)
21
+ end
22
+
18
23
  def log_task_title(title)
19
- do_log("⚙️ #{title}")
24
+ do_log_info("⚙️ #{title}")
20
25
  end
21
26
 
22
27
  def log_task_step(description)
23
- do_log("➡️ #{description}")
28
+ do_log_info("➡️ #{description}")
24
29
  end
25
30
 
26
31
  def log_task_info(info)
27
- do_log("ℹ️ #{info}")
32
+ do_log_info("ℹ️ #{info}")
33
+ end
34
+
35
+ def log_task_failure(msg)
36
+ @failed= true
37
+ do_log_error("⚠️ #{msg}")
28
38
  end
29
39
 
30
40
  def log_task_end
31
- end_comment= "✅ Done."
32
- do_log(end_comment)
41
+ end_comment= if defined?(@failed) && @failed
42
+ "❌ Ended with errors!"
43
+ else
44
+ "✅ Done."
45
+ end
46
+ do_log_info(end_comment)
33
47
  end
34
48
  end
35
49
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Cdtb
5
+ module Upgrades
6
+ # Invokes rails to install gem migrations
7
+ #
8
+ class InstallGemMigrationsStep
9
+ # Pass +gem_names+ to define from which gems to install migrations.
10
+ def install!(gem_names)
11
+ cmd= "#{Rails.root.join("bin/rails")} railties:install:migrations"
12
+ env_vars= "FROM=#{gem_names.join(",")}"
13
+ `#{cmd} #{env_vars}`
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Cdtb
5
+ module Upgrades
6
+ # Upgrades the gems with engines in them. All, Decidim modules and standard Rails engines.
7
+ #
8
+ class UpgradeModulesTask < ::Decidim::Cdtb::Task
9
+ def initialize
10
+ progress_bar= { title: "Modules" }
11
+ super("UPGRADE MODULES", progress_bar: progress_bar)
12
+ end
13
+
14
+ def prepare_execution(_ctx)
15
+ log_task_info("Have you updated the versions of your modules in the Gemfile (y/n)?")
16
+ response= $stdin.gets
17
+ if response&.downcase == "y"
18
+ get the number of modules
19
+ else
20
+ @exit= true
21
+ end
22
+ end
23
+
24
+ def total_items
25
+ @num_users
26
+ end
27
+
28
+ def do_execution(context)
29
+ # progress_bar= context[:progress_bar]
30
+
31
+ # system("bundle update decidim")
32
+ # system("bin/rails decidim:upgrade")
33
+ # system("bin/rails db:migrate")
34
+ end
35
+
36
+ def end_execution(_ctx)
37
+ log_task_step("#{@num_applied} users nicknamized")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "install_gem_migrations_step"
4
+
5
+ module Decidim
6
+ module Cdtb
7
+ module Upgrades
8
+ # Validates that all Decidim modules have the migrations installed.
9
+ #
10
+ class ValidateMigrationsTask < ::Decidim::Cdtb::Task
11
+ STEPS_IN_DO_EXECUTION= 2
12
+
13
+ def initialize
14
+ progress_bar= { title: "Modules" }
15
+ super("VALIDATE MODULES MIGRATIONS", progress_bar: progress_bar)
16
+ end
17
+
18
+ def prepare_execution(_ctx)
19
+ all_railties= Rails.application.migration_railties
20
+ railties_w_migrations= all_railties.select do |railtie|
21
+ railtie.respond_to?(:paths) && railtie.paths["db/migrate"].first.present?
22
+ end
23
+ @gem_names= railties_w_migrations.map(&:railtie_name)
24
+
25
+ log_task_info("Found #{@gem_names.size} gems with migrations. Validating.....")
26
+ end
27
+
28
+ def total_items
29
+ STEPS_IN_DO_EXECUTION
30
+ end
31
+
32
+ def pending_migrations?
33
+ @pending_migrations.present?
34
+ end
35
+
36
+ def do_execution(context)
37
+ progress_bar= context[:progress_bar]
38
+
39
+ output= install_gem_migrations
40
+
41
+ progress_bar.increment
42
+
43
+ @pending_migrations= output.lines.select { |l| l.include?("Copied migration") }
44
+
45
+ progress_bar.increment
46
+ end
47
+
48
+ def end_execution(_ctx)
49
+ log_task_step("#{@gem_names.size} gems validated")
50
+ log_task_failure(@pending_migrations.join("\n")) if pending_migrations?
51
+ end
52
+
53
+ def install_gem_migrations
54
+ install_step= InstallGemMigrationsStep.new
55
+ install_step.install!(@gem_names)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  DECIDIM_MIN_VERSION = ">= 0.26.2"
7
7
  end
8
8
  end
data/lib/decidim/cdtb.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "cdtb/version"
4
4
  require_relative "cdtb/engine"
5
+ require_relative "cdtb/tasks"
5
6
 
6
7
  module Decidim
7
8
  module Cdtb
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Installs a GitHub workflow to validate that all migrations from all engines have been installed
3
+
4
+ Example:
5
+ rails generate validate_migrations
6
+
7
+ This will create:
8
+ .github/workflows/validate_migrations.yml
@@ -0,0 +1,52 @@
1
+ name: "[CI] Validate migrations"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ - release/*
8
+ - "*-stable"
9
+ pull_request:
10
+
11
+ env:
12
+ DB_DATABASE: app
13
+ DB_USERNAME: postgres
14
+ DB_PASSWORD: postgres
15
+ RUBY_VERSION: 3.1.3
16
+
17
+ jobs:
18
+ test:
19
+ runs-on: ubuntu-latest
20
+ env:
21
+ SECRET_KEY_BASE: "secret_key_base"
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2.0.0
25
+ with:
26
+ fetch-depth: 1
27
+ - uses: ruby/setup-ruby@master
28
+ with:
29
+ ruby-version: ${{ env.RUBY_VERSION }}
30
+ bundler-cache: true
31
+ - name: Recover Ruby dependency cache
32
+ uses: actions/cache@v1
33
+ with:
34
+ path: ./vendor/bundle
35
+ key: ${{ runner.OS }}-app-rubydeps-${{ hashFiles('Gemfile.lock') }}
36
+ restore-keys: |
37
+ ${{ runner.OS }}-app-rubydeps-${{ env.cache-name }}-
38
+ ${{ runner.OS }}-app-rubydeps-
39
+
40
+ - name: Set bundle local config vendor/bundle path
41
+ run: bundle config set --local path 'vendor/bundle'
42
+
43
+ - name: Install Ruby deps
44
+ uses: nick-invision/retry@v2
45
+ with:
46
+ timeout_minutes: 10
47
+ max_attempts: 3
48
+ retry_on: error
49
+ command: bundle install --jobs 4 --retry 3
50
+
51
+ - name: Run specs
52
+ run: bin/rails cdtb:upgrades:validate_migrations
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cdtb
4
+ # Generates the GitHub workflow that validates that the app has the migrations from all gems already installed
5
+ class ValidateMigrationsCiGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def copy_github_workflow_file
9
+ copy_file "validate_migrations.yml", ".github/workflows/validate_migrations.yml"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # A set of utils to manage Decidim Organizations.
5
+ #
6
+ namespace :cdtb do
7
+ namespace :upgrades do
8
+ require "decidim/cdtb/tasks_utils"
9
+ include ::Decidim::Cdtb::TasksUtils
10
+
11
+ desc <<~EODESC
12
+ Validates that migrations from all gems in the Gemfile have been installed.
13
+ EODESC
14
+ task validate_migrations: [:environment] do
15
+ task= ::Decidim::Cdtb::Upgrades::ValidateMigrationsTask.new
16
+ task.execute!
17
+ raise("There are pending migrations") if task.pending_migrations?
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-cdtb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Valls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim
@@ -110,11 +110,18 @@ files:
110
110
  - lib/decidim/cdtb/task.rb
111
111
  - lib/decidim/cdtb/tasks.rb
112
112
  - lib/decidim/cdtb/tasks_utils.rb
113
+ - lib/decidim/cdtb/upgrades/install_gem_migrations_step.rb
114
+ - lib/decidim/cdtb/upgrades/upgrade_modules_task.rb
115
+ - lib/decidim/cdtb/upgrades/validate_migrations_task.rb
113
116
  - lib/decidim/cdtb/version.rb
117
+ - lib/generators/cdtb/USAGE
118
+ - lib/generators/cdtb/templates/validate_migrations.yml
119
+ - lib/generators/cdtb/validate_migrations_ci_generator.rb
114
120
  - lib/tasks/anonymize.rake
115
121
  - lib/tasks/cdtb.rake
116
122
  - lib/tasks/multitenants.rake
117
123
  - lib/tasks/storage.rake
124
+ - lib/tasks/upgrade.rake
118
125
  - sig/decidim/cdtb.rbs
119
126
  homepage: http://github.com/CodiTramunana/cdtb
120
127
  licenses: