git-fit 0.5.2 → 0.5.4

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: e9c72b520e8e23448fc1c1dbc59a0d4f56e670a6274f7fee951bc59b30388ac9
4
- data.tar.gz: '0593bd28c9e1245215215fd27a79becc94e199adaf401be36c0548ced45185c6'
3
+ metadata.gz: b3388f891fdb16dd73df349152885f9a28f074495b3a7ef2f9932dae6b064cfb
4
+ data.tar.gz: cd9591fdd163b5e842743cbf96e89fb7dfb0b86b4a3b19aafd08b61447f4b34c
5
5
  SHA512:
6
- metadata.gz: 5198cf67db145f177ff9724e04db810dad001ec26880225da674ac7e56e9a831bb479e230e1f877bdca0cac68378987b1e659b3c1a5e73d54506cecbb0a43b9f
7
- data.tar.gz: 415217acf88a14ce72695533a6608816aa5be1a815367e2fa80c00ce8e6c45acf9e115e36108d1ba66fd0b3eb85c2576c13219865bdd2c27c3ee84a21e3d978f
6
+ metadata.gz: a18773ca91756e251326407cc9e919072925aa0f15ffc6429c05ef45c8bb4012d5ecefbec360308612f0b211b142a7a8e4fa0dbf60783ee38c83202acd4a90a3
7
+ data.tar.gz: 6bd5f44697a43805cef33b210d5d3d97c10e24e030652342167c5ac4c8ccf5c139ddc6db1e6afa2e3fd0e08d238f04eac1b7e33616d37db75c5c1dbccd441958
data/lib/git-fit.rb CHANGED
@@ -64,7 +64,7 @@ require_relative "git_fit/export"
64
64
  require_relative "git_fit/db/cli"
65
65
  require_relative "git_fit/install/actions"
66
66
  require_relative "git_fit/cli/install_cli"
67
- require_relative "git_fit/cli/remote_cli"
67
+ require_relative "git_fit/cli/gh_cli"
68
68
  require_relative "git_fit/cli/export"
69
69
  require_relative "git_fit/cli/import_cli"
70
70
  require_relative "git_fit/cli"
@@ -2,7 +2,7 @@ require "thor"
2
2
  require "open3"
3
3
 
4
4
  module GitFit
5
- module RemoteHelpers
5
+ module GhHelpers
6
6
  def detect_repo(url = nil)
7
7
  url ||= `git remote get-url origin`.chomp
8
8
  url.sub(%r{.*github\.com[:/]}, "").sub(/\.git$/, "")
@@ -16,8 +16,8 @@ module GitFit
16
16
  end
17
17
  end
18
18
 
19
- class RemoteSecretCLI < Thor
20
- include RemoteHelpers
19
+ class GhSecretCLI < Thor
20
+ include GhHelpers
21
21
 
22
22
  class_option :repo, type: :string, desc: "GitHub repo (owner/repo)"
23
23
 
@@ -37,8 +37,8 @@ module GitFit
37
37
  end
38
38
  end
39
39
 
40
- class RemoteConfigCLI < Thor
41
- include RemoteHelpers
40
+ class GhConfigCLI < Thor
41
+ include GhHelpers
42
42
 
43
43
  class_option :repo, type: :string, desc: "GitHub repo (owner/repo)"
44
44
 
@@ -58,11 +58,11 @@ module GitFit
58
58
  end
59
59
  end
60
60
 
61
- class RemoteCLI < Thor
61
+ class GhCLI < Thor
62
62
  desc "secret SUBCOMMAND", "Manage GitHub Secrets"
63
- subcommand "secret", RemoteSecretCLI
63
+ subcommand "secret", GhSecretCLI
64
64
 
65
65
  desc "config SUBCOMMAND", "Manage GitHub Variables"
66
- subcommand "config", RemoteConfigCLI
66
+ subcommand "config", GhConfigCLI
67
67
  end
68
68
  end
@@ -3,20 +3,10 @@ require "fileutils"
3
3
 
4
4
  module GitFit
5
5
  class InstallCLI < Thor
6
- desc "actions", "Install GitHub Actions (db-cache restore/save)"
7
- def actions
8
- base = ".github/actions/db-cache"
9
- restore_path = File.join(base, "restore", "action.yml")
10
- save_path = File.join(base, "save", "action.yml")
11
-
12
- FileUtils.mkdir_p(File.dirname(restore_path))
13
- FileUtils.mkdir_p(File.dirname(save_path))
14
-
15
- File.write(restore_path, GitFit::Install::Actions::RESTORE_ACTION)
16
- File.write(save_path, GitFit::Install::Actions::SAVE_ACTION)
17
-
18
- say_status :created, restore_path, :green
19
- say_status :created, save_path, :green
20
- end
6
+ desc "actions [family]", "Install GitHub Actions (default: all families)"
7
+ def actions(family = nil)
8
+ paths = GitFit::Install::Actions.install(family)
9
+ paths.each { |p| say_status :created, p, :green }
10
+ end
21
11
  end
22
12
  end
data/lib/git_fit/cli.rb CHANGED
@@ -61,8 +61,8 @@ module GitFit
61
61
  say_status :error, "Parse failed: #{e.message}", :red
62
62
  end
63
63
 
64
- desc "remote SUBCOMMAND", "Manage GitHub remote secrets and config"
65
- subcommand "remote", RemoteCLI
64
+ desc "gh SUBCOMMAND", "Manage GitHub secrets and variables"
65
+ subcommand "gh", GhCLI
66
66
 
67
67
  desc "install SUBCOMMAND", "Install project assets (actions)"
68
68
  subcommand "install", InstallCLI
@@ -1,90 +1,53 @@
1
+ require "erb"
2
+
1
3
  module GitFit
2
4
  module Install
3
5
  module Actions
4
- RESTORE_ACTION = <<~RESTORE_ACTION_YAML
5
- name: DB Cache Restore
6
- description: Restore SQLite DB with checksum verification
7
- inputs:
8
- path:
9
- required: false
10
- default: db/fit.sqlite3
11
- key-prefix:
12
- required: false
13
- default: git-fit-db
14
- runs:
15
- using: composite
16
- steps:
17
- - uses: actions/cache/restore@v4
18
- id: restore-db
19
- with:
20
- path: |-
21
- ${{ inputs.path }}
22
- ${{ inputs.path }}.checksum
23
- key: ${{ inputs.key-prefix }}-v1-${{ github.run_id }}
24
- restore-keys: ${{ inputs.key-prefix }}-v1-
6
+ TEMPLATE_DIR = File.expand_path("actions", __dir__)
7
+
8
+ def self.render(name, db_path:)
9
+ path = File.join(TEMPLATE_DIR, "#{name}.yml.erb")
10
+ ERB.new(File.read(path)).result_with_hash(db_path: db_path)
11
+ end
12
+
13
+ def self.available_families
14
+ Dir.children(TEMPLATE_DIR)
15
+ .select { |e| File.directory?(File.join(TEMPLATE_DIR, e)) }
16
+ .sort
17
+ end
18
+
19
+ def self.install_family(family)
20
+ dir = File.join(TEMPLATE_DIR, family)
21
+ db_path = ENV["GIT_FIT_DATABASE_PATH"] || "db/fit.sqlite3"
22
+
23
+ Dir.glob("*.yml.erb", base: dir).sort.map do |tpl|
24
+ action_name = tpl.delete_suffix(".yml.erb")
25
+ content = render("#{family}/#{action_name}", db_path: db_path)
26
+ out_path = ".github/actions/#{family}/#{action_name}/action.yml"
27
+ FileUtils.mkdir_p(File.dirname(out_path))
28
+ File.write(out_path, content)
29
+ out_path
30
+ end
31
+ end
32
+
33
+ def self.restore_action(db_path = "db/fit.sqlite3")
34
+ render("db-cache/restore", db_path: db_path)
35
+ end
36
+
37
+ RESTORE_ACTION = restore_action
38
+
39
+ def self.save_action(db_path = "db/fit.sqlite3")
40
+ render("db-cache/save", db_path: db_path)
41
+ end
25
42
 
26
- - name: Verify checksum
27
- shell: bash
28
- run: |
29
- db="${{ inputs.path }}"
30
- ck="${db}.checksum"
31
- if [ ! -f "$ck" ]; then
32
- echo "No checksum file — first run or cache miss, skipping verify"
33
- exit 0
34
- fi
35
- if ! sha256sum --check "$ck" --quiet 2>/dev/null; then
36
- echo "::warning::Checksum mismatch — $db may be corrupted"
37
- echo "Removing stale files"
38
- rm -f "$db" "$ck"
39
- else
40
- echo "Checksum OK — $db is intact"
41
- fi
42
- RESTORE_ACTION_YAML
43
+ SAVE_ACTION = save_action
43
44
 
44
- SAVE_ACTION = <<~SAVE_ACTION_YAML
45
- name: DB Cache Save
46
- description: Save SQLite DB with checksum, skip if unchanged
47
- inputs:
48
- path:
49
- required: false
50
- default: db/fit.sqlite3
51
- key-prefix:
52
- required: false
53
- default: git-fit-db
54
- outputs:
55
- saved:
56
- description: "true if cache was updated, false if unchanged"
57
- value: ${{ steps.detect.outputs.saved }}
58
- runs:
59
- using: composite
60
- steps:
61
- - name: Detect changes
62
- id: detect
63
- shell: bash
64
- run: |
65
- db="${{ inputs.path }}"
66
- ck="${db}.checksum"
67
- new_sum=$(sha256sum "$db" 2>/dev/null || echo "")
68
- if [ -z "$new_sum" ]; then
69
- echo "saved=false" >> "$GITHUB_OUTPUT"
70
- exit 0
71
- fi
72
- if [ -f "$ck" ] && sha256sum --check "$ck" --quiet 2>/dev/null; then
73
- echo "DB unchanged — skip save"
74
- echo "saved=false" >> "$GITHUB_OUTPUT"
75
- exit 0
76
- fi
77
- echo "$new_sum" > "$ck"
78
- echo "saved=true" >> "$GITHUB_OUTPUT"
45
+ def self.install(family = nil)
46
+ families = family ? [family] : available_families
47
+ families.flat_map { |f| install_family(f) }
48
+ end
79
49
 
80
- - uses: actions/cache/save@v4
81
- if: steps.detect.outputs.saved == 'true'
82
- with:
83
- path: |-
84
- ${{ inputs.path }}
85
- ${{ inputs.path }}.checksum
86
- key: ${{ inputs.key-prefix }}-v1-${{ github.run_id }}
87
- SAVE_ACTION_YAML
50
+ private_class_method :render, :available_families, :install_family
88
51
  end
89
52
  end
90
53
  end
@@ -1,3 +1,3 @@
1
1
  module GitFit
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.4"
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.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax
@@ -134,9 +134,9 @@ files:
134
134
  - lib/git-fit.rb
135
135
  - lib/git_fit/cli.rb
136
136
  - lib/git_fit/cli/export.rb
137
+ - lib/git_fit/cli/gh_cli.rb
137
138
  - lib/git_fit/cli/import_cli.rb
138
139
  - lib/git_fit/cli/install_cli.rb
139
- - lib/git_fit/cli/remote_cli.rb
140
140
  - lib/git_fit/config.rb
141
141
  - lib/git_fit/config_template.rb
142
142
  - lib/git_fit/db/activity.rb