git-fit 0.5.8 → 0.5.9
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/lib/git_fit/cli/install_cli.rb +37 -2
- data/lib/git_fit/install/actions.rb +50 -9
- data/lib/git_fit/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: 77927cc9d568e7f7b76c291e79a40144a6973a1ec959b53684156bc32e801fd4
|
|
4
|
+
data.tar.gz: 6b740fd8f0e3877a6f22d5a287478fcb7983e3e82886d5a24a3035051e6ef73d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 682ab1bf78d273e5814603ee7f1fafcfe16bd0020a6703b275f12fe0a23dbe624f198fd94ef47ce9e8f8a05541cf33bd45d7583019708a7e664d650207707be3
|
|
7
|
+
data.tar.gz: 208d7e4dd44ea7cfb04b3f343619963597a86da2d86830b7ffa82b06397bb2a9970e8b10d18ce26c1e790dac26a29c5fb6e5e2d12803417c47d09d823ee33a28
|
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
require "thor"
|
|
2
2
|
require "fileutils"
|
|
3
|
+
require "yaml"
|
|
3
4
|
|
|
4
5
|
module GitFit
|
|
5
6
|
class InstallCLI < Thor
|
|
6
7
|
desc "actions [family]", "Install GitHub Actions (default: all families)"
|
|
8
|
+
option :check, type: :boolean, desc: "Check on-disk files against templates, exit non-zero on mismatch"
|
|
9
|
+
option :"dry-run", type: :boolean, desc: "Render templates and print without writing"
|
|
7
10
|
def actions(family = nil)
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
check = options[:check]
|
|
12
|
+
dry_run = options[:"dry-run"]
|
|
13
|
+
|
|
14
|
+
if check && dry_run
|
|
15
|
+
say "Error: --check and --dry-run are mutually exclusive", :red
|
|
16
|
+
raise Thor::Error, "Cannot use --check and --dry-run together"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
results = GitFit::Install::Actions.install(family, check: check, dry_run: dry_run)
|
|
20
|
+
|
|
21
|
+
if dry_run
|
|
22
|
+
results.each do |r|
|
|
23
|
+
say "Would write: #{r[:path]}", :cyan
|
|
24
|
+
say r[:content], :cyan
|
|
25
|
+
end
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if check
|
|
30
|
+
mismatches = results.select { |r| r[:mismatch] }
|
|
31
|
+
if mismatches.any?
|
|
32
|
+
mismatches.each do |r|
|
|
33
|
+
say "DIFF: #{r[:path]}", :red
|
|
34
|
+
puts r[:diff]
|
|
35
|
+
end
|
|
36
|
+
raise Thor::Error, "Install check failed: #{mismatches.size} file(s) differ from template"
|
|
37
|
+
else
|
|
38
|
+
results.each { |r| say_status :ok, r[:path], :green }
|
|
39
|
+
say "All #{results.size} files match templates", :green
|
|
40
|
+
end
|
|
41
|
+
return
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
results.each { |r| say_status :created, r[:path], :green }
|
|
10
45
|
end
|
|
11
46
|
end
|
|
12
47
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
require "erb"
|
|
2
|
+
require "digest"
|
|
2
3
|
|
|
3
4
|
module GitFit
|
|
4
5
|
module Install
|
|
5
6
|
module Actions
|
|
6
7
|
TEMPLATE_DIR = File.expand_path("actions", __dir__)
|
|
8
|
+
VERSION_STAMP = "# Generated by git-fit v#{GitFit::VERSION} — do not edit manually\n"
|
|
7
9
|
|
|
8
10
|
def self.render(name, db_path:)
|
|
9
11
|
path = File.join(TEMPLATE_DIR, "#{name}.yml.erb")
|
|
@@ -16,18 +18,62 @@ module GitFit
|
|
|
16
18
|
.sort
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
def self.install_family(family)
|
|
21
|
+
def self.install_family(family, check: false, dry_run: false)
|
|
20
22
|
dir = File.join(TEMPLATE_DIR, family)
|
|
21
23
|
db_path = ENV["GIT_FIT_DATABASE_PATH"] || "db/fit.sqlite3"
|
|
24
|
+
results = []
|
|
22
25
|
|
|
23
26
|
Dir.glob("*.yml.erb", base: dir).sort.map do |tpl|
|
|
24
27
|
action_name = tpl.delete_suffix(".yml.erb")
|
|
25
28
|
content = render("#{family}/#{action_name}", db_path: db_path)
|
|
29
|
+
stamped = "#{VERSION_STAMP}\n#{content}"
|
|
26
30
|
out_path = ".github/actions/#{family}/#{action_name}/action.yml"
|
|
31
|
+
|
|
32
|
+
if dry_run
|
|
33
|
+
results << { path: out_path, content: stamped, dry_run: true }
|
|
34
|
+
next
|
|
35
|
+
end
|
|
36
|
+
|
|
27
37
|
FileUtils.mkdir_p(File.dirname(out_path))
|
|
28
|
-
|
|
29
|
-
out_path
|
|
38
|
+
|
|
39
|
+
if check && !File.exist?(out_path)
|
|
40
|
+
results << { path: out_path, missing: true }
|
|
41
|
+
next
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if File.exist?(out_path)
|
|
45
|
+
existing = File.read(out_path)
|
|
46
|
+
if check
|
|
47
|
+
if existing != stamped
|
|
48
|
+
results << { path: out_path, diff: diff(existing, stamped), mismatch: true }
|
|
49
|
+
else
|
|
50
|
+
results << { path: out_path, match: true }
|
|
51
|
+
end
|
|
52
|
+
next
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
File.write(out_path, stamped)
|
|
57
|
+
results << { path: out_path, written: true }
|
|
30
58
|
end
|
|
59
|
+
|
|
60
|
+
results
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.diff(a, b)
|
|
64
|
+
require "tempfile"
|
|
65
|
+
ta = Tempfile.new("a")
|
|
66
|
+
tb = Tempfile.new("b")
|
|
67
|
+
ta.write(a)
|
|
68
|
+
tb.write(b)
|
|
69
|
+
ta.close
|
|
70
|
+
tb.close
|
|
71
|
+
`diff -u #{ta.path} #{tb.path} 2>/dev/null || echo "(no diff binary)"`
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.install(family = nil, check: false, dry_run: false)
|
|
75
|
+
families = family ? [family] : available_families
|
|
76
|
+
families.flat_map { |f| install_family(f, check: check, dry_run: dry_run) }
|
|
31
77
|
end
|
|
32
78
|
|
|
33
79
|
def self.restore_action(db_path = "db/fit.sqlite3")
|
|
@@ -42,12 +88,7 @@ module GitFit
|
|
|
42
88
|
|
|
43
89
|
SAVE_ACTION = save_action
|
|
44
90
|
|
|
45
|
-
|
|
46
|
-
families = family ? [family] : available_families
|
|
47
|
-
families.flat_map { |f| install_family(f) }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private_class_method :render, :available_families, :install_family
|
|
91
|
+
private_class_method :render, :available_families, :install_family, :diff
|
|
51
92
|
end
|
|
52
93
|
end
|
|
53
94
|
end
|
data/lib/git_fit/version.rb
CHANGED