thecore_generators 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +77 -42
- data/lib/generators/thecore/atom/atom_generator.rb +252 -35
- data/lib/generators/thecore/workspace_context.rb +21 -2
- data/lib/templates/app_template.rb +124 -41
- data/lib/thecore_generators/check_practices.rb +1 -1
- data/lib/thecore_generators/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c96cf53c100408b84dad8704e8008fc6ca860d8b99fc0e4c4da605b702a0bdd0
|
|
4
|
+
data.tar.gz: 4b2b88048110f0ecc45b780ee7f92eada4235bfbbb4fa89322366bb38adee079
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7ec0f8d41dc5f67a0f2a9fab4ed436d49ac2877c1686861403ce2f00e5ea7f8b1bf9794f6cb63d0ef0a9d0855b27d8e6285f0d70eaa034bf7c50312cfbd81ba
|
|
7
|
+
data.tar.gz: 63ebaace602a89a384c7b340559269d3d5a4eb5bfb20b7c538180817312229e2ffcdd94d30915180417dc18a4fb38297878408fd9431621ff1adbbb7365bf77b
|
data/README.md
CHANGED
|
@@ -31,16 +31,16 @@ in the thecore repo for the full design. **The Collection Action generator** (`r
|
|
|
31
31
|
thecore:collection_action`, thecore_generators#21) is also complete as of this release — see
|
|
32
32
|
[ADR 0006](https://github.com/gabrieletassoni/thecore/blob/master/docs/adr/0006-atom-generator-dual-ci-manual-submodule-wiring-collection-action-reuses-existing-infra.md)
|
|
33
33
|
in the thecore repo (`master`, thecore's actual default branch — unlike this gem's own
|
|
34
|
-
`release/3`; the ADR 0001-0005 links above predate that distinction being double-checked
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
`release/3`; the ADR 0001-0005 links above predate that distinction being double-checked).
|
|
35
|
+
**`thecore:atom`** (`rails generate thecore:atom NAME`, thecore_generators#20/#22) is
|
|
36
|
+
feature-complete, including its `CLAUDE.md` fetch from thecore's own `samples/ATOM_CLAUDE.md`.
|
|
37
|
+
Both generators are documented in the thecore repo's `docs/GUIDE.md` (§4.2.1, §4.2.2, §4.8) and
|
|
38
|
+
`docs/WALKTHROUGH.md`.
|
|
39
|
+
|
|
40
|
+
The App template and `thecore:atom` fetch their samples from `thecore`'s `master` on GitHub, so
|
|
41
|
+
a sample this gem starts fetching must be on `master` before the release that fetches it (until
|
|
42
|
+
then the fetch 404s and the generator aborts with a message naming the file). See the
|
|
43
|
+
Unreleased entries in `CHANGELOG.md` for the samples the next release needs.
|
|
44
44
|
|
|
45
45
|
### What `rails generate model`/`rails generate migration` do now
|
|
46
46
|
|
|
@@ -240,9 +240,17 @@ silently overwrite an existing ATOM with the same name.
|
|
|
240
240
|
It prompts (interactively, or via `--summary=`/`--description=`/`--author=`/`--email=`/`--url=`
|
|
241
241
|
with `--non-interactive`) for the same five fields `createATOM.js` always has, then:
|
|
242
242
|
|
|
243
|
-
- Shells to `rails plugin new <path> -fG --skip-gemfile-entry --skip-hotwire --full
|
|
244
|
-
`bundle exec`, for robust gem resolution regardless of
|
|
245
|
-
Rails engine skeleton.
|
|
243
|
+
- Shells to `rails plugin new <path> -fG --skip-gemfile-entry --skip-hotwire --full
|
|
244
|
+
--database=postgresql --skip-ci` (via `bundle exec`, for robust gem resolution regardless of
|
|
245
|
+
environment), producing the standard Rails engine skeleton. The dummy app runs on PostgreSQL
|
|
246
|
+
(never SQLite): its `database.yml` takes the server from `PGHOST`/`PGPORT`/`PGUSER`/`PGPASSWORD`
|
|
247
|
+
(default: the devcontainer's `db`) and uses `<name>_development`/`_test`/`_production`. Its
|
|
248
|
+
`config/boot.rb` applies the test-database rule: when `DATABASE_URL` is set (the devcontainer
|
|
249
|
+
points it at the host app's development database), it keeps the server/credentials but always
|
|
250
|
+
uses `<name>_<RAILS_ENV>` (also when the URL names only the server), so running the ATOM's tests (the test helper sets `RAILS_ENV=test`)
|
|
251
|
+
never touches development data. `--skip-ci` drops the SQLite-based `.github/workflows/ci.yml`
|
|
252
|
+
and `.github/dependabot.yml` `rails plugin new` writes by itself: the only CI is Thecore's own
|
|
253
|
+
(below).
|
|
246
254
|
- Asks (`yes?`-style, default yes; `--skip-api-admin-deps` in non-interactive mode) whether to
|
|
247
255
|
add `model_driven_api`/`thecore_ui_rails_admin` as dependencies — at this gem's own ADR 0001
|
|
248
256
|
floor (`~> 3.9`/`~> 3.8`), not `createATOM.js`'s stale `~> 3.1`/`~> 3.2`. Declining adds
|
|
@@ -258,16 +266,28 @@ with `--non-interactive`) for the same five fields `createATOM.js` always has, t
|
|
|
258
266
|
per-developer choice this ecosystem already treats as generic). `gempush.yml`'s two
|
|
259
267
|
long-standing bugs are fixed here (a broken `awk` pipeline computing the version string; a
|
|
260
268
|
`version_exists` check referenced in `if:` conditions but never actually set, so the
|
|
261
|
-
tag/publish steps have never run for any ATOM generated this way).
|
|
262
|
-
`
|
|
269
|
+
tag/publish steps have never run for any ATOM generated this way). Both publish like the real
|
|
270
|
+
ATOMs (thecore_devcontainer#14): `gempush.yml` only on pushes to `release/3`; `.gitlab-ci.yml`'s
|
|
271
|
+
`build_gem` only when `lib/*/version.rb` changes, plus GitLab's SAST and Secret Detection
|
|
272
|
+
templates and a `security-summary` job running `script/security_summary.rb`, which is fetched
|
|
273
|
+
from `thecore`'s samples with its test (`test/script/security_summary_test.rb`).
|
|
274
|
+
- `--gem-host=HOST` (default `rubygems.org`) names the gem server: the gemspec's
|
|
275
|
+
`allowed_push_host` becomes `https://HOST`, and for a host other than RubyGems the GitLab CI
|
|
276
|
+
pushes there (`GITLAB_GEM_REPO_TARGET`), and so does `gempush.yml` (`gem push --host
|
|
277
|
+
https://HOST`, with the API key in the GitHub repository secret `GEMS_REPO_CREDENTIALS`). With
|
|
278
|
+
the default the variable is left out, so the image's `gem-compile.sh` pushes to RubyGems, and
|
|
279
|
+
`gempush.yml` pushes to RubyGems with the `RUBYGEMS_AUTH_TOKEN` secret. The gemspec requires `rails ~> 7.2`, the Rails of
|
|
280
|
+
Thecore 3 hosts.
|
|
263
281
|
- Rewrites the gemspec's authors/email/homepage/summary/description/metadata fields via targeted
|
|
264
282
|
in-memory substitutions (not `createATOM.js`'s own blind full-file line rewrite, which —
|
|
265
283
|
verified directly against a current `rails plugin new --full` gemspec — silently drops the
|
|
266
284
|
gem's own `rails` dependency when adding the two Thecore ones; this appends instead of
|
|
267
285
|
replacing).
|
|
268
|
-
- `git init`s the new ATOM directory with one initial commit, then **logs** (never runs) the
|
|
269
|
-
exact follow-up commands to create a remote and `git submodule add` it into the
|
|
270
|
-
|
|
286
|
+
- `git init`s the new ATOM directory on `release/3` with one initial commit, then **logs** (never runs) the
|
|
287
|
+
exact follow-up commands to create a remote and `git submodule add -b release/3` it into the
|
|
288
|
+
host app, followed by the "Changing an ATOM" workflow: how to move the host `Gemfile` from the
|
|
289
|
+
`path:` entry to the published gem (`bundle update <name> --conservative`, then commit
|
|
290
|
+
`Gemfile.lock` with the submodule pointer) — worded generically, no GitHub/GitLab assumption (ADR 0006: automating a remote-repo-creating,
|
|
271
291
|
credential-dependent step isn't something this generator does on your behalf).
|
|
272
292
|
- Adds `gem "<name>", path: "vendor/submodules/<name>"` to the host app's own `Gemfile` (via
|
|
273
293
|
Thor's own `gem` action) — skipped, with a warning, if the Gemfile already declares a gem with
|
|
@@ -280,10 +300,7 @@ with `--non-interactive`) for the same five fields `createATOM.js` always has, t
|
|
|
280
300
|
the exact same `THECORE_SAMPLES_SOURCE` override mechanism the App template's own asset fetch
|
|
281
301
|
already established (`ENV["THECORE_SAMPLES_SOURCE"]`, defaulting to `thecore`'s `master`
|
|
282
302
|
branch; http(s) fetched over the network, anything else read as a local directory; fails fast
|
|
283
|
-
with a clear message naming the file/source/error on failure).
|
|
284
|
-
`CLAUDE.md`/`.gitlab-ci.yml` fetches, this 404s against the real default URL until `thecore`'s
|
|
285
|
-
`master` actually carries the commit that added `samples/ATOM_CLAUDE.md` — see the caveat
|
|
286
|
-
above.
|
|
303
|
+
with a clear message naming the file/source/error on failure).
|
|
287
304
|
|
|
288
305
|
### `rails generate thecore:collection_action NAME`
|
|
289
306
|
|
|
@@ -375,16 +392,20 @@ files that bootstrap step created, by design. See
|
|
|
375
392
|
for the full design and why the two stay separate).
|
|
376
393
|
|
|
377
394
|
- **Core Gemfile stack, active** — `devise`, `cancancan`, `rails_admin`, `sassc-rails`,
|
|
378
|
-
`model_driven_api` (
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
- **
|
|
383
|
-
`
|
|
384
|
-
`
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
`
|
|
395
|
+
`model_driven_api` (`>= 3.13.1`), `thecore_ui_rails_admin` (`>= 3.8.7`), `rails-erd`
|
|
396
|
+
(`:development`). `thecore_generators` itself is added too, `group: :development` — so the
|
|
397
|
+
generated app can immediately use every generator/task documented above without a manual
|
|
398
|
+
Gemfile edit first.
|
|
399
|
+
- **Security floors and pins** — `thecore_backend_commons >= 3.10` and `thecore_auth_commons >=
|
|
400
|
+
3.6.3` (transitive, listed for their floor), `rails >= 7.2.4`, `puma >= 7.2.1`, and the pins
|
|
401
|
+
`redis < 6` (Action Cable 7.2) and `connection_pool ~> 2.4` (Sidekiq 7). Each carries its reason
|
|
402
|
+
in a Gemfile comment.
|
|
403
|
+
- **The rest of the generic Thecore ecosystem, commented out** — `thecore_print_commons`,
|
|
404
|
+
`thecore_tcp_debug`, `thecore_download_documents`, `thecore_dataentry_commons`, each with a
|
|
405
|
+
one-line purpose comment — discoverable but off by default, the same "commented but documented"
|
|
406
|
+
philosophy ADR 0005 applies to the devcontainer's `gh`/`glab` CLI mounts below.
|
|
407
|
+
`thecore_settings`, `thecore_background_jobs` and `thecore_ui_commons` are named as already in
|
|
408
|
+
the bundle (dependencies of the gems above), not offered.
|
|
388
409
|
- **`vendor/submodules/`/`vendor/external/`** — created empty (a `.keep` file each), not
|
|
389
410
|
pre-wired with any submodule or gem. Per ADR 0005 these are developer-convenience clone
|
|
390
411
|
locations, not template content.
|
|
@@ -394,11 +415,22 @@ for the full design and why the two stay separate).
|
|
|
394
415
|
CLI config mounts commented out by default), **both** `.gitlab-ci.yml` and
|
|
395
416
|
`.github/workflows/ci.yml` (build/test/lint/deploy, no customer-specific paths — no hosting-
|
|
396
417
|
profile prompt, same git-hosting-agnostic reasoning ADR 0006 established for `thecore:atom`'s
|
|
397
|
-
own dual-CI generation, extended here by ADR 0007/thecore_generators#25),
|
|
398
|
-
|
|
418
|
+
own dual-CI generation, extended here by ADR 0007/thecore_generators#25), the security
|
|
419
|
+
scanning next to them (`.github/workflows/security.yml`, and on GitLab SAST, Secret Detection,
|
|
420
|
+
brakeman, bundler-audit and a `security-summary` job running `script/security_summary.rb`,
|
|
421
|
+
fetched with its test `test/script/security_summary_test.rb`), and `CLAUDE.md`
|
|
422
|
+
(universal sections only, project-specific sections left as TODO placeholders), plus
|
|
423
|
+
`AGENTS.md` (points to `CLAUDE.md`) and `docs/agents/` (issue tracker picked from the git
|
|
424
|
+
remote's host, GitHub or GitLab Issues; triage labels; domain docs). The fetch
|
|
399
425
|
location is one overridable point,
|
|
400
426
|
`ENV["THECORE_SAMPLES_SOURCE"]`, defaulting to the raw GitHub URL for `thecore`'s `samples/`
|
|
401
427
|
on `master` (`thecore`'s actual default branch).
|
|
428
|
+
- **Test-database rule** — the generated `test/test_helper.rb` replaces whatever database
|
|
429
|
+
`DATABASE_URL` names with `<app>_test` before the app boots. The devcontainer's `DATABASE_URL`
|
|
430
|
+
points at development, so running tests never touches development data.
|
|
431
|
+
- **No root `Dockerfile`** — the `Dockerfile` and `bin/docker-entrypoint` that `rails new` 7.2
|
|
432
|
+
generates are removed, so the Thecore build script (`app-compile.sh` in `thecore_devcontainer`)
|
|
433
|
+
builds the app with the Thecore Dockerfile instead of Rails' own. `.dockerignore` is kept.
|
|
402
434
|
- **The standard installer chain** (`devise:install`, `rails_admin:install`, `active_storage:
|
|
403
435
|
install`, `action_text:install`, `action_mailbox:install`, `cancan:ability`, `erd:install`,
|
|
404
436
|
each preceded by the necessary `bundle install`) is genuinely optional, gated behind an
|
|
@@ -433,17 +465,20 @@ git-based dependencies — see the Gemfile's comment — purely so
|
|
|
433
465
|
`test/generators/thecore/model_generator_default_concern_behavior_test.rb` can prove the
|
|
434
466
|
no-concern default actually works at runtime, not just that no file was written.
|
|
435
467
|
|
|
468
|
+
`test/dummy` runs on PostgreSQL only (never SQLite). Create its test database once, then run
|
|
469
|
+
the suite:
|
|
470
|
+
|
|
436
471
|
```bash
|
|
437
472
|
bundle install
|
|
473
|
+
(cd test/dummy && RAILS_ENV=test bin/rails db:create)
|
|
438
474
|
bundle exec rake test
|
|
439
475
|
```
|
|
440
476
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
```
|
|
477
|
+
Connection settings come from `PGHOST`/`PGPORT`/`PGUSER`/`PGPASSWORD` (defaults
|
|
478
|
+
`db`/`5432`/`postgres`/`postgres`). If `DATABASE_URL` is set to a PostgreSQL URL (e.g. inside the
|
|
479
|
+
Thecore devcontainer), `test/dummy/config/boot.rb` keeps its server/credentials but always
|
|
480
|
+
swaps the database name to `thecore_generators_<RAILS_ENV>`, so tests never touch the host
|
|
481
|
+
app's database — no need to unset it.
|
|
447
482
|
|
|
448
483
|
`bundle exec rake` alone runs the same suite (`test` is the default Rake task).
|
|
449
484
|
|
|
@@ -460,8 +495,8 @@ The host backend app's own `Gemfile` (`:development` group) and the
|
|
|
460
495
|
`addModel`/`addMigration` commands both depend on this gem being present to get Thecore-aware
|
|
461
496
|
`rails generate` behavior — the extension actually checks for it and offers to add it
|
|
462
497
|
automatically if it's missing, since without it `rails generate model`/`migration` still "work"
|
|
463
|
-
but silently skip every convention described above. See `
|
|
464
|
-
|
|
498
|
+
but silently skip every convention described above. See `docs/agents/consumers.md`
|
|
499
|
+
for detail.
|
|
465
500
|
|
|
466
501
|
## Releasing
|
|
467
502
|
|
|
@@ -49,6 +49,11 @@ module Thecore
|
|
|
49
49
|
"(only consulted with --non-interactive; interactively this is its " \
|
|
50
50
|
"own yes/no prompt, default yes)"
|
|
51
51
|
|
|
52
|
+
class_option :gem_host, type: :string, default: "rubygems.org",
|
|
53
|
+
desc: "Where the ATOM's gem is published: rubygems.org (the default, as for the base " \
|
|
54
|
+
"thecore_* gems) or a private gem server's host name (e.g. gems.example.com). Sets the " \
|
|
55
|
+
"gemspec's allowed_push_host and the GitLab CI's push target to match"
|
|
56
|
+
|
|
52
57
|
source_root File.expand_path("templates", __dir__)
|
|
53
58
|
|
|
54
59
|
# Validated the same way as createATOM.js's own six prompts: every field must
|
|
@@ -66,6 +71,11 @@ module Thecore
|
|
|
66
71
|
# versions) — not createATOM.js's stale "~> 3.1"/"~> 3.2".
|
|
67
72
|
MODEL_DRIVEN_API_VERSION = "~> 3.9"
|
|
68
73
|
THECORE_UI_RAILS_ADMIN_VERSION = "~> 3.8"
|
|
74
|
+
MINITEST_VERSION = "~> 5.25"
|
|
75
|
+
# Thecore 3 hosts run Rails 7.2. The ATOM commits no lockfile, so without this its own bundle
|
|
76
|
+
# (with --skip-api-admin-deps nothing else holds Rails back) resolves the newest Rails.
|
|
77
|
+
RAILS_VERSION = "~> 7.2"
|
|
78
|
+
GEM_HOST_PATTERN = /\A[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:\d+)?\z/i
|
|
69
79
|
|
|
70
80
|
# Faithful port of templates/createATOM/after_initialize.rb /
|
|
71
81
|
# templates/createATOM/assets.rb in thecore_code_extension — static content,
|
|
@@ -100,7 +110,10 @@ module Thecore
|
|
|
100
110
|
# close to the original's structure as the fix allows.
|
|
101
111
|
GEMPUSH_YML_CONTENT = <<~YAML
|
|
102
112
|
name: Ruby Gem
|
|
103
|
-
on:
|
|
113
|
+
on:
|
|
114
|
+
push:
|
|
115
|
+
branches:
|
|
116
|
+
- release/3
|
|
104
117
|
jobs:
|
|
105
118
|
build:
|
|
106
119
|
name: Build + Publish
|
|
@@ -124,6 +137,9 @@ module Thecore
|
|
|
124
137
|
version=$(grep -oP 'VERSION = "\\K[^"]+' lib/*/version.rb | awk -F'.' '{print $1"."$2"."$3}')
|
|
125
138
|
git tag -a $version -m "Version $version"
|
|
126
139
|
git push --tags
|
|
140
|
+
YAML
|
|
141
|
+
|
|
142
|
+
GEMPUSH_RUBYGEMS_STEP = <<~YAML
|
|
127
143
|
- name: Publish to RubyGems
|
|
128
144
|
if: env.version_exists == 'false'
|
|
129
145
|
env:
|
|
@@ -137,6 +153,46 @@ module Thecore
|
|
|
137
153
|
gem push *.gem
|
|
138
154
|
YAML
|
|
139
155
|
|
|
156
|
+
# --gem-host other than RubyGems: the gemspec's allowed_push_host names that host, so
|
|
157
|
+
# pushing to RubyGems would be rejected. `gem push --host` reads the key from
|
|
158
|
+
# GEM_HOST_API_KEY, here the GEMS_REPO_CREDENTIALS repository secret (the same name as
|
|
159
|
+
# the GitLab CI variable).
|
|
160
|
+
GEMPUSH_PRIVATE_HOST_STEP = <<~YAML
|
|
161
|
+
# Needs the GEMS_REPO_CREDENTIALS repository secret: the API key of %<url>s.
|
|
162
|
+
- name: Publish to %<host>s
|
|
163
|
+
if: env.version_exists == 'false'
|
|
164
|
+
env:
|
|
165
|
+
GEM_HOST_API_KEY: ${{secrets.GEMS_REPO_CREDENTIALS}}
|
|
166
|
+
run: |
|
|
167
|
+
gem build *.gemspec
|
|
168
|
+
gem push --host %<url>s *.gem
|
|
169
|
+
YAML
|
|
170
|
+
|
|
171
|
+
GITLAB_CI_HEADER = <<~YAML
|
|
172
|
+
# Publish: build_gem builds and pushes the gem only when lib/*/version.rb changes (see
|
|
173
|
+
# CLAUDE.md). Security: SAST and Secret Detection report only; security-summary lists their
|
|
174
|
+
# findings and turns orange when there are any. CVEs in the dependencies are checked by the
|
|
175
|
+
# host app's bundler-audit, since this gem commits no Gemfile.lock.
|
|
176
|
+
YAML
|
|
177
|
+
|
|
178
|
+
DUMMY_ABILITY_CONTENT = <<~RUBY
|
|
179
|
+
# The host app's Ability, which the Thecore engines reference. Permissions come from
|
|
180
|
+
# thecore_auth_commons' Role/Permission system, so this stays empty, as in a host app.
|
|
181
|
+
class Ability
|
|
182
|
+
include CanCan::Ability
|
|
183
|
+
|
|
184
|
+
def initialize(user); end
|
|
185
|
+
end
|
|
186
|
+
RUBY
|
|
187
|
+
|
|
188
|
+
DUMMY_DEVISE_CONTENT = <<~RUBY
|
|
189
|
+
Devise.setup do |config|
|
|
190
|
+
config.mailer_sender = "please-change-me@example.com"
|
|
191
|
+
require "devise/orm/active_record"
|
|
192
|
+
config.stretches = Rails.env.test? ? 1 : 12
|
|
193
|
+
end
|
|
194
|
+
RUBY
|
|
195
|
+
|
|
140
196
|
SCAFFOLD_DIRECTORIES = %w[
|
|
141
197
|
db/migrate
|
|
142
198
|
app/models/concerns/api
|
|
@@ -194,6 +250,14 @@ module Thecore
|
|
|
194
250
|
"really mean to regenerate it."
|
|
195
251
|
end
|
|
196
252
|
|
|
253
|
+
def validate_gem_host!
|
|
254
|
+
return if gem_host.match?(GEM_HOST_PATTERN)
|
|
255
|
+
|
|
256
|
+
raise Thor::Error,
|
|
257
|
+
"--gem-host=#{options[:gem_host]} is not a gem server host name - pass only the host " \
|
|
258
|
+
"(e.g. gems.example.com), or leave it out to publish on rubygems.org."
|
|
259
|
+
end
|
|
260
|
+
|
|
197
261
|
def validate_non_interactive_options!
|
|
198
262
|
return unless effectively_non_interactive?
|
|
199
263
|
|
|
@@ -235,14 +299,65 @@ module Thecore
|
|
|
235
299
|
# is Shellwords-escaped even though #validate_atom_name! already restricts it
|
|
236
300
|
# to a shell-safe character set - defense in depth, matching the same care
|
|
237
301
|
# #git_init_and_commit already takes with the free-text @author/@email.
|
|
302
|
+
#
|
|
303
|
+
# Two flags go beyond createATOM.js (thecore_devcontainer#15): `--database=postgresql`,
|
|
304
|
+
# because PostgreSQL is the only database Thecore targets and an ATOM's
|
|
305
|
+
# Postgres-specific code must be tested on it (the default dummy app is SQLite); and
|
|
306
|
+
# `--skip-ci`, because Thecore writes its own CI (#create_ci_files) and a second,
|
|
307
|
+
# SQLite-based GitHub workflow plus dependabot.yml would be a pipeline nobody maintains.
|
|
238
308
|
def create_rails_engine
|
|
239
309
|
inside("vendor/submodules") do
|
|
240
310
|
run("bundle exec rails plugin new #{Shellwords.escape(file_name)} " \
|
|
241
|
-
"-fG --skip-gemfile-entry --skip-hotwire --full",
|
|
311
|
+
"-fG --skip-gemfile-entry --skip-hotwire --full --database=postgresql --skip-ci",
|
|
242
312
|
abort_on_failure: true)
|
|
243
313
|
end
|
|
244
314
|
end
|
|
245
315
|
|
|
316
|
+
# The dummy app's database.yml, the pilot ATOM's (mytask) shape: the server comes from
|
|
317
|
+
# the PG* variables (defaulting to the devcontainer's `db` service), the database names
|
|
318
|
+
# are the ATOM's own. Rails' postgresql template names them `dummy_*` and sets no host.
|
|
319
|
+
def configure_dummy_database
|
|
320
|
+
create_file File.join(atom_root, "test/dummy/config/database.yml"), dummy_database_yml, force: true
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# The test-database rule. The devcontainer exports a global DATABASE_URL pointing at the
|
|
324
|
+
# host app's development database, and DATABASE_URL wins over database.yml: without
|
|
325
|
+
# this, the dummy app's schema load (force: :cascade) or db:test:prepare (drop + create)
|
|
326
|
+
# would wipe the host app's development data. It lives in the dummy's boot.rb, not in
|
|
327
|
+
# test/test_helper.rb, so every entry point is covered (the test helper, which sets
|
|
328
|
+
# RAILS_ENV=test before booting, bin/rails db:*, the db:test:prepare subprocess Rails
|
|
329
|
+
# spawns for a pending schema) - same place as in the pilot's own ATOMs. Same URI rule as
|
|
330
|
+
# the App template's test helper: a regex on the path would take a server-only URL's host
|
|
331
|
+
# for the database name.
|
|
332
|
+
def force_atom_database_under_database_url
|
|
333
|
+
append_to_file File.join(atom_root, "test/dummy/config/boot.rb"), <<~RUBY
|
|
334
|
+
|
|
335
|
+
# PostgreSQL is the only database target. DATABASE_URL overrides database.yml, and the
|
|
336
|
+
# devcontainer points it at the host app's development database, which this dummy app's
|
|
337
|
+
# schema load or db:test:prepare would clobber. Keep DATABASE_URL's server/credentials,
|
|
338
|
+
# but always use this ATOM's own per-environment database (#{file_name}_test for tests),
|
|
339
|
+
# replacing the one the URL names or adding it when the URL names only the server.
|
|
340
|
+
if ENV["DATABASE_URL"].to_s.start_with?("postgres")
|
|
341
|
+
require "uri"
|
|
342
|
+
atom_database_url = URI.parse(ENV["DATABASE_URL"])
|
|
343
|
+
atom_database_url.path = "/#{file_name}_\#{ENV.fetch("RAILS_ENV", "development")}"
|
|
344
|
+
ENV["DATABASE_URL"] = atom_database_url.to_s
|
|
345
|
+
end
|
|
346
|
+
RUBY
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# The host-app pieces the Thecore engines expect, which a `rails plugin new` dummy lacks:
|
|
350
|
+
# an `Ability` class (the App template gets it from `cancan:ability`) and Devise's ORM hook
|
|
351
|
+
# (`devise:install`), without which thecore_auth_commons' `User` hits `undefined method
|
|
352
|
+
# devise` at boot. Same files as the pilot ATOM's (mytask) dummy. Only with the API/Admin
|
|
353
|
+
# dependencies: without them neither CanCan nor Devise is in the bundle.
|
|
354
|
+
def configure_dummy_host_app
|
|
355
|
+
return unless @include_api_admin_deps
|
|
356
|
+
|
|
357
|
+
create_file File.join(atom_root, "test/dummy/app/models/ability.rb"), DUMMY_ABILITY_CONTENT
|
|
358
|
+
create_file File.join(atom_root, "test/dummy/config/initializers/devise.rb"), DUMMY_DEVISE_CONTENT
|
|
359
|
+
end
|
|
360
|
+
|
|
246
361
|
# #create_file already `mkdir_p`s its own parent directory, so a separate
|
|
247
362
|
# #empty_directory call per entry would just be redundant work (and, for the
|
|
248
363
|
# 3 of these 12 that #create_scaffold_files/#create_locale_files/
|
|
@@ -256,7 +371,10 @@ module Thecore
|
|
|
256
371
|
create_file File.join(atom_root, "config/initializers/add_to_db_migration.rb"),
|
|
257
372
|
"Rails.application.config.paths['db/migrate'] << File.expand_path(\"../../db/migrate\", __dir__)\n"
|
|
258
373
|
create_file File.join(atom_root, "config/initializers/assets.rb"), ASSETS_CONTENT
|
|
259
|
-
|
|
374
|
+
# CanCan comes with the API/Admin dependencies (model_driven_api -> thecore_auth_commons ->
|
|
375
|
+
# cancancan): without them `include CanCan::Ability` raises NameError at boot, and an ATOM
|
|
376
|
+
# outside the auth stack has no abilities to declare.
|
|
377
|
+
template "abilities.rb.tt", File.join(atom_root, "config/initializers/abilities.rb") if @include_api_admin_deps
|
|
260
378
|
template "seeds.rb.tt", File.join(atom_root, "db/seeds.rb")
|
|
261
379
|
end
|
|
262
380
|
|
|
@@ -271,32 +389,42 @@ module Thecore
|
|
|
271
389
|
create_file File.join(atom_root, "config/locales/it.yml"), "it:\n"
|
|
272
390
|
end
|
|
273
391
|
|
|
392
|
+
# The real ATOMs' publish CI. GitHub (base gems): gempush.yml publishes from release/3 only,
|
|
393
|
+
# to RubyGems, or with --gem-host to that host (#gempush_yml). GitLab (spot gems, mytask's .gitlab-ci.yml): build_gem runs
|
|
394
|
+
# gem-compile.sh only when lib/*/version.rb changes, never on a tag. gem-compile.sh pushes
|
|
395
|
+
# to GITLAB_GEM_REPO_TARGET, or to RubyGems when it's unset, so the variable is written only
|
|
396
|
+
# for a private gem host: an "https://${GEM_HOST}/" with an empty variable would be
|
|
397
|
+
# "https:///", which is set. SAST and Secret Detection report only; on GitLab CE they stay
|
|
398
|
+
# green whatever they find, so security-summary runs script/security_summary.rb (fetched
|
|
399
|
+
# from thecore's samples by #fetch_security_summary) on their reports.
|
|
274
400
|
def create_ci_files
|
|
275
|
-
create_file File.join(atom_root, ".github/workflows/gempush.yml"),
|
|
401
|
+
create_file File.join(atom_root, ".github/workflows/gempush.yml"), gempush_yml
|
|
402
|
+
create_file File.join(atom_root, ".gitlab-ci.yml"), GITLAB_CI_HEADER + gitlab_ci.to_yaml.delete_prefix("---\n")
|
|
403
|
+
end
|
|
276
404
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
"
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
"GEM_HOST_API_KEY" => '${GEMS_REPO_CREDENTIALS}',
|
|
284
|
-
},
|
|
285
|
-
"stages" => %w[build release],
|
|
286
|
-
"build_gem" => {
|
|
287
|
-
"rules" => [{ "if" => "$CI_COMMIT_TAG", "when" => "never" }, { "when" => "always" }],
|
|
288
|
-
"stage" => "build",
|
|
289
|
-
"script" => ["/usr/bin/gem-compile.sh"],
|
|
290
|
-
},
|
|
291
|
-
}
|
|
292
|
-
create_file File.join(atom_root, ".gitlab-ci.yml"), gitlab_ci.to_yaml
|
|
405
|
+
def fetch_security_summary
|
|
406
|
+
%w[script/security_summary.rb test/script/security_summary_test.rb].each do |file|
|
|
407
|
+
Thecore::Generators::SampleFetcher.fetch_thecore_sample(
|
|
408
|
+
self, file, File.join(atom_root, file), label: "the thecore:atom generator"
|
|
409
|
+
)
|
|
410
|
+
end
|
|
293
411
|
end
|
|
294
412
|
|
|
295
413
|
def setup_gemfile
|
|
296
|
-
|
|
414
|
+
# `rails plugin new --database=postgresql` already declares pg; add it only if a
|
|
415
|
+
# future Rails template stops doing so (Bundler rejects a gem declared twice).
|
|
416
|
+
gemfile_path = File.join(atom_root, "Gemfile")
|
|
417
|
+
has_pg = File.read(File.join(destination_root, gemfile_path)).match?(/^\s*gem\s+["']pg["']/)
|
|
418
|
+
gemfile_addition = +"\n"
|
|
419
|
+
gemfile_addition << "gem 'pg'\n" unless has_pg
|
|
420
|
+
# Same pin as this gem's own Gemfile: Rails 7.2's test runner breaks on Minitest 6
|
|
421
|
+
# ("wrong number of arguments"). Recent 7.2 releases cap it themselves, but nothing else
|
|
422
|
+
# in the ATOM's lockfile-less bundle does (the --skip-api-admin-deps variant even floats
|
|
423
|
+
# to the newest Rails, where 5.x works too: checked on Rails 8.1).
|
|
424
|
+
gemfile_addition << "gem 'minitest', '#{MINITEST_VERSION}'\n"
|
|
297
425
|
gemfile_addition << "gem 'model_driven_api', '#{MODEL_DRIVEN_API_VERSION}'\n" \
|
|
298
426
|
"gem 'thecore_ui_rails_admin', '#{THECORE_UI_RAILS_ADMIN_VERSION}'\n" if @include_api_admin_deps
|
|
299
|
-
append_to_file
|
|
427
|
+
append_to_file gemfile_path, gemfile_addition
|
|
300
428
|
|
|
301
429
|
return unless @include_api_admin_deps
|
|
302
430
|
|
|
@@ -333,12 +461,13 @@ module Thecore
|
|
|
333
461
|
content = content.sub(/^\s*spec\.homepage\s*=.*$/, " spec.homepage = #{@url.to_s.inspect}")
|
|
334
462
|
content = content.sub(/^\s*spec\.summary\s*=.*$/, " spec.summary = #{@summary.to_s.inspect}")
|
|
335
463
|
content = content.sub(/^\s*spec\.description\s*=.*$/, " spec.description = #{@description.to_s.inspect}")
|
|
464
|
+
content = content.sub(/^(\s*spec\.add_dependency\s+["']rails["']).*$/) { "#{Regexp.last_match(1)}, #{RAILS_VERSION.inspect}" }
|
|
336
465
|
content = content.sub(/^\s*spec\.metadata\["allowed_push_host"\]\s*=.*$/,
|
|
337
|
-
|
|
466
|
+
" spec.metadata[\"allowed_push_host\"] = \"https://#{gem_host}\"")
|
|
338
467
|
content = content.sub(/^\s*spec\.metadata\["source_code_uri"\]\s*=.*$/,
|
|
339
468
|
' spec.metadata["source_code_uri"] = spec.homepage')
|
|
340
469
|
content = content.sub(/^\s*spec\.metadata\["changelog_uri"\]\s*=.*$/,
|
|
341
|
-
' spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/
|
|
470
|
+
' spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/release/3/CHANGELOG.md"')
|
|
342
471
|
|
|
343
472
|
create_file gemspec_path, content, force: true
|
|
344
473
|
end
|
|
@@ -361,14 +490,6 @@ module Thecore
|
|
|
361
490
|
# gemspec edits already succeeded) - #ensure_atom_does_not_already_exist!
|
|
362
491
|
# then refuses a same-named retry until it's removed by hand; the abort
|
|
363
492
|
# message says so.
|
|
364
|
-
#
|
|
365
|
-
# NOTE: like the App template's own fetch of thecore/samples/CLAUDE.md
|
|
366
|
-
# before it, this 404s against the real default GitHub URL until thecore's
|
|
367
|
-
# `master` actually carries the commit that added samples/ATOM_CLAUDE.md
|
|
368
|
-
# (thecore#18) - as of this gem's 3.11.0 release that commit exists only in
|
|
369
|
-
# a local `thecore` checkout, not yet pushed. Same operational sequencing
|
|
370
|
-
# note as the App template's own CLAUDE.md section: push `thecore` before
|
|
371
|
-
# relying on the default in production.
|
|
372
493
|
def fetch_claude_md
|
|
373
494
|
Thecore::Generators::SampleFetcher.fetch_thecore_sample(
|
|
374
495
|
self, "ATOM_CLAUDE.md", File.join(atom_root, "CLAUDE.md"), label: "the thecore:atom generator"
|
|
@@ -388,7 +509,7 @@ module Thecore
|
|
|
388
509
|
def git_init_and_commit
|
|
389
510
|
atom_path = File.join(destination_root, atom_root)
|
|
390
511
|
committed = inside(atom_root) do
|
|
391
|
-
run("git init -q -b
|
|
512
|
+
run("git init -q -b release/3", abort_on_failure: true)
|
|
392
513
|
run("git add -A", abort_on_failure: true)
|
|
393
514
|
# Not abort_on_failure: a freshly-generated tree always has something to
|
|
394
515
|
# commit in normal use, but `git commit` failing (e.g. "nothing to
|
|
@@ -408,8 +529,15 @@ module Thecore
|
|
|
408
529
|
say_status :next_steps, <<~MSG.strip, :yellow
|
|
409
530
|
#{file_name} is git-initialized locally with one commit, but has no remote yet. To finish wiring it in:
|
|
410
531
|
1. Create a repository for it on the git host of your choice (GitHub, GitLab, ...)
|
|
411
|
-
2. cd #{atom_path} && git remote add origin <remote-url> && git push -u origin
|
|
412
|
-
3. From this app's root: git submodule add <remote-url> vendor/submodules/#{file_name}
|
|
532
|
+
2. cd #{atom_path} && git remote add origin <remote-url> && git push -u origin release/3
|
|
533
|
+
3. From this app's root: git submodule add -b release/3 <remote-url> vendor/submodules/#{file_name}
|
|
534
|
+
Until the gem is published, this app's Gemfile uses it from the submodule:
|
|
535
|
+
gem "#{file_name}", path: "vendor/submodules/#{file_name}"
|
|
536
|
+
Once published (bump lib/#{file_name}/version.rb and push to release/3; the CI publishes it), switch to the published gem:
|
|
537
|
+
4. Replace that line with gem "#{file_name}", "~> <major.minor>"#{published_gem_location}
|
|
538
|
+
5. bundle update #{file_name} --conservative, then commit Gemfile.lock together with the submodule pointer
|
|
539
|
+
Its own tests run from its directory, on its own test database: cd #{atom_path} && bundle install && bin/rails db:create && bin/rails test
|
|
540
|
+
From then on every change follows the same loop: edit and test in vendor/submodules/#{file_name}, bump the version, push to release/3, wait for the gem server, bundle update #{file_name} --conservative, commit Gemfile.lock + the submodule pointer.
|
|
413
541
|
MSG
|
|
414
542
|
else
|
|
415
543
|
say_status :warning, <<~MSG.strip, :red
|
|
@@ -443,10 +571,99 @@ module Thecore
|
|
|
443
571
|
|
|
444
572
|
private
|
|
445
573
|
|
|
574
|
+
def gitlab_ci
|
|
575
|
+
variables = { "GITLAB_EMAIL" => @email, "GITLAB_USER_NAME" => @author }
|
|
576
|
+
variables["GITLAB_GEM_REPO_TARGET"] = "https://#{gem_host}/" unless rubygems_host?
|
|
577
|
+
variables["GEM_HOST_API_KEY"] = "${GEMS_REPO_CREDENTIALS}"
|
|
578
|
+
{
|
|
579
|
+
"image" => "gabrieletassoni/vscode-devcontainers-thecore:3",
|
|
580
|
+
"variables" => variables,
|
|
581
|
+
"stages" => %w[test build],
|
|
582
|
+
"build_gem" => {
|
|
583
|
+
"rules" => [
|
|
584
|
+
{ "if" => "$CI_COMMIT_TAG", "when" => "never" },
|
|
585
|
+
{ "changes" => ["lib/*/version.rb"], "when" => "on_success" },
|
|
586
|
+
{ "when" => "never" },
|
|
587
|
+
],
|
|
588
|
+
"stage" => "build",
|
|
589
|
+
"script" => ["/usr/bin/gem-compile.sh"],
|
|
590
|
+
},
|
|
591
|
+
"include" => [
|
|
592
|
+
{ "template" => "Jobs/SAST.gitlab-ci.yml" },
|
|
593
|
+
{ "template" => "Jobs/Secret-Detection.gitlab-ci.yml" },
|
|
594
|
+
],
|
|
595
|
+
"semgrep-sast" => {
|
|
596
|
+
"needs" => [],
|
|
597
|
+
"variables" => { "SAST_EXCLUDED_PATHS" => "spec, test, tests, tmp, vendor, node_modules" },
|
|
598
|
+
},
|
|
599
|
+
"secret_detection" => { "needs" => [] },
|
|
600
|
+
"security-summary" => {
|
|
601
|
+
"stage" => "test",
|
|
602
|
+
"needs" => [
|
|
603
|
+
{ "job" => "semgrep-sast", "optional" => true },
|
|
604
|
+
{ "job" => "secret_detection", "optional" => true },
|
|
605
|
+
],
|
|
606
|
+
"allow_failure" => true,
|
|
607
|
+
"rules" => [{ "if" => '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH' }],
|
|
608
|
+
"script" => ["ruby script/security_summary.rb gl-sast-report.json gl-secret-detection-report.json"],
|
|
609
|
+
},
|
|
610
|
+
}
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
# --gem-host, tolerating a scheme and a trailing slash (a URL copied from a browser).
|
|
614
|
+
def gem_host
|
|
615
|
+
options[:gem_host].to_s.strip.sub(%r{\Ahttps?://}i, "").chomp("/").downcase
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def published_gem_location
|
|
619
|
+
return "" if rubygems_host?
|
|
620
|
+
|
|
621
|
+
%( inside the `source "https://#{gem_host}/" do ... end` block)
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
# The GitHub publish workflow pushes to the same host the gemspec's allowed_push_host names.
|
|
625
|
+
def gempush_yml
|
|
626
|
+
step = rubygems_host? ? GEMPUSH_RUBYGEMS_STEP : format(GEMPUSH_PRIVATE_HOST_STEP, host: gem_host, url: "https://#{gem_host}")
|
|
627
|
+
# The step is a heredoc of its own: indent it to the steps list's level.
|
|
628
|
+
GEMPUSH_YML_CONTENT + step.gsub(/^/, " ")
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
def rubygems_host?
|
|
632
|
+
gem_host == "rubygems.org"
|
|
633
|
+
end
|
|
634
|
+
|
|
446
635
|
def atom_root
|
|
447
636
|
File.join("vendor", "submodules", file_name)
|
|
448
637
|
end
|
|
449
638
|
|
|
639
|
+
def dummy_database_yml
|
|
640
|
+
<<~YAML
|
|
641
|
+
# PostgreSQL only: Thecore targets PostgreSQL exclusively, so this dummy app does too
|
|
642
|
+
# (never SQLite). When DATABASE_URL is set (e.g. in the devcontainer), config/boot.rb
|
|
643
|
+
# keeps only its server/credentials and forces #{file_name}_<RAILS_ENV> as the database.
|
|
644
|
+
default: &default
|
|
645
|
+
adapter: postgresql
|
|
646
|
+
encoding: unicode
|
|
647
|
+
host: <%= ENV.fetch("PGHOST", "db") %>
|
|
648
|
+
port: <%= ENV.fetch("PGPORT", 5432) %>
|
|
649
|
+
username: <%= ENV.fetch("PGUSER", "postgres") %>
|
|
650
|
+
password: <%= ENV.fetch("PGPASSWORD", "postgres") %>
|
|
651
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
|
652
|
+
|
|
653
|
+
development:
|
|
654
|
+
<<: *default
|
|
655
|
+
database: #{file_name}_development
|
|
656
|
+
|
|
657
|
+
test:
|
|
658
|
+
<<: *default
|
|
659
|
+
database: #{file_name}_test
|
|
660
|
+
|
|
661
|
+
production:
|
|
662
|
+
<<: *default
|
|
663
|
+
database: #{file_name}_production
|
|
664
|
+
YAML
|
|
665
|
+
end
|
|
666
|
+
|
|
450
667
|
# True whenever prompting for input isn't viable: --non-interactive was
|
|
451
668
|
# passed explicitly, or (via the shared Thecore::Generators::TtyDetection,
|
|
452
669
|
# also used by AssociationWiring's own `interactive_association_prompt?`)
|
|
@@ -37,7 +37,7 @@ module Thecore
|
|
|
37
37
|
atom_name = atom_name.to_s.strip
|
|
38
38
|
return resolve_named_atom(app_root, atom_name) unless atom_name.empty?
|
|
39
39
|
|
|
40
|
-
resolve_cwd_atom(cwd)
|
|
40
|
+
resolve_cwd_atom(cwd, app_root)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# Walks up from `dir` until the immediate parent directory is
|
|
@@ -137,9 +137,21 @@ module Thecore
|
|
|
137
137
|
"(expected a #{atom_name}.gemspec or #{atom_name.tr('-', '_')}.gemspec inside it)."
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
# A cwd-detected ATOM only counts when it belongs to the app being
|
|
141
|
+
# generated into: it must be `app_root` itself (e.g. an engine's own
|
|
142
|
+
# bin/rails, whose destination_root is already the ATOM) or live
|
|
143
|
+
# inside it. For a real `rails generate` the app root is always an
|
|
144
|
+
# ancestor of cwd, so this never changes the normal outcome — but
|
|
145
|
+
# when `app_root` itself sits *inside* some `vendor/submodules/<x>/`
|
|
146
|
+
# tree (an ATOM's own test/dummy app, or a gem checked out as a
|
|
147
|
+
# submodule of a host app and running its own generator tests with
|
|
148
|
+
# a tmp destination_root), walking up from cwd would otherwise find
|
|
149
|
+
# that enclosing <x> and redirect every file *out of* app_root into
|
|
150
|
+
# it. See docs/agents/model-and-migration-generators.md, WorkspaceContext.
|
|
151
|
+
def resolve_cwd_atom(cwd, app_root)
|
|
141
152
|
candidate = atom_root_of(cwd)
|
|
142
153
|
return nil unless candidate
|
|
154
|
+
return nil unless within_app_root?(candidate, app_root)
|
|
143
155
|
|
|
144
156
|
unless valid_atom_dir?(candidate)
|
|
145
157
|
raise Thor::Error,
|
|
@@ -149,6 +161,13 @@ module Thecore
|
|
|
149
161
|
|
|
150
162
|
candidate
|
|
151
163
|
end
|
|
164
|
+
|
|
165
|
+
def within_app_root?(candidate, app_root)
|
|
166
|
+
return true if app_root.to_s.empty?
|
|
167
|
+
|
|
168
|
+
root = File.expand_path(app_root.to_s)
|
|
169
|
+
candidate == root || candidate.start_with?("#{root}/")
|
|
170
|
+
end
|
|
152
171
|
end
|
|
153
172
|
end
|
|
154
173
|
end
|
|
@@ -27,37 +27,73 @@ gem "rails_admin"
|
|
|
27
27
|
# this declaration must stay regardless, since sassc-rails needs to be active even
|
|
28
28
|
# when the installer chain below is declined.
|
|
29
29
|
gem "sassc-rails"
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
|
|
31
|
+
# --- Floors and pins ----------------------------------------------------------
|
|
32
|
+
# Each floor is the first release carrying a fix the pilot (mytask-imas) depends on, so
|
|
33
|
+
# a `bundle update --conservative` from an old lock can't stay below it. ADR 0001
|
|
34
|
+
# (thecore repo) only needed model_driven_api >= 3.9.0 / thecore_ui_rails_admin >= 3.8.0
|
|
35
|
+
# (DefaultModuleRegistry); the floors below are higher.
|
|
36
|
+
# - model_driven_api 3.13.1: the generic API no longer instantiates the class named by
|
|
37
|
+
# the request path (any JWT could run `Tempfile.new` through `GET /api/v2/tempfiles`).
|
|
38
|
+
# - thecore_ui_rails_admin 3.8.7: RailsAdmin's User create form answered 500 under
|
|
39
|
+
# Devise 5, which thecore_auth_commons 3.6.3 requires.
|
|
40
|
+
gem "model_driven_api", "~> 3.13", ">= 3.13.1"
|
|
41
|
+
gem "thecore_ui_rails_admin", "~> 3.8", ">= 3.8.7"
|
|
42
|
+
# Both already arrive as dependencies of the two gems above; listed only for their floors.
|
|
43
|
+
# - thecore_backend_commons 3.10.0: no job is retried by default and only the latest
|
|
44
|
+
# failed job is kept (sidekiq-failures set capped at 1), so failing jobs can't fill
|
|
45
|
+
# Redis; THECORE_JOB_RETRIES / THECORE_FAILED_JOBS_KEPT change both per installation.
|
|
46
|
+
# It also carries 3.9.1's ActionCable JWT verification and 3.9.0's roo 3 (rubyzip
|
|
47
|
+
# >= 3.4, CVE-2026-85396).
|
|
48
|
+
# - thecore_auth_commons 3.6.3: OAuth login takes the identity only from OmniAuth's
|
|
49
|
+
# verified data, never from request params (3.6.2: no fixed initial admin password).
|
|
50
|
+
gem "thecore_backend_commons", "~> 3.10"
|
|
51
|
+
gem "thecore_auth_commons", "~> 3.6", ">= 3.6.3"
|
|
52
|
+
# `rails new` already declares rails and puma: their lines are rewritten, since a second
|
|
53
|
+
# `gem` line with a different requirement is a Bundler error.
|
|
54
|
+
# - rails 7.2.4: carries the 7.2.3.1/7.2.3.2 security fixes.
|
|
55
|
+
# - puma 7.2.1: fixes the PROXY protocol v1 CVE-2026-47736/47737.
|
|
56
|
+
gsub_file "Gemfile", /^gem ["']rails["'].*$/, 'gem "rails", "~> 7.2", ">= 7.2.4"'
|
|
57
|
+
gsub_file "Gemfile", /^gem ["']puma["'].*$/, 'gem "puma", ">= 7.2.1"'
|
|
58
|
+
# Pins still needed (checked against rubygems.org on 2026-11-09):
|
|
59
|
+
# - redis < 6: Action Cable 7.2's Redis adapter (production's cable.yml) requires
|
|
60
|
+
# `redis >= 4, < 6` when it loads. redis-namespace (via thecore_background_jobs) only
|
|
61
|
+
# asks for `>= 4`, so a fresh resolve takes redis 6.0.0 and production crashes at boot
|
|
62
|
+
# with a Gem::LoadError.
|
|
63
|
+
# - connection_pool ~> 2.4: connection_pool 3 changed TimedStack#pop and breaks Sidekiq
|
|
64
|
+
# 7's scheduler thread. Sidekiq 7.3.10 caps it below 3 itself, but 7.3.9 and earlier
|
|
65
|
+
# don't, and Bundler can still pick that pair: a fresh resolve of this gem's own dev
|
|
66
|
+
# bundle took sidekiq 7.3.9 with connection_pool 3.0.2 (a fresh app took 7.3.10).
|
|
67
|
+
# thecore_background_jobs keeps `sidekiq ~> 7.0`, so drop this pin once it moves to
|
|
68
|
+
# Sidekiq 8 (which requires connection_pool >= 3).
|
|
69
|
+
gem "redis", "< 6"
|
|
70
|
+
gem "connection_pool", "~> 2.4"
|
|
36
71
|
gem "rails-erd", group: :development
|
|
37
72
|
|
|
38
73
|
# thecore_generators itself is dev-tooling only (it hooks `rails g model`/`migration`,
|
|
39
74
|
# see ADR 0002 in the thecore repo) — never a runtime dependency, so it goes in the
|
|
40
75
|
# :development group. A single-line `group:` option is equivalent to (and simpler
|
|
41
76
|
# than) createApp.js's manual `group :development do ... end` block insertion.
|
|
42
|
-
gem "thecore_generators", "~> 3.
|
|
77
|
+
gem "thecore_generators", "~> 3.13", group: :development
|
|
43
78
|
|
|
44
79
|
# --- Optional ecosystem gems, discoverable but off by default ---------------
|
|
45
80
|
# Same "commented but documented" philosophy as the devcontainer's gh/glab CLI
|
|
46
81
|
# mounts (ADR 0005): each of these publishes to RubyGems.org (see thecore's own
|
|
47
82
|
# CLAUDE.md) but isn't needed by every app, so it starts commented out with a
|
|
48
83
|
# one-line description — uncomment only the ones this project actually needs.
|
|
84
|
+
# The ones already in the bundle as dependencies are named, not offered.
|
|
49
85
|
append_to_file "Gemfile", <<~RUBY
|
|
50
86
|
|
|
87
|
+
# Already in the bundle as dependencies of the gems above, so don't add them:
|
|
88
|
+
# thecore_settings (via thecore_auth_commons)
|
|
89
|
+
# thecore_background_jobs (via thecore_backend_commons)
|
|
90
|
+
# thecore_ui_commons (via thecore_ui_rails_admin)
|
|
91
|
+
|
|
51
92
|
# The rest of the generic Thecore ecosystem — uncomment only what you need.
|
|
52
|
-
# gem "thecore_auth_commons", "~> 3.0" # Role/permission/predicate models and authorization scaffolding
|
|
53
|
-
# gem "thecore_settings", "~> 3.0" # ThecoreSettings key/value configuration store
|
|
54
93
|
# gem "thecore_print_commons", "~> 3.0" # Shared PDF/print generation helpers
|
|
55
|
-
# gem "thecore_background_jobs", "~> 3.0" # Shared background job scheduling helpers
|
|
56
|
-
# gem "thecore_ui_commons", "~> 3.0" # Shared UI helpers/components for the admin frontend
|
|
57
94
|
# gem "thecore_tcp_debug", "~> 3.0" # TCP-level debugging/diagnostics support
|
|
58
95
|
# gem "thecore_download_documents", "~> 3.0" # Document download support
|
|
59
96
|
# gem "thecore_dataentry_commons", "~> 3.0" # Shared data-entry UI helpers
|
|
60
|
-
# gem "thecore_connectors" # Helpers for connecting to external systems/data sources
|
|
61
97
|
RUBY
|
|
62
98
|
|
|
63
99
|
# --- Developer-convenience placeholder directories --------------------------
|
|
@@ -79,6 +115,18 @@ create_file "vendor/external/.keep", <<~TEXT
|
|
|
79
115
|
anything automatically.
|
|
80
116
|
TEXT
|
|
81
117
|
|
|
118
|
+
# --- No root Dockerfile ------------------------------------------------------
|
|
119
|
+
# `rails new` (7.2) writes a Kamal-style root `Dockerfile` plus the
|
|
120
|
+
# `bin/docker-entrypoint` it runs. The Thecore build script (`app-compile.sh` in
|
|
121
|
+
# thecore_devcontainer) prefers a root `Dockerfile` whenever one exists, so keeping
|
|
122
|
+
# Rails' one would make CI build the app with it instead of the Thecore Dockerfile
|
|
123
|
+
# (`/etc/thecore/docker/Dockerfile`), which is what the pilot (mytask-imas) uses.
|
|
124
|
+
# Removed here, not in the extension, so both "Create an App" and a bare
|
|
125
|
+
# `rails new -m` get it. `.dockerignore` is left alone: the Thecore Dockerfile's
|
|
126
|
+
# `ADD .` honours it.
|
|
127
|
+
remove_file "Dockerfile"
|
|
128
|
+
remove_file "bin/docker-entrypoint"
|
|
129
|
+
|
|
82
130
|
# --- Devcontainer / CI / CLAUDE.md assets, from thecore's own samples -------
|
|
83
131
|
# Single source of truth (ADR 0005) — not duplicated inside this gem. The base
|
|
84
132
|
# location is resolved fresh inside `fetch_thecore_sample` on every call, through
|
|
@@ -95,35 +143,19 @@ TEXT
|
|
|
95
143
|
# directory and read directly — this gem's own offline test points it at a
|
|
96
144
|
# fixture instead.
|
|
97
145
|
#
|
|
98
|
-
# NOTE: this default URL only serves real content once `thecore`'s `master`
|
|
99
|
-
# carries the commits that added `samples/CLAUDE.md`/`samples/.gitlab-ci.yml`
|
|
100
|
-
# and brought `samples/devcontainer/` up to date (thecore#14/#15) — as of this
|
|
101
|
-
# gem's own 3.8.0 release those commits exist only in a local checkout, not
|
|
102
|
-
# pushed to `origin/master` yet. Until they're pushed, the default URL 404s for
|
|
103
|
-
# `.gitlab-ci.yml`/`CLAUDE.md`/the two devcontainer scripts and serves stale
|
|
104
|
-
# content for `devcontainer.json`/`docker-compose.yml`. This is an operational
|
|
105
|
-
# sequencing issue (push `thecore` before relying on the default in production),
|
|
106
|
-
# not a defect in this code — but it means `THECORE_SAMPLES_SOURCE` pointed at a
|
|
107
|
-
# local clone of `thecore` is the only way to exercise the real default content
|
|
108
|
-
# today.
|
|
109
|
-
#
|
|
110
146
|
# Every write below is unconditional (`force: true`, no interactive prompt).
|
|
111
|
-
#
|
|
112
|
-
# `
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
# them
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
# `.gitlab-ci.yml`/`CLAUDE.md` don't exist yet in the documented flow either,
|
|
121
|
-
# but stay unconditional too so re-running this template later
|
|
122
|
-
# (`bin/rails app:template`) is a clean overwrite, not a prompt.
|
|
147
|
+
# Inside the documented flow, the separate, prior "Setup Devcontainer" step
|
|
148
|
+
# (`thecore_code_extension/commands/setupDevContainer.js`) has already written the
|
|
149
|
+
# eight `.devcontainer/*` files (ten from the extension release after 3.11.0);
|
|
150
|
+
# replacing them with the samples is the point, not a
|
|
151
|
+
# conflict to ask about. With a bare `rails new -m` (or an older extension release)
|
|
152
|
+
# some or all of them are new files instead, and `force: true` is harmless there.
|
|
153
|
+
# `.gitlab-ci.yml`/`CLAUDE.md` and the agent docs stay unconditional too, so
|
|
154
|
+
# re-running this template later (`bin/rails app:template`) is a clean overwrite,
|
|
155
|
+
# not a prompt.
|
|
123
156
|
#
|
|
124
|
-
# A fetch failure (
|
|
125
|
-
#
|
|
126
|
-
# specific message instead of continuing into a silently half-scaffolded app
|
|
157
|
+
# A fetch failure (a network blip, or `thecore` reorganizing `samples/`) aborts
|
|
158
|
+
# the whole template with a clear, specific message instead of continuing into a silently half-scaffolded app
|
|
127
159
|
# (some `.devcontainer/*` files present, others not, no clear signal pointing
|
|
128
160
|
# back to the real cause) -- the same fail-fast philosophy thecore_generators#17
|
|
129
161
|
# already applies to `bundle_command`/`rails_command` failures in the installer
|
|
@@ -142,22 +174,73 @@ rescue StandardError => e
|
|
|
142
174
|
"-- aborting the app template. Set THECORE_SAMPLES_SOURCE to override the source.")
|
|
143
175
|
end
|
|
144
176
|
|
|
145
|
-
|
|
177
|
+
# `docker-socket-gid.sh` (initializeCommand, on the host) writes the host's
|
|
178
|
+
# docker.sock gid to `.devcontainer/.env` for docker-compose.yml's `group_add`;
|
|
179
|
+
# `.gitignore` keeps that per-host `.env` out of git, since Rails' own
|
|
180
|
+
# `.gitignore` only covers `/.env*` at the root (ADR 0006 in thecore_devcontainer).
|
|
181
|
+
%w[devcontainer.json docker-compose.yml Dockerfile create-db-user.sql link-host-home.sh check-plugins.sh
|
|
182
|
+
heal-stale-containers.sh github-accounts.sh docker-socket-gid.sh .gitignore].each do |file|
|
|
146
183
|
fetch_thecore_sample("devcontainer/#{file}", ".devcontainer/#{file}")
|
|
147
184
|
end
|
|
148
185
|
# `get`/`create_file` only write content, never permissions — the executable bit
|
|
149
|
-
# has to be restored explicitly for the
|
|
186
|
+
# has to be restored explicitly for the five scripts (`thecore/samples/devcontainer/`
|
|
150
187
|
# stores them executable, but that's lost the moment their bytes cross an HTTP
|
|
151
188
|
# fetch or a plain `File.read`).
|
|
152
189
|
chmod ".devcontainer/link-host-home.sh", 0o755
|
|
153
190
|
chmod ".devcontainer/check-plugins.sh", 0o755
|
|
191
|
+
chmod ".devcontainer/heal-stale-containers.sh", 0o755
|
|
192
|
+
chmod ".devcontainer/github-accounts.sh", 0o755
|
|
193
|
+
chmod ".devcontainer/docker-socket-gid.sh", 0o755
|
|
154
194
|
|
|
155
195
|
fetch_thecore_sample(".gitlab-ci.yml", ".gitlab-ci.yml")
|
|
156
196
|
# thecore_generators#25 (ADR 0007): fetched unconditionally, alongside .gitlab-ci.yml above --
|
|
157
197
|
# no hosting-profile prompt, same reasoning ADR 0006 already established for thecore:atom's own
|
|
158
198
|
# dual-CI generation (git hosting is a generic, per-developer choice, not something to ask about).
|
|
159
199
|
fetch_thecore_sample(".github/workflows/ci.yml", ".github/workflows/ci.yml")
|
|
200
|
+
# thecore_devcontainer#9: the pilot's security CI. GitHub's scans (brakeman, bundler-audit, nightly
|
|
201
|
+
# too) are a workflow of their own, so the schedule never builds or deploys; the GitLab ones live in
|
|
202
|
+
# .gitlab-ci.yml above. The GitLab security-summary job runs script/security_summary.rb, fetched
|
|
203
|
+
# with its plain-Minitest test (run by `bin/rails test` with the rest).
|
|
204
|
+
fetch_thecore_sample(".github/workflows/security.yml", ".github/workflows/security.yml")
|
|
205
|
+
fetch_thecore_sample("script/security_summary.rb", "script/security_summary.rb")
|
|
206
|
+
fetch_thecore_sample("test/script/security_summary_test.rb", "test/script/security_summary_test.rb")
|
|
160
207
|
fetch_thecore_sample("CLAUDE.md", "CLAUDE.md")
|
|
208
|
+
# thecore_devcontainer#13: the agent docs CLAUDE.md points to (issue tracker picked from the git
|
|
209
|
+
# remote's host, triage labels, domain docs) and an AGENTS.md that only points to CLAUDE.md, so
|
|
210
|
+
# agents other than Claude Code read the same single source.
|
|
211
|
+
fetch_thecore_sample("AGENTS.md", "AGENTS.md")
|
|
212
|
+
%w[issue-tracker.md triage-labels.md domain.md].each do |doc|
|
|
213
|
+
fetch_thecore_sample("docs/agents/#{doc}", "docs/agents/#{doc}")
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# --- Test database rule (the pilot's, mytask-imas test/test_helper.rb) --------
|
|
217
|
+
# The devcontainer sets one global DATABASE_URL pointing at the development
|
|
218
|
+
# database, and a URL wins over database.yml's per-environment names -- so
|
|
219
|
+
# without this, `rails test` would run (and wipe fixtures' tables) against
|
|
220
|
+
# development. Swapping whatever database the URL names for `<app>_test`, before
|
|
221
|
+
# the app boots, gives tests their own database on the same server. The pilot's
|
|
222
|
+
# version is a regex on the path, which mangles a URL naming only the server (the
|
|
223
|
+
# form the CI samples use, so `db:test:prepare` takes database.yml's test name);
|
|
224
|
+
# URI handles both.
|
|
225
|
+
# Skipped when `rails new --skip-test` generated no test helper.
|
|
226
|
+
if File.exist?(File.join(destination_root, "test/test_helper.rb"))
|
|
227
|
+
insert_into_file "test/test_helper.rb", after: /^ENV\[["']RAILS_ENV["']\] \|\|= ["']test["']\n/ do
|
|
228
|
+
<<~RUBY
|
|
229
|
+
|
|
230
|
+
# DATABASE_URL (set by the devcontainer) names the development database and wins
|
|
231
|
+
# over config/database.yml: replace whatever database it names (or add one, when it
|
|
232
|
+
# names only the server) with the test one, so running tests never touches
|
|
233
|
+
# development data.
|
|
234
|
+
if ENV["DATABASE_URL"]
|
|
235
|
+
require "uri"
|
|
236
|
+
test_database_url = URI.parse(ENV["DATABASE_URL"])
|
|
237
|
+
test_database_url.path = "/#{app_name}_test"
|
|
238
|
+
ENV["DATABASE_URL"] = test_database_url.to_s
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
RUBY
|
|
242
|
+
end
|
|
243
|
+
end
|
|
161
244
|
|
|
162
245
|
# --- Standard installer chain ------------------------------------------------
|
|
163
246
|
# Needs the gems added above actually bundled and installable, i.e. real network
|
|
@@ -349,7 +349,7 @@ module Thecore
|
|
|
349
349
|
# happens to sit inside a `vendor/submodules/<atom>/` tree at the
|
|
350
350
|
# moment `--fix` runs (e.g. invoked via an explicit `bin/rails` path
|
|
351
351
|
# rather than the `rails` executable's own directory walk-up - see
|
|
352
|
-
# WorkspaceContext's `Dir.pwd`-reset gotcha in
|
|
352
|
+
# WorkspaceContext's `Dir.pwd`-reset gotcha in docs/agents/model-and-migration-generators.md),
|
|
353
353
|
# `AtomAware#initialize` would silently redirect the freshly-built
|
|
354
354
|
# generator's `destination_root` into that unrelated ATOM instead of
|
|
355
355
|
# `@app_root`, even though this violation was found in host-app
|