Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of ci-scripts. 

5 

6ci-scripts is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11ci-scripts is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with ci-scripts. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20 

21import os 

22from ci_scripts.common import process_call 

23 

24 

25def make_sure_in_path(): 

26 """ 

27 Makes sure the ruby paths are in the system's PATH 

28 :return: None 

29 """ 

30 gemdir = os.path.join(os.path.expanduser("~"), ".gem") 

31 rubydir = os.path.join(gemdir, "ruby") 

32 for version in os.listdir(rubydir): 

33 ruby_path = os.path.join(rubydir, version, "bin") 

34 os.environ["PATH"] += ":" + ruby_path 

35 os.environ["PATH"] += ":" + os.path.join(gemdir, "bin") 

36 

37 

38def install_gem(gem: str): 

39 """ 

40 Installs a gem 

41 :param gem: The gem to install 

42 :return: None 

43 """ 

44 make_sure_in_path() 

45 process_call(["gem", "install", gem]) 

46 

47 

48def rubocop_test(): 

49 """ 

50 Tests the style of the ruby project using rubocop 

51 :return: None 

52 """ 

53 install_gem("rubocop") 

54 process_call(["rubocop"]) 

55 

56 

57def rdoc(): 

58 """ 

59 Creates documentation using rdoc and rsync it for use in progstats 

60 :return: None 

61 """ 

62 install_gem("rdoc") 

63 process_call(["rdoc", "--exclude=virtual"]) 

64 

65 destination = os.environ["PROGSTATS_DATA_PATH"] 

66 project = os.environ["CI_PROJECT_NAME"] 

67 dest = os.path.join(destination, "doc_html", project) 

68 

69 process_call(["rsync", "-a", "--delete-after", "doc/", dest]) 

70 

71 

72def gem_build(): 

73 """ 

74 Builds gem for project 

75 :return: None 

76 """ 

77 if not os.path.isdir("artifacts"): 

78 os.mkdir("artifacts") 

79 

80 project = os.environ["CI_PROJECT_NAME"] 

81 

82 process_call(["gem", "build", project + ".gemspec"]) 

83 

84 for child in os.listdir("."): 

85 if child.endswith(".gem"): 

86 os.rename(child, os.path.join("artifacts", child)) 

87 

88 

89def gem_publish(): 

90 """ 

91 Publishes a gem 

92 :return: None 

93 """ 

94 gemdir = os.path.join(os.path.expanduser("~"), ".gem") 

95 if not os.path.isdir(gemdir): 

96 os.mkdir(gemdir) 

97 

98 cred_file = os.path.join(gemdir, "credentials") 

99 with open(cred_file, "w") as f: 

100 f.write(os.environ["RUBYGEMS_CREDENTIALS"]) 

101 process_call(["chmod", "0600", cred_file]) 

102 

103 for gemfile in os.listdir("artifacts"): 

104 if gemfile.endswith(".gem"): 

105 process_call(["gem", "push", os.path.join("artifacts", gemfile)]) 

106 

107 os.remove(cred_file)