git-fit 0.5.2 → 0.5.3

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: 7e357e4ed167a5b5cbbb76c2490e5e62ffd4883d6e99dc123d492f83e281e583
4
+ data.tar.gz: 94d1327c355f921a120a290f4f8861f7ff4e04e877a30ab0cbc9b8dab2f76e5a
5
5
  SHA512:
6
- metadata.gz: 5198cf67db145f177ff9724e04db810dad001ec26880225da674ac7e56e9a831bb479e230e1f877bdca0cac68378987b1e659b3c1a5e73d54506cecbb0a43b9f
7
- data.tar.gz: 415217acf88a14ce72695533a6608816aa5be1a815367e2fa80c00ce8e6c45acf9e115e36108d1ba66fd0b3eb85c2576c13219865bdd2c27c3ee84a21e3d978f
6
+ metadata.gz: 6626c0c270e88df95cda6c74b815fbe97c5813b687b74e9a9631fe8c98245b935d75c29076b4298261835bb48b8319d30a6f6f4758afc79d77210f86082d8ab4
7
+ data.tar.gz: e83614a173412d03c7db1dddeb497d240f37158f301dd1024851b201686ec1926699b6c493a817b5a73a8aecb510a38d247cb1a3cfbdf9938b022612fdf4e889
@@ -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
@@ -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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax