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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 329dda87a51a4e7262c948a3512e51c4fcee9d99f9dceb7c1cc3dbcc23e122f9
4
- data.tar.gz: 4d77ca960d45a452dfadac61902d226206e9a76ebd39607387cd32bea45439eb
3
+ metadata.gz: 77927cc9d568e7f7b76c291e79a40144a6973a1ec959b53684156bc32e801fd4
4
+ data.tar.gz: 6b740fd8f0e3877a6f22d5a287478fcb7983e3e82886d5a24a3035051e6ef73d
5
5
  SHA512:
6
- metadata.gz: 537a6b1603267cf4ad153882616d19f338e644586d5210c403ade87a759019fcaafa4c85ca52b8494dc8c0018d95501b24b23e9dcc3ef9ca39cbd0cc45277659
7
- data.tar.gz: 175d07fb83ad7dfd28d4d09753a74c0677937ceabb3f7502759f9e70ec526870144e1057641e88de5229b7315ae726a16b057270f1d1d4ad5ac653538d12c6f7
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
- paths = GitFit::Install::Actions.install(family)
9
- paths.each { |p| say_status :created, p, :green }
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
- File.write(out_path, content)
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
- def self.install(family = nil)
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
@@ -1,3 +1,3 @@
1
1
  module GitFit
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-fit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax