dev_onboarder 0.9.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 +7 -0
- data/CHANGELOG.md +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -0
- data/Rakefile +14 -0
- data/app/controllers/dev_onboarder/setup_controller.rb +15 -0
- data/app/views/dev_onboarder/setup/show.html.erb +61 -0
- data/config/routes.rb +5 -0
- data/exe/dev_onboarder +6 -0
- data/lib/dev_onboarder/cli.rb +119 -0
- data/lib/dev_onboarder/engine.rb +46 -0
- data/lib/dev_onboarder/env_file.rb +25 -0
- data/lib/dev_onboarder/lines.rb +42 -0
- data/lib/dev_onboarder/machine_tools.rb +43 -0
- data/lib/dev_onboarder/overview.rb +54 -0
- data/lib/dev_onboarder/record.rb +51 -0
- data/lib/dev_onboarder/record_location.rb +17 -0
- data/lib/dev_onboarder/requirement.rb +22 -0
- data/lib/dev_onboarder/requirements.rb +67 -0
- data/lib/dev_onboarder/secret_prompt.rb +40 -0
- data/lib/dev_onboarder/secrets.rb +16 -0
- data/lib/dev_onboarder/setup.rb +67 -0
- data/lib/dev_onboarder/shell.rb +24 -0
- data/lib/dev_onboarder/status.rb +33 -0
- data/lib/dev_onboarder/version.rb +5 -0
- data/lib/dev_onboarder.rb +9 -0
- data/the_local/agents/dev_onboarder-develop.md +116 -0
- data/the_local/agents/dev_onboarder-info.md +43 -0
- data/the_local/agents/dev_onboarder-install.md +47 -0
- data/the_local/interface.yml +36 -0
- metadata +77 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a976b60fbd1fdf065d23f456c7e8748e3d9a14431355386c8b7e7b55465af4fc
|
|
4
|
+
data.tar.gz: 7dfbe87e983559d84a811fb9c87dceb0f74c9d1929a082c20310f13969b0a2ce
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8e0b84e69b5b6dbe02339487cefcea0f7a0d95b5c9f3e687d799b19dcac07da0d37d547ef98fe59b9aac924487e78047785c1eb6a0e03d55992d8954fd578025
|
|
7
|
+
data.tar.gz: 8d6503b8bc9d9a4d4a2d177d17979723191a4feb3342da456aeb9181e70f0923498b003feb11c7db54169dc4d547a727b38340bfb13bf22349615ed328009524
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.9.0]
|
|
4
|
+
|
|
5
|
+
- The gem is a the_local provider: a host that runs `the_local install` gets info, install and develop locals for the setup tool.
|
|
6
|
+
|
|
7
|
+
## [0.8.0]
|
|
8
|
+
|
|
9
|
+
- A host adds only the gem and its `Setupfile`, and changes nothing else.
|
|
10
|
+
- A Rails app in development loads `.env` before its own initializers.
|
|
11
|
+
- The setup page is at `/dev_onboarder` in local environments with no route drawn by the app, and uses the app's `ApplicationController`.
|
|
12
|
+
- The setup record is kept inside the clone's git directory, one for each worktree.
|
|
13
|
+
|
|
14
|
+
## [0.7.0]
|
|
15
|
+
|
|
16
|
+
- A failed fix shows what it printed, and a requirement can set a time limit for its fix.
|
|
17
|
+
- An error in the `Setupfile`, a repeated key and a missing `Setupfile` are reported without a stack trace.
|
|
18
|
+
- A setup record that cannot be read is reported and written again.
|
|
19
|
+
- The setup page says so when the repo has no `Setupfile`.
|
|
20
|
+
|
|
21
|
+
## [0.6.0]
|
|
22
|
+
|
|
23
|
+
- A Rails app with keystone_ui can mount `DevOnboarder::Engine` to show the setup page.
|
|
24
|
+
- An app's server prints one line when it starts locally and a requirement needs setup.
|
|
25
|
+
|
|
26
|
+
## [0.5.0]
|
|
27
|
+
|
|
28
|
+
- `env` and `key_file` declare secrets and keys requirements in one line each.
|
|
29
|
+
- Setup asks for a missing variable's value and stores it in the repo's ignored `.env` file.
|
|
30
|
+
- `DevOnboarder::EnvFile#load_into` loads that file into the environment when an app starts.
|
|
31
|
+
|
|
32
|
+
## [0.4.0]
|
|
33
|
+
|
|
34
|
+
- `program`, `ruby_version` and `brewfile` declare machine tools requirements in one line each.
|
|
35
|
+
|
|
36
|
+
## [0.3.0]
|
|
37
|
+
|
|
38
|
+
- A `feature` block in the `Setupfile` groups the requirements needed only to test one feature.
|
|
39
|
+
- `dev_onboarder setup <feature>` checks and fixes one feature, and `dev_onboarder features` lists which are ready.
|
|
40
|
+
- A run now adds its results to the setup record and keeps the results it did not check.
|
|
41
|
+
|
|
42
|
+
## [0.2.0]
|
|
43
|
+
|
|
44
|
+
- `dev_onboarder status` lists each requirement that is new, changed or not met since the last run.
|
|
45
|
+
- The setup record stores a fingerprint of each requirement's check, fix and instruction.
|
|
46
|
+
|
|
47
|
+
## [0.1.0]
|
|
48
|
+
|
|
49
|
+
- `dev_onboarder` checks each requirement in a repo's `Setupfile`, runs its fix and records the result.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tylercschneider
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# dev_onboarder
|
|
2
|
+
|
|
3
|
+
One setup command that gets a developer from a fresh clone to a working repo.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Add the gem to the repo's `Gemfile` and run `bundle install`, then write a `Setupfile`. Nothing else in
|
|
8
|
+
the repo changes: the gem adds no line to its routes, boot code, initializers or `.gitignore`.
|
|
9
|
+
|
|
10
|
+
## Declare what the repo needs
|
|
11
|
+
|
|
12
|
+
Write a `Setupfile` at the repo's root. Each line declares one requirement:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
requirement :databases, group: :repo_setup, purpose: "Development and test databases exist",
|
|
16
|
+
check: "bin/rails db:version", fix: "bin/rails db:prepare"
|
|
17
|
+
|
|
18
|
+
requirement :price_key, group: :secrets, purpose: "Stock price key is set",
|
|
19
|
+
check: "test -n \"$PRICE_KEY\"", instruction: "Ask the team lead for the key"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `check` is a shell command that exits zero when the requirement is met.
|
|
23
|
+
- `fix` is a shell command run when the check fails, after which the check runs again.
|
|
24
|
+
- `instruction` is shown when the requirement is still not met.
|
|
25
|
+
|
|
26
|
+
## Declare machine tools in one line
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
program "psql", version: "17", install: "brew install postgresql@17"
|
|
30
|
+
ruby_version
|
|
31
|
+
brewfile
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- `program` requires a program on the path. `version` is the oldest version accepted, read from the
|
|
35
|
+
program's `--version` output, and `install` is the command run when the program is missing or too old.
|
|
36
|
+
- `ruby_version` requires the running Ruby to be the one the repo's `.ruby-version` names, and shows
|
|
37
|
+
both versions when they differ.
|
|
38
|
+
- `brewfile` requires every package in the repo's `Brewfile` and installs the missing ones with
|
|
39
|
+
Homebrew. Without Homebrew it installs nothing and lists the packages.
|
|
40
|
+
|
|
41
|
+
## Declare secrets and keys in one line
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
env "PRICE_KEY", from: "the vendor dashboard, under API keys"
|
|
45
|
+
env "MAP_KEY", from: "the team lead", optional: true
|
|
46
|
+
key_file "config/master.key", from: "the team lead"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- `env` requires an environment variable, set either in the shell or in the repo's `.env` file. When
|
|
50
|
+
it is missing, setup shows where to get it and asks for the value. What is typed is not shown, and it
|
|
51
|
+
is written to `.env` and to nowhere else.
|
|
52
|
+
- Setup stores a value only when git ignores `.env`. Otherwise it says to add `.env` to `.gitignore`.
|
|
53
|
+
- An `optional` variable is listed when it is missing and does not fail setup or status.
|
|
54
|
+
- `key_file` requires a file to exist and says who to ask for it.
|
|
55
|
+
- Setup asks for nothing when no keyboard is attached, as in CI.
|
|
56
|
+
|
|
57
|
+
A Rails app that has keystone_ui reads `.env` when it starts in development, before its own
|
|
58
|
+
initializers run, with nothing added to the app. A variable the shell already sets is left as it is.
|
|
59
|
+
|
|
60
|
+
## Run it
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
bundle exec dev_onboarder
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The command lists every requirement as met or not met, and exits with a failure status when any is
|
|
67
|
+
still not met. It writes what it found to `dev_onboarder.json` inside the clone's git directory, where
|
|
68
|
+
nothing is ever committed, so a second run shows when each requirement was last checked. Each git
|
|
69
|
+
worktree keeps its own record. Outside git, the record is `.dev_onboarder.json` at the repo's root.
|
|
70
|
+
|
|
71
|
+
## Declare what one feature needs
|
|
72
|
+
|
|
73
|
+
A requirement needed only to test one feature goes inside a `feature` block:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
feature :payments, "Take a test payment" do
|
|
77
|
+
requirement :payment_key, group: :secrets, purpose: "Payment test key is set",
|
|
78
|
+
check: "test -n \"$PAYMENT_KEY\"", instruction: "Copy the test key from the payment dashboard"
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- `bundle exec dev_onboarder` checks a feature's requirements, runs none of their fixes, and does not
|
|
83
|
+
fail because of them.
|
|
84
|
+
- `bundle exec dev_onboarder setup payments` checks and fixes only that feature's requirements.
|
|
85
|
+
- `bundle exec dev_onboarder features` lists each feature as ready or not ready, from the record of
|
|
86
|
+
the last run.
|
|
87
|
+
|
|
88
|
+
## Show the setup page in a Rails app
|
|
89
|
+
|
|
90
|
+
In a Rails app that has keystone_ui, the gem adds a page that shows what the last setup run recorded:
|
|
91
|
+
every requirement by group with its state and when it was last checked, each feature and whether it is
|
|
92
|
+
ready, and the command to run. The page reads the `Setupfile` and the setup record. It runs no check and
|
|
93
|
+
no fix.
|
|
94
|
+
|
|
95
|
+
When the app runs locally, the page is at `/dev_onboarder`, and it does not exist in production. It is
|
|
96
|
+
drawn inside the app's own layout when the app has an `ApplicationController`. To use another
|
|
97
|
+
controller, set `DevOnboarder.base_controller = "AdminController"`.
|
|
98
|
+
|
|
99
|
+
When the app's server starts locally and a requirement outside any feature is new, changed or not met,
|
|
100
|
+
the server output carries one line saying how many need setup and the command to run.
|
|
101
|
+
|
|
102
|
+
A Rails app without keystone_ui gets no page, no `.env` loading and no startup line, and a repo with no
|
|
103
|
+
Rails app is unaffected. Both use the command alone. The page is tested against keystone_ui 0.30.
|
|
104
|
+
|
|
105
|
+
## When something fails
|
|
106
|
+
|
|
107
|
+
- A fix that exits non-zero has what it printed shown under its requirement.
|
|
108
|
+
- A requirement can set a time limit for its fix, in seconds: `fix: "bin/rails db:prepare", timeout: 120`.
|
|
109
|
+
A fix that runs past it is stopped and reported as failed.
|
|
110
|
+
- An error in the `Setupfile` is reported with the line it is on, and no stack trace.
|
|
111
|
+
- Two requirements with the same key are refused, with the line of each.
|
|
112
|
+
- A setup record that cannot be read is reported, and the run writes it again.
|
|
113
|
+
- A run writes the setup record once, when it ends, so a run stopped part way leaves the earlier record
|
|
114
|
+
as it was.
|
|
115
|
+
|
|
116
|
+
## See what changed
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
bundle exec dev_onboarder status
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Status compares the `Setupfile` with the record of the last run and lists each requirement that is
|
|
123
|
+
new, changed or was left not met. It runs no check and no fix and writes nothing. It exits with a
|
|
124
|
+
failure status when it lists anything. A requirement counts as changed when its `check`, `fix` or
|
|
125
|
+
`instruction` changes.
|
|
126
|
+
|
|
127
|
+
A feature's requirements are listed under the feature's name, and status does not fail because of them.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevOnboarder
|
|
4
|
+
class SetupController < DevOnboarder.base_controller.constantize
|
|
5
|
+
helper KeystoneUiHelper
|
|
6
|
+
|
|
7
|
+
rescue_from DevOnboarder::Error do |error|
|
|
8
|
+
render html: helpers.ui_alert(message: error.message, type: :warning), layout: true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
@overview = Engine.overview(Rails.root.to_s)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<%
|
|
2
|
+
state_badges = {
|
|
3
|
+
met: { label: "Met", variant: :success },
|
|
4
|
+
new: { label: "New", variant: :info },
|
|
5
|
+
changed: { label: "Changed", variant: :warning },
|
|
6
|
+
not_met: { label: "Not met", variant: :danger }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
requirement_columns = [
|
|
10
|
+
Keystone::Ui::Column.new(:requirement, "Requirement"),
|
|
11
|
+
Keystone::Ui::Column.new(:purpose, "Purpose"),
|
|
12
|
+
Keystone::Ui::Column.new(:state, "State"),
|
|
13
|
+
Keystone::Ui::Column.new(:last_checked, "Last checked", mobile_hidden: true)
|
|
14
|
+
]
|
|
15
|
+
%>
|
|
16
|
+
|
|
17
|
+
<%= ui_page do %>
|
|
18
|
+
<%= ui_page_header(title: "Setup", subtitle: "What this repo needs on your machine") %>
|
|
19
|
+
|
|
20
|
+
<% if @overview.notice.present? %>
|
|
21
|
+
<%= ui_alert(message: @overview.notice, type: :warning) %>
|
|
22
|
+
<% else %>
|
|
23
|
+
<%= ui_alert(message: "Everything outside a feature is set up.", type: :success) %>
|
|
24
|
+
<% end %>
|
|
25
|
+
|
|
26
|
+
<%= ui_section do %>
|
|
27
|
+
<%= ui_code(caption: "Run this command to set up what is missing") do %>bundle exec dev_onboarder<% end %>
|
|
28
|
+
<%= ui_copy_button(text: "bundle exec dev_onboarder") %>
|
|
29
|
+
<% end %>
|
|
30
|
+
|
|
31
|
+
<% @overview.groups.each do |group| %>
|
|
32
|
+
<%
|
|
33
|
+
requirement_rows = group.rows.map do |row|
|
|
34
|
+
{
|
|
35
|
+
requirement: row.requirement.key.to_s,
|
|
36
|
+
purpose: row.requirement.purpose,
|
|
37
|
+
state: ui_badge(**state_badges.fetch(row.state)),
|
|
38
|
+
last_checked: row.checked_at ? row.checked_at.utc.strftime("%Y-%m-%d %H:%M UTC") : "Never"
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
%>
|
|
42
|
+
<%= ui_section(title: group.name.to_s.tr("_", " ").capitalize) do %>
|
|
43
|
+
<%= ui_data_table(items: requirement_rows, columns: requirement_columns) %>
|
|
44
|
+
<% end %>
|
|
45
|
+
<% end %>
|
|
46
|
+
|
|
47
|
+
<% if @overview.features.any? %>
|
|
48
|
+
<%
|
|
49
|
+
feature_rows = @overview.features.map do |entry|
|
|
50
|
+
{
|
|
51
|
+
feature: entry.feature.name.to_s,
|
|
52
|
+
description: entry.feature.description,
|
|
53
|
+
status: entry.ready ? ui_badge(label: "Ready", variant: :success) : ui_badge(label: "Not ready", variant: :neutral)
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
%>
|
|
57
|
+
<%= ui_section(title: "Features") do %>
|
|
58
|
+
<%= ui_data_table(items: feature_rows, columns: [{ feature: "Feature" }, { description: "Description" }, { status: "Status" }]) %>
|
|
59
|
+
<% end %>
|
|
60
|
+
<% end %>
|
|
61
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/exe/dev_onboarder
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lines"
|
|
4
|
+
require_relative "record_location"
|
|
5
|
+
require_relative "requirements"
|
|
6
|
+
require_relative "secret_prompt"
|
|
7
|
+
require_relative "setup"
|
|
8
|
+
require_relative "shell"
|
|
9
|
+
require_relative "status"
|
|
10
|
+
|
|
11
|
+
module DevOnboarder
|
|
12
|
+
class CLI
|
|
13
|
+
REQUIREMENTS_FILE = "Setupfile"
|
|
14
|
+
ENV_FILE = ".env"
|
|
15
|
+
|
|
16
|
+
def initialize(argv, out: $stdout, dir: Dir.pwd, shell: Shell.new, clock: -> { Time.now }, input: $stdin)
|
|
17
|
+
@input = input
|
|
18
|
+
@argv = argv
|
|
19
|
+
@out = out
|
|
20
|
+
@dir = dir
|
|
21
|
+
@shell = shell
|
|
22
|
+
@clock = clock
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def call
|
|
26
|
+
run
|
|
27
|
+
rescue Error => e
|
|
28
|
+
@out.puts e.message
|
|
29
|
+
1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def run
|
|
35
|
+
return report_status if @argv.first == "status"
|
|
36
|
+
return report_features if @argv.first == "features"
|
|
37
|
+
return report_unknown_feature if feature && !declared_feature?
|
|
38
|
+
|
|
39
|
+
run_setup
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def report_status
|
|
43
|
+
@out.puts status_lines
|
|
44
|
+
findings_of(nil).all? { |finding| finding.requirement.optional } ? 0 : 1
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def status_lines
|
|
48
|
+
return "Nothing has changed since your last setup." if findings.empty?
|
|
49
|
+
|
|
50
|
+
outside_any_feature = findings_of(nil).map { |finding| Lines.for_finding(finding) }
|
|
51
|
+
outside_any_feature + requirements.features.flat_map { |declared| feature_lines(declared) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def feature_lines(declared)
|
|
55
|
+
listed = findings_of(declared.name)
|
|
56
|
+
return [] if listed.empty?
|
|
57
|
+
|
|
58
|
+
["#{declared.name} — #{declared.description}"] + listed.map { |finding| " #{Lines.for_finding(finding)}" }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def findings_of(feature_name)
|
|
62
|
+
findings.select { |finding| finding.requirement.feature == feature_name }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def report_features
|
|
66
|
+
@out.puts(requirements.features.map { |declared| Lines.for_feature(declared, ready: ready?(declared)) })
|
|
67
|
+
0
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def ready?(declared)
|
|
71
|
+
findings.none? { |finding| finding.requirement.feature == declared.name }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def report_unknown_feature
|
|
75
|
+
@out.puts "No feature named #{feature}."
|
|
76
|
+
1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def run_setup
|
|
80
|
+
@out.puts "The setup record could not be read, so this run writes it again." if record.unreadable?
|
|
81
|
+
outcomes = setup.call
|
|
82
|
+
outcomes.each { |outcome| @out.puts Lines.for_outcome(outcome) }
|
|
83
|
+
outcomes.select { |outcome| required?(outcome.requirement) }.all?(&:met) ? 0 : 1
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def setup
|
|
87
|
+
Setup.new(requirements: requirements, record: record, shell: @shell, clock: @clock, feature: feature,
|
|
88
|
+
secrets: secret_prompt)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def required?(requirement)
|
|
92
|
+
requirement.feature == feature && !requirement.optional
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def secret_prompt
|
|
96
|
+
SecretPrompt.new(env_file: EnvFile.new(File.join(@dir, ENV_FILE)), input: @input, out: @out, shell: @shell)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def feature
|
|
100
|
+
@argv[1]&.to_sym
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def declared_feature?
|
|
104
|
+
requirements.features.any? { |declared| declared.name == feature }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def findings
|
|
108
|
+
@findings ||= Status.new(requirements: requirements, record: record).call
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def requirements
|
|
112
|
+
@requirements ||= Requirements.load(File.join(@dir, REQUIREMENTS_FILE))
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def record
|
|
116
|
+
Record.new(RecordLocation.path(@dir))
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/engine"
|
|
4
|
+
require "keystone_ui"
|
|
5
|
+
require_relative "env_file"
|
|
6
|
+
require_relative "overview"
|
|
7
|
+
require_relative "record_location"
|
|
8
|
+
require_relative "requirements"
|
|
9
|
+
|
|
10
|
+
module DevOnboarder
|
|
11
|
+
class << self
|
|
12
|
+
attr_writer :base_controller
|
|
13
|
+
|
|
14
|
+
def base_controller
|
|
15
|
+
@base_controller || (Object.const_defined?(:ApplicationController) ? "ApplicationController" : "ActionController::Base")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Engine < ::Rails::Engine
|
|
20
|
+
isolate_namespace DevOnboarder
|
|
21
|
+
|
|
22
|
+
initializer "dev_onboarder.load_environment_file", before: :load_config_initializers do |app|
|
|
23
|
+
EnvFile.new(app.root.join(".env").to_s).load_into(ENV) if Rails.env.development?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
initializer "dev_onboarder.page_route" do |app|
|
|
27
|
+
app.routes.prepend { mount DevOnboarder::Engine, at: "/dev_onboarder" if Rails.env.local? }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
server do
|
|
31
|
+
notice = startup_notice(Rails.root.to_s) if Rails.env.local?
|
|
32
|
+
puts notice if notice
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.startup_notice(root)
|
|
36
|
+
return unless File.exist?(File.join(root, "Setupfile"))
|
|
37
|
+
|
|
38
|
+
overview(root).notice
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.overview(root)
|
|
42
|
+
Overview.new(requirements: Requirements.load(File.join(root, "Setupfile")),
|
|
43
|
+
record: Record.new(RecordLocation.path(root)))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevOnboarder
|
|
4
|
+
class EnvFile
|
|
5
|
+
def initialize(path)
|
|
6
|
+
@path = path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def set(name, value)
|
|
10
|
+
File.write(@path, values.merge(name => value).map { |key, stored| "#{key}=#{stored}\n" }.join)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def load_into(environment)
|
|
14
|
+
values.each { |name, value| environment[name] ||= value }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def values
|
|
20
|
+
return {} unless File.exist?(@path)
|
|
21
|
+
|
|
22
|
+
File.readlines(@path, chomp: true).to_h { |line| line.split("=", 2) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevOnboarder
|
|
4
|
+
module Lines
|
|
5
|
+
STATE_LABELS = { new: "new ", changed: "changed", not_met: "not met" }.freeze
|
|
6
|
+
|
|
7
|
+
def self.for_outcome(outcome)
|
|
8
|
+
[outcome_line(outcome), *fix_output(outcome), instruction(outcome)].compact
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.for_finding(finding)
|
|
12
|
+
"#{STATE_LABELS.fetch(finding.state)} #{finding.requirement.key} — #{finding.requirement.purpose}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.for_feature(feature, ready:)
|
|
16
|
+
"#{ready ? "ready " : "not ready"} #{feature.name} — #{feature.description}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.outcome_line(outcome)
|
|
20
|
+
"#{outcome.met ? "met " : "not met"} #{outcome.requirement.key} — #{outcome.requirement.purpose}" \
|
|
21
|
+
"#{last_checked(outcome)}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.fix_output(outcome)
|
|
25
|
+
outcome.fix_output.to_s.lines(chomp: true).map { |line| " #{line}" }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.instruction(outcome)
|
|
29
|
+
return if outcome.met || outcome.requirement.instruction.nil?
|
|
30
|
+
|
|
31
|
+
" #{outcome.requirement.instruction}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.last_checked(outcome)
|
|
35
|
+
return unless outcome.last_checked_at
|
|
36
|
+
|
|
37
|
+
" (last checked #{outcome.last_checked_at.utc.strftime("%Y-%m-%d %H:%M UTC")})"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private_class_method :outcome_line, :fix_output, :instruction, :last_checked
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevOnboarder
|
|
4
|
+
module MachineTools
|
|
5
|
+
HOMEBREW_ON_PATH = "command -v brew >/dev/null"
|
|
6
|
+
VERSION_CHECK = <<~'RUBY'.strip
|
|
7
|
+
exit Gem::Version.new(%%x(%<name>s --version)[/\d+(\.\d+)+/].to_s) >= Gem::Version.new("%<version>s")
|
|
8
|
+
RUBY
|
|
9
|
+
|
|
10
|
+
def program(name, version: nil, install: nil)
|
|
11
|
+
requirement name.tr("-", "_").to_sym, group: :machine_tools,
|
|
12
|
+
purpose: "#{name}#{" #{version} or newer" if version} is installed",
|
|
13
|
+
check: installed_check(name, version), fix: install
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def ruby_version
|
|
17
|
+
named = File.read(File.join(@dir, ".ruby-version")).strip
|
|
18
|
+
requirement :ruby_version, group: :machine_tools, purpose: "Ruby #{named} is the running Ruby",
|
|
19
|
+
check: %(test "$(ruby -e 'print RUBY_VERSION')" = "#{named}"),
|
|
20
|
+
instruction: "This repo names Ruby #{named} and you are running Ruby #{RUBY_VERSION}."
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def brewfile
|
|
24
|
+
requirement :brewfile, group: :machine_tools, purpose: "Every package in the Brewfile is installed",
|
|
25
|
+
check: "#{HOMEBREW_ON_PATH} && brew bundle check --file=Brewfile --no-upgrade",
|
|
26
|
+
fix: "#{HOMEBREW_ON_PATH} && brew bundle --file=Brewfile --no-upgrade",
|
|
27
|
+
instruction: "Without Homebrew, install these yourself: #{brewfile_packages.join(", ")}."
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def brewfile_packages
|
|
33
|
+
File.read(File.join(@dir, "Brewfile")).scan(/^\s*(?:brew|cask)\s+["']([^"']+)["']/).flatten
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def installed_check(name, version)
|
|
37
|
+
on_path = "command -v #{name} >/dev/null"
|
|
38
|
+
return on_path unless version
|
|
39
|
+
|
|
40
|
+
"#{on_path} && ruby -e '#{format(VERSION_CHECK, name: name, version: version)}'"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "record"
|
|
4
|
+
require_relative "status"
|
|
5
|
+
|
|
6
|
+
module DevOnboarder
|
|
7
|
+
class Overview
|
|
8
|
+
Group = Data.define(:name, :rows)
|
|
9
|
+
Row = Data.define(:requirement, :state, :checked_at)
|
|
10
|
+
FeatureRow = Data.define(:feature, :ready)
|
|
11
|
+
|
|
12
|
+
def initialize(requirements:, record:)
|
|
13
|
+
@requirements = requirements
|
|
14
|
+
@record = record
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def groups
|
|
18
|
+
@requirements.group_by(&:group).map do |name, requirements|
|
|
19
|
+
Group.new(name: name, rows: requirements.map { |requirement| row_for(requirement) })
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def features
|
|
24
|
+
@requirements.features.map { |feature| FeatureRow.new(feature: feature, ready: ready?(feature)) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def notice
|
|
28
|
+
count = findings.count { |finding| finding.requirement.feature.nil? }
|
|
29
|
+
return if count.zero?
|
|
30
|
+
|
|
31
|
+
"dev_onboarder: #{count} requirement#{"s" unless count == 1} need#{"s" if count == 1} setup. " \
|
|
32
|
+
"Run bundle exec dev_onboarder."
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def ready?(feature)
|
|
38
|
+
findings.none? { |finding| finding.requirement.feature == feature.name }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def row_for(requirement)
|
|
42
|
+
Row.new(requirement: requirement, state: states.fetch(requirement.key, :met),
|
|
43
|
+
checked_at: @record.result_for(requirement.key)&.checked_at)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def states
|
|
47
|
+
@states ||= findings.to_h { |finding| [finding.requirement.key, finding.state] }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def findings
|
|
51
|
+
@findings ||= Status.new(requirements: @requirements, record: @record).call
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|