git-fit 0.5.0 → 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 +4 -4
- data/lib/git-fit.rb +1 -0
- data/lib/git_fit/cli/install_cli.rb +5 -15
- data/lib/git_fit/cli/remote_cli.rb +68 -0
- data/lib/git_fit/cli.rb +3 -0
- data/lib/git_fit/install/actions.rb +44 -81
- data/lib/git_fit/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e357e4ed167a5b5cbbb76c2490e5e62ffd4883d6e99dc123d492f83e281e583
|
|
4
|
+
data.tar.gz: 94d1327c355f921a120a290f4f8861f7ff4e04e877a30ab0cbc9b8dab2f76e5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6626c0c270e88df95cda6c74b815fbe97c5813b687b74e9a9631fe8c98245b935d75c29076b4298261835bb48b8319d30a6f6f4758afc79d77210f86082d8ab4
|
|
7
|
+
data.tar.gz: e83614a173412d03c7db1dddeb497d240f37158f301dd1024851b201686ec1926699b6c493a817b5a73a8aecb510a38d247cb1a3cfbdf9938b022612fdf4e889
|
data/lib/git-fit.rb
CHANGED
|
@@ -64,6 +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
68
|
require_relative "git_fit/cli/export"
|
|
68
69
|
require_relative "git_fit/cli/import_cli"
|
|
69
70
|
require_relative "git_fit/cli"
|
|
@@ -3,20 +3,10 @@ require "fileutils"
|
|
|
3
3
|
|
|
4
4
|
module GitFit
|
|
5
5
|
class InstallCLI < Thor
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require "thor"
|
|
2
|
+
require "open3"
|
|
3
|
+
|
|
4
|
+
module GitFit
|
|
5
|
+
module RemoteHelpers
|
|
6
|
+
def detect_repo(url = nil)
|
|
7
|
+
url ||= `git remote get-url origin`.chomp
|
|
8
|
+
url.sub(%r{.*github\.com[:/]}, "").sub(/\.git$/, "")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def gh(*args)
|
|
12
|
+
repo = options[:repo] || detect_repo
|
|
13
|
+
out, err, st = Open3.capture3("gh", *args.map(&:to_s), "-R", repo)
|
|
14
|
+
raise "gh: #{err.strip}" unless st.success?
|
|
15
|
+
out
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class RemoteSecretCLI < Thor
|
|
20
|
+
include RemoteHelpers
|
|
21
|
+
|
|
22
|
+
class_option :repo, type: :string, desc: "GitHub repo (owner/repo)"
|
|
23
|
+
|
|
24
|
+
desc "list", "List secrets"
|
|
25
|
+
def list
|
|
26
|
+
puts gh("secret", "list")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
desc "set KEY", "Set a secret (reads value from stdin or prompt)"
|
|
30
|
+
def set(key)
|
|
31
|
+
puts gh("secret", "set", key)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc "delete KEY", "Delete a secret"
|
|
35
|
+
def delete(key)
|
|
36
|
+
puts gh("secret", "delete", key)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class RemoteConfigCLI < Thor
|
|
41
|
+
include RemoteHelpers
|
|
42
|
+
|
|
43
|
+
class_option :repo, type: :string, desc: "GitHub repo (owner/repo)"
|
|
44
|
+
|
|
45
|
+
desc "list", "List variables"
|
|
46
|
+
def list
|
|
47
|
+
puts gh("variable", "list")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
desc "set KEY VALUE", "Set a variable"
|
|
51
|
+
def set(key, value)
|
|
52
|
+
puts gh("variable", "set", key, "--body", value)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
desc "get KEY", "Get a variable value"
|
|
56
|
+
def get(key)
|
|
57
|
+
puts gh("variable", "get", key)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class RemoteCLI < Thor
|
|
62
|
+
desc "secret SUBCOMMAND", "Manage GitHub Secrets"
|
|
63
|
+
subcommand "secret", RemoteSecretCLI
|
|
64
|
+
|
|
65
|
+
desc "config SUBCOMMAND", "Manage GitHub Variables"
|
|
66
|
+
subcommand "config", RemoteConfigCLI
|
|
67
|
+
end
|
|
68
|
+
end
|
data/lib/git_fit/cli.rb
CHANGED
|
@@ -61,6 +61,9 @@ 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
|
|
66
|
+
|
|
64
67
|
desc "install SUBCOMMAND", "Install project assets (actions)"
|
|
65
68
|
subcommand "install", InstallCLI
|
|
66
69
|
|
|
@@ -1,90 +1,53 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
|
|
1
3
|
module GitFit
|
|
2
4
|
module Install
|
|
3
5
|
module Actions
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
data/lib/git_fit/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lax
|
|
@@ -136,6 +136,7 @@ files:
|
|
|
136
136
|
- lib/git_fit/cli/export.rb
|
|
137
137
|
- lib/git_fit/cli/import_cli.rb
|
|
138
138
|
- lib/git_fit/cli/install_cli.rb
|
|
139
|
+
- lib/git_fit/cli/remote_cli.rb
|
|
139
140
|
- lib/git_fit/config.rb
|
|
140
141
|
- lib/git_fit/config_template.rb
|
|
141
142
|
- lib/git_fit/db/activity.rb
|