Skip to content

Commit d9f82eb

Browse files
authored
Merge pull request #394 from cncf/feature/#385-git-prereq
Feature/#385 Git now part of prereqs
2 parents 8478eab + 5b7c3b4 commit d9f82eb

File tree

4 files changed

+114
-2
lines changed

4 files changed

+114
-2
lines changed

spec/prereqs_spec.cr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ require "file_utils"
66
require "sam"
77

88
describe "Prereq" do
9-
it "'prereq' should check the system for prerequisites", tags: "happy-path" do
9+
it "'prereq' should check the system for prerequisites", tags: "prereqs" do
1010
response_s = `./cnf-conformance prereqs verbose`
1111
LOGGING.info response_s
1212
$?.success?.should be_true
1313
(/helm found/ =~ response_s).should_not be_nil
1414
(/wget found/ =~ response_s).should_not be_nil
1515
(/curl found/ =~ response_s).should_not be_nil
1616
(/kubectl found/ =~ response_s).should_not be_nil
17+
(/git found/ =~ response_s).should_not be_nil
1718
end
1819

1920
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require "../../spec_helper"
2+
require "colorize"
3+
require "../../../src/tasks/utils/utils.cr"
4+
require "../../../src/tasks/prereqs.cr"
5+
require "../../../src/tasks/utils/system_information/git.cr"
6+
require "file_utils"
7+
require "sam"
8+
9+
describe "Git" do
10+
11+
it "'git_global_response()' should return the information about the git installation", tags: "git-prereq" do
12+
(git_global_response(true)).should contain("git version")
13+
end
14+
15+
it "'git_local_response()' should return the information about the git installation", tags: "git-prereq" do
16+
(git_local_response(true)).should eq("")
17+
end
18+
19+
it "'git_version()' should return the information about the git version", tags: "git-prereq" do
20+
(git_version(git_global_response)).should match(/(([0-9]{1,3}[\.]){1,2}[0-9]{1,3})/)
21+
(git_version(git_local_response)).should contain("")
22+
end
23+
24+
it "'git_installations()' should return the information about the git installation", tags: "git-prereq" do
25+
(git_installation(true)).should contain("git found")
26+
end
27+
end

src/tasks/prereqs.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ require "./utils/system_information/helm.cr"
66
require "./utils/system_information/wget.cr"
77
require "./utils/system_information/curl.cr"
88
require "./utils/system_information/kubectl.cr"
9+
require "./utils/system_information/git.cr"
910

1011
task "prereqs" do |_, args|
1112
if helm_installation.includes?("helm found") &&
1213
wget_installation.includes?("wget found") &&
1314
curl_installation.includes?("curl found") &&
14-
kubectl_installation.includes?("kubectl found")
15+
kubectl_installation.includes?("kubectl found") &&
16+
git_installation.includes?("git found")
1517
stdout_success "All prerequisites found."
1618
else
1719
stdout_failure "Setup failed. Some prerequisites are missing. Please install all of the prerequisites before continuing."
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require "file_utils"
2+
require "colorize"
3+
require "totem"
4+
5+
def git_installation(verbose=false)
6+
gmsg = "No Global git version found"
7+
lmsg = "No Local git version found"
8+
ggit = git_global_response
9+
VERBOSE_LOGGING.info ggit if verbose
10+
11+
global_git_version = git_version(ggit, verbose)
12+
13+
if !global_git_version.empty?
14+
gmsg = "Global git found. Version: #{global_git_version}"
15+
stdout_success gmsg
16+
else
17+
stdout_warning gmsg
18+
end
19+
20+
lgit = git_local_response
21+
VERBOSE_LOGGING.info lgit if verbose
22+
23+
local_git_version = git_version(lgit, verbose)
24+
25+
if !local_git_version.empty?
26+
lmsg = "Local git found. Version: #{local_git_version}"
27+
stdout_success lmsg
28+
else
29+
stdout_warning lmsg
30+
end
31+
32+
# uncomment to fail the installation check
33+
# global_git_version = nil
34+
# local_git_version = nil
35+
# gmsg = "No Global git version found"
36+
# lmsg = "No Local git version found"
37+
if !(global_git_version && local_git_version)
38+
stdout_failure "Git not found"
39+
stdout_failure %Q(
40+
Linux installation instructions for Git can be found here: https://github.com/git-guides/install-git
41+
42+
Install git binary with curl on Linux
43+
44+
On Debian/Ubuntu:
45+
46+
sudo apt-get install git-all
47+
48+
On Fedora
49+
50+
sudo dnf install git-all
51+
)
52+
end
53+
"#{lmsg} #{gmsg}"
54+
end
55+
56+
def git_global_response(verbose=false)
57+
git_response = `git version`
58+
VERBOSE_LOGGING.info git_response if verbose
59+
git_response
60+
end
61+
62+
def git_local_response(verbose=false)
63+
current_dir = FileUtils.pwd
64+
VERBOSE_LOGGING.info current_dir if verbose
65+
git = "#{current_dir}/#{TOOLS_DIR}/git/linux-amd64/git"
66+
# git_response = `#{git} version`
67+
status = Process.run("#{git} version", shell: true, output: git_response = IO::Memory.new, error: stderr = IO::Memory.new)
68+
VERBOSE_LOGGING.info git_response.to_s if verbose
69+
git_response.to_s
70+
end
71+
72+
def git_version(git_response, verbose=false)
73+
# example
74+
# git version 1.9.1
75+
resp = git_response.match /git version (([0-9]{1,3}[\.]){1,2}[0-9]{1,3})/
76+
VERBOSE_LOGGING.info resp if verbose
77+
if resp
78+
"#{resp && resp.not_nil![1]}"
79+
else
80+
""
81+
end
82+
end

0 commit comments

Comments
 (0)