git-maintain 0.12.0 → 0.14.2
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/CHANGELOG +23 -0
- data/README.md +14 -14
- data/bin/git-maintain +7 -55
- data/git-maintain-completion.sh +1 -1
- data/lib/{addons → git-maintain/addons}/RDMACore.rb +79 -20
- data/lib/{addons → git-maintain/addons}/git-maintain.rb +61 -6
- data/lib/git-maintain/addons/healthd.rb +73 -0
- data/lib/git-maintain/addons/hpc-testing.rb +102 -0
- data/lib/git-maintain/azure.rb +200 -0
- data/lib/{branch.rb → git-maintain/branch.rb} +356 -237
- data/lib/git-maintain/branch_iterator.rb +148 -0
- data/lib/git-maintain/ci.rb +163 -0
- data/lib/git-maintain/common.rb +117 -0
- data/lib/git-maintain/error.rb +81 -0
- data/lib/{repo.rb → git-maintain/repo.rb} +199 -104
- data/lib/git-maintain/travis.rb +179 -0
- data/lib/git-maintain.rb +2 -0
- metadata +30 -14
- data/lib/azure.rb +0 -98
- data/lib/ci.rb +0 -88
- data/lib/common.rb +0 -259
- data/lib/travis.rb +0 -80
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Module containing addon classes for hpc-testing repository.
|
|
2
|
+
module GitMaintain
|
|
3
|
+
|
|
4
|
+
# Subclass of Branch customized for the hpc-testing repository.
|
|
5
|
+
class HPCTestingBranch < Branch
|
|
6
|
+
# The name of this repository.
|
|
7
|
+
REPO_NAME = "hpc-testing"
|
|
8
|
+
|
|
9
|
+
# Configure hpc-testing release options.
|
|
10
|
+
#
|
|
11
|
+
# @param action [Symbol] Selected action name
|
|
12
|
+
# @param optsParser [OptionParser] The OptionParser instance
|
|
13
|
+
# @param opts [Hash] The options hash to populate
|
|
14
|
+
def self.set_opts(action, optsParser, opts)
|
|
15
|
+
opts[:auto_news] = false
|
|
16
|
+
|
|
17
|
+
case action
|
|
18
|
+
when :release
|
|
19
|
+
optsParser.on("--auto-news", "Auto-generate NEWS entries.") {
|
|
20
|
+
opts[:auto_news] = true }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Create a new release for hpc-testing.
|
|
25
|
+
# Updates spec files, NEWS, commits, and tags the release.
|
|
26
|
+
#
|
|
27
|
+
# @param opts [Hash] Options hash
|
|
28
|
+
# @raise [GitMaintainError] If prepping, committing, or tagging fails
|
|
29
|
+
def release(opts)
|
|
30
|
+
prev_ver=@repo.runGit("show HEAD:rpm/hpc-testing.spec | grep Version: | awk '{ print $NF}'").
|
|
31
|
+
chomp()
|
|
32
|
+
ver_nums = prev_ver.split(".")
|
|
33
|
+
|
|
34
|
+
if opts[:manual_branch] == nil then
|
|
35
|
+
new_ver = (ver_nums[0 .. -2] + [ver_nums[-1].to_i() + 1 ]).join(".")
|
|
36
|
+
git_prev_ver = "v" + (ver_nums[-1] == "0" ? ver_nums[0 .. -2].join(".") : prev_ver)
|
|
37
|
+
else
|
|
38
|
+
new_ver = (ver_nums[0 .. -3] + [ver_nums[-2].to_i() + 1 ] + [ "0" ]).join(".")
|
|
39
|
+
git_prev_ver = "v" + prev_ver
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
puts "Preparing release #{prev_ver} => #{new_ver}"
|
|
43
|
+
rep = checkLog(opts, @local_branch, git_prev_ver, "release")
|
|
44
|
+
if rep != "y" then
|
|
45
|
+
puts "Skipping release"
|
|
46
|
+
return
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Prepare tag message
|
|
50
|
+
tag_path=`mktemp`.chomp()
|
|
51
|
+
puts tag_path
|
|
52
|
+
tag_file = File.open(tag_path, "w+")
|
|
53
|
+
tag_file.puts "hpc-testing-#{new_ver}"
|
|
54
|
+
tag_file.puts ""
|
|
55
|
+
tag_file.puts `git log HEAD ^#{git_prev_ver} --no-merges --format=' * %s'`
|
|
56
|
+
tag_file.close()
|
|
57
|
+
|
|
58
|
+
# Update version number in relevant files
|
|
59
|
+
@repo.run("sed -i -e 's/\\(Version:[[:space:]]*\\)[0-9.]*/\\1#{new_ver}/g' rpm/hpc-testing.spec")
|
|
60
|
+
|
|
61
|
+
news_entries = ""
|
|
62
|
+
if opts[:auto_news] == true then
|
|
63
|
+
news_entries = "\n" + @repo.runGit("log HEAD ^#{git_prev_ver} --no-merges --format=' * %s'")
|
|
64
|
+
end
|
|
65
|
+
@repo.run("cat <<EOF > NEWS.new
|
|
66
|
+
- hpc-testing #{new_ver}#{news_entries}
|
|
67
|
+
$(cat NEWS)
|
|
68
|
+
EOF
|
|
69
|
+
mv NEWS.new NEWS")
|
|
70
|
+
|
|
71
|
+
release_do_add_commit_tag(opts, ["rpm/hpc-testing.spec", "NEWS"], "v" + new_ver, tag_path)
|
|
72
|
+
`rm -f #{tag_path}`
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Initialize HPCTestingBranch, forcing NO_CI to true.
|
|
76
|
+
#
|
|
77
|
+
# @param repo [Repo] The Repo instance
|
|
78
|
+
# @param version [String] Suffix version or branch name
|
|
79
|
+
# @param ci [CI] The CI instance
|
|
80
|
+
# @param branch_suff [String] Branch suffix
|
|
81
|
+
# @raise [NoRefError] If resolving git references fails
|
|
82
|
+
def initialize(repo, version, ci, branch_suff)
|
|
83
|
+
super(repo, version, ci, branch_suff)
|
|
84
|
+
@NO_CI = true
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Repo class customized for the hpc-testing repository.
|
|
89
|
+
class HPCTestingRepo < Repo
|
|
90
|
+
# Initialize HPCTestingRepo with release notifications disabled.
|
|
91
|
+
#
|
|
92
|
+
# @param path [String] Repository directory path
|
|
93
|
+
def initialize(path)
|
|
94
|
+
super(path)
|
|
95
|
+
@NOTIFY_RELEASE = false
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
GitMaintain::registerCustom(HPCTestingBranch::REPO_NAME,
|
|
99
|
+
{ GitMaintain::Branch => HPCTestingBranch,
|
|
100
|
+
GitMaintain::Repo => HPCTestingRepo,
|
|
101
|
+
GitMaintain::CI => GitMaintain::TravisCI})
|
|
102
|
+
end
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Main module for git-maintain repository maintenance tool.
|
|
2
|
+
module GitMaintain
|
|
3
|
+
# CI adapter class for Azure DevOps Pipelines integration.
|
|
4
|
+
class AzureCI < CI
|
|
5
|
+
# Base URL for Azure DevOps services.
|
|
6
|
+
AZURE_URL='https://dev.azure.com/'
|
|
7
|
+
|
|
8
|
+
# Initialize the AzureCI adapter.
|
|
9
|
+
#
|
|
10
|
+
# @param repo [Repo] The Repo instance
|
|
11
|
+
# @param stable [String] Name of the stable Azure DevOps organization
|
|
12
|
+
# @param valid [String] Name of the validation Azure DevOps organization
|
|
13
|
+
def initialize(repo, stable='', valid='')
|
|
14
|
+
super(repo)
|
|
15
|
+
@url = AZURE_URL
|
|
16
|
+
@stable_org=stable
|
|
17
|
+
@valid_org=valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
# Get the Azure build status string for a specific commit SHA.
|
|
22
|
+
#
|
|
23
|
+
# @param sha1 [String] Commit SHA
|
|
24
|
+
# @param resp [Hash] API response payload containing builds
|
|
25
|
+
# @return [String] Build status string (e.g. 'succeeded', 'started', 'failed')
|
|
26
|
+
def getState(sha1, resp)
|
|
27
|
+
br = findBranch(sha1, resp)
|
|
28
|
+
return "not found" if br == nil
|
|
29
|
+
return "started" if br["result"] == nil
|
|
30
|
+
return br["result"].to_s()
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Retrieve the build logs from Azure DevOps.
|
|
34
|
+
#
|
|
35
|
+
# @param sha1 [String] Commit SHA
|
|
36
|
+
# @param resp [Hash] API response payload
|
|
37
|
+
# @return [String] Empty string placeholder (log fetching is handled by Azure pipelines)
|
|
38
|
+
def getLog(sha1, resp)
|
|
39
|
+
str=""
|
|
40
|
+
# br = findBranch(sha1, resp)
|
|
41
|
+
# raise("Travis build not found") if br == nil
|
|
42
|
+
# job_id = br["id"].to_s()
|
|
43
|
+
# logs= getJson(@url, "azure_log_list" + job_id,
|
|
44
|
+
# @repo.name + "/_apis/build/builds/#{job_id}/logs?api-version=5.1")
|
|
45
|
+
# 1.upto(logs["count"]) { |x|
|
|
46
|
+
# log(:DEBUG_CI, "Downloading log file #{x}/#{logs["count"]}")
|
|
47
|
+
# nzstr = getJson(@url, "azure_log_" + job_id + '_' + x.to_s(),
|
|
48
|
+
# @repo.name + "/_apis/build/builds/#{job_id}/logs/#{x}?api-version=5.1", false)
|
|
49
|
+
# # This is zipped. We need to extract it
|
|
50
|
+
# }
|
|
51
|
+
return str
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Get the Azure build timestamp for a specific commit SHA.
|
|
55
|
+
#
|
|
56
|
+
# @param sha1 [String] Commit SHA
|
|
57
|
+
# @param resp [Hash] API response payload
|
|
58
|
+
# @return [String] Build startTime timestamp string
|
|
59
|
+
# @raise [GitMaintainError] If no build is found for the commit
|
|
60
|
+
def getTS(sha1, resp)
|
|
61
|
+
br = findBranch(sha1, resp)
|
|
62
|
+
raise GitMaintainError.new("Travis build not found") if br == nil
|
|
63
|
+
return br["startTime"]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Check if the Azure build status string represents success.
|
|
67
|
+
#
|
|
68
|
+
# @param sha1 [String] Commit SHA
|
|
69
|
+
# @param resp [Hash] API response payload
|
|
70
|
+
# @return [Boolean] True if build succeeded or passed
|
|
71
|
+
def checkState(sha1, resp)
|
|
72
|
+
st = getState(sha1, resp)
|
|
73
|
+
return st == "passed" || st == "succeeded"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Fetch validation organization builds JSON payload from Azure DevOps API.
|
|
77
|
+
#
|
|
78
|
+
# @return [Hash] JSON API response
|
|
79
|
+
# @raise [MissingArgumentError] If validation organization is not configured
|
|
80
|
+
# @raise [GitMaintainError] If API request fails
|
|
81
|
+
def getBrValidJson()
|
|
82
|
+
raise MissingArgumentError.new("validation organisation") if @valid_org == ''
|
|
83
|
+
return getJson(@url + @valid_org + '/',
|
|
84
|
+
:azure_br_valid, @repo.name + '/_apis/build/builds?api-version=5.1')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Fetch stable organization builds JSON payload from Azure DevOps API.
|
|
88
|
+
#
|
|
89
|
+
# @return [Hash] JSON API response
|
|
90
|
+
# @raise [MissingArgumentError] If stable organization is not configured
|
|
91
|
+
# @raise [GitMaintainError] If API request fails
|
|
92
|
+
def getBrStableJson()
|
|
93
|
+
raise MissingArgumentError.new("stable organisation") if @stable_org == ''
|
|
94
|
+
return getJson(@url + @stable_org + '/',
|
|
95
|
+
:azure_br_stable, @repo.name + '/_apis/build/builds?api-version=5.1')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Find the specific Azure build matching the given commit SHA.
|
|
99
|
+
#
|
|
100
|
+
# @param sha1 [String] Commit SHA
|
|
101
|
+
# @param resp [Hash] API response builds payload
|
|
102
|
+
# @return [Hash, nil] Build dictionary, or nil if not found
|
|
103
|
+
# @raise [GitMaintainError] If API response is missing expected commit keys
|
|
104
|
+
def findBranch(sha1, resp)
|
|
105
|
+
log(:DEBUG_CI, "Looking for build for #{sha1}")
|
|
106
|
+
resp["value"].each(){|br|
|
|
107
|
+
commit= br["sourceVersion"]
|
|
108
|
+
raise GitMaintainError.new("Incomplete JSON received from Travis") if commit == nil
|
|
109
|
+
log(:DEBUG_CI, "Found entry for sha #{commit}")
|
|
110
|
+
next if commit != sha1
|
|
111
|
+
return br
|
|
112
|
+
}
|
|
113
|
+
return nil
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
public
|
|
117
|
+
# Retrieve the validation build state for a specific branch and commit.
|
|
118
|
+
#
|
|
119
|
+
# @param br [Branch] The Branch instance
|
|
120
|
+
# @param sha1 [String] Commit SHA
|
|
121
|
+
# @return [String] Build status string (e.g. 'succeeded')
|
|
122
|
+
def getValidState(br, sha1)
|
|
123
|
+
return getState(sha1, getBrValidJson())
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Check if the validation build is successful.
|
|
127
|
+
#
|
|
128
|
+
# @param br [Branch] The Branch instance
|
|
129
|
+
# @param sha1 [String] Commit SHA
|
|
130
|
+
# @return [Boolean] True if build passed
|
|
131
|
+
def checkValidState(br, sha1)
|
|
132
|
+
return checkState(sha1, getBrValidJson())
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Retrieve the validation build log.
|
|
136
|
+
#
|
|
137
|
+
# @param br [Branch] The Branch instance
|
|
138
|
+
# @param sha1 [String] Commit SHA
|
|
139
|
+
# @return [String] Build log output text
|
|
140
|
+
def getValidLog(br, sha1)
|
|
141
|
+
return getLog(sha1, getBrValidJson())
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Retrieve the validation build timestamp.
|
|
145
|
+
#
|
|
146
|
+
# @param br [Branch] The Branch instance
|
|
147
|
+
# @param sha1 [String] Commit SHA
|
|
148
|
+
# @return [String] Build timestamp
|
|
149
|
+
def getValidTS(br, sha1)
|
|
150
|
+
return getTS(sha1, getBrValidJson())
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Retrieve the stable build state for a specific branch and commit.
|
|
154
|
+
#
|
|
155
|
+
# @param br [Branch] The Branch instance
|
|
156
|
+
# @param sha1 [String] Commit SHA
|
|
157
|
+
# @return [String] Build status string (e.g. 'succeeded')
|
|
158
|
+
def getStableState(br, sha1)
|
|
159
|
+
return getState(sha1, getBrStableJson())
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Check if the stable build is successful.
|
|
163
|
+
#
|
|
164
|
+
# @param br [Branch] The Branch instance
|
|
165
|
+
# @param sha1 [String] Commit SHA
|
|
166
|
+
# @return [Boolean] True if build passed
|
|
167
|
+
def checkStableState(br, sha1)
|
|
168
|
+
return checkState(sha1, getBrStableJson())
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Retrieve the stable build log.
|
|
172
|
+
#
|
|
173
|
+
# @param br [Branch] The Branch instance
|
|
174
|
+
# @param sha1 [String] Commit SHA
|
|
175
|
+
# @return [String] Build log output text
|
|
176
|
+
def getStableLog(br, sha1)
|
|
177
|
+
return getLog(sha1, getBrStableJson())
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Retrieve the stable build timestamp.
|
|
181
|
+
#
|
|
182
|
+
# @param br [Branch] The Branch instance
|
|
183
|
+
# @param sha1 [String] Commit SHA
|
|
184
|
+
# @return [String] Build timestamp
|
|
185
|
+
def getStableTS(br, sha1)
|
|
186
|
+
return getTS(sha1, getBrStableJson())
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Check if the CI build status represents an error/failure.
|
|
190
|
+
#
|
|
191
|
+
# @param br [Branch] The Branch instance
|
|
192
|
+
# @param status [String] CI status string
|
|
193
|
+
# @return [Boolean] True if build failed
|
|
194
|
+
def isErrored(br, status)
|
|
195
|
+
# https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?
|
|
196
|
+
# view=azure-devops-rest-5.1#buildresult
|
|
197
|
+
return status == "failed"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|