-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
182 lines (160 loc) · 4.46 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
require 'bundler/setup'
require 'csv'
require 'fileutils'
require 'json'
require 'open-uri'
require 'pp'
require 'set'
require 'colored'
require 'faraday'
require 'octokit'
require 'safe_yaml'
SafeYAML::OPTIONS[:default_mode] = :safe
PROFILES = [
'eforms',
'european-union',
'government-procurement-agreement',
'public-private-partnerships',
]
TEMPLATES = [
'standard_extension_template',
'standard_profile_template',
]
SPECIFICATIONS = [
'infrastructure',
'ocds-extensions',
'standard',
]
guides = [
'ocds-kibana-manual',
'ocds-r-manual',
'sample-data',
]
extension_tools = [
'extension-explorer',
'extension_creator',
'extension_registry',
'extension_registry.py',
'ocds-extensions-translations',
]
internal_tools = [
'collect-generic',
'data-support',
'deploy',
'editor-tools',
'field-level-mapping-template',
'jscc',
'json-schema-random',
'notebooks-ocds',
'notebooks-oc4ids',
'scrapy-log-analyzer',
'software-development-handbook',
'standard-development-handbook',
'standard-maintenance-scripts',
'yapw',
]
DOCUMENTATION_DEPENDENCIES = [
'docson',
'european-union-support',
'ocds-babel',
'ocds-index',
'sphinxcontrib-opencontracting',
'standard_theme',
]
non_tools = SPECIFICATIONS + guides + DOCUMENTATION_DEPENDENCIES
REPOSITORY_CATEGORIES = {
'Specifications' => -> (repo) { specification?(repo.name) },
'Guides' => -> (repo) { guides.include?(repo.name) },
'Tools' => -> (repo) { !extension?(repo.name) && !extension_tools.include?(repo.name) && !internal_tools.include?(repo.name) && !non_tools.include?(repo.name) },
'Extension tools' => -> (repo) { extension_tools.include?(repo.name) },
'Internal tools' => -> (repo) { internal_tools.include?(repo.name) },
'Documentation dependencies' => -> (repo) { DOCUMENTATION_DEPENDENCIES.include?(repo.name) },
'Templates' => -> (repo) { template?(repo.name) },
'Profiles' => -> (repo) { profile?(repo.name) },
'Extensions' => -> (repo) { extension?(repo.name, profiles: false, templates: false) },
}
def client
@client ||= begin
client = Octokit::Client.new(netrc: true)
client.login
client
end
end
def organizations
@organizations ||= begin
if ENV['ORGS']
ENV['ORGS'].split(',')
elsif ENV['ORG']
[ENV['ORG']]
else
['open-contracting', 'open-contracting-extensions']
end
end
end
def repos
@repos ||= begin
organizations.reduce([]) do |memo, organization|
repos = client.org_repos(organization, per_page: 100, accept: 'application/vnd.github.drax-preview+json') # licenses
if ENV['REPOS']
memo + repos.select{ |repo| ENV['REPOS'].split(',').include?(repo.full_name) }
else
memo + repos
end
end
end
end
def has_github_file(full_name, path)
begin
client.contents(full_name, path: path)
rescue Octokit::NotFound
end
end
def read_github_file(full_name, path)
begin
Base64.decode64(client.contents(full_name, path: path).content)
rescue Octokit::NotFound
''
end
end
def profile?(name)
PROFILES.include?(name)
end
def template?(name)
TEMPLATES.include?(name)
end
def specification?(name)
SPECIFICATIONS.include?(name)
end
def extension?(name, profiles: true, templates: true)
name.start_with?('ocds_') && name.end_with?('_extension') || profiles && profile?(name) || templates && template?(name)
end
def variables(*keys)
keys.map do |key|
value = ENV[key]
if value.nil? || value.empty?
abort "usage: rake #{ARGV[0]} #{keys.map{ |key| "#{key}=value" }.join(' ')}"
end
value
end
end
def core_extensions
@core_extensions ||= begin
base_url = 'https://raw.githubusercontent.com/open-contracting/extension_registry/main/'
ids_to_repos = {}
CSV.parse(URI.open("#{base_url}/extension_versions.csv").read, headers: true).each do |version|
parts = URI.parse(version.fetch('Base URL'))
# Assumes different versions of the same extension use the same repository.
if ['bitbucket.org', 'gitlab.com', 'raw.githubusercontent.com'].include?(parts.hostname)
ids_to_repos[version.fetch('Id')] = parts.path.split('/')[1..2].join('/')
else
raise "#{parts.hostname} not supported (#{version['Id']})"
end
end
repos_to_core = {}
CSV.parse(URI.open("#{base_url}/extensions.csv").read, headers: true).each do |extension|
repos_to_core[ids_to_repos.fetch(extension.fetch('Id'))] = extension.fetch('Core') == 'true'
end
repos_to_core
end
end
Dir['tasks/*.rake'].each { |r| import r }