-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
130 lines (101 loc) · 5.36 KB
/
Copy pathRakefile
File metadata and controls
130 lines (101 loc) · 5.36 KB
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
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require_relative 'lib/dfe/reference_data'
require_relative 'lib/dfe/reference_data/bigquery/importer'
require_relative 'lib/dfe/reference_data/bigquery/converter'
require_relative 'lib/dfe/reference_data/dqt/degree_types'
require_relative 'lib/dfe/reference_data/helpers/v2/country_list_compiler'
RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task default: %i[rubocop install spec]
desc 'Generate lib/dfe/reference_data/cah.rb from downloaded CSVs'
task :import_cah_mappings do
sh 'bin/import_cah_mappings'
end
desc 'Pull new bank holidays from GOV_UK_BANK_HOLIDAYS_URL and update raw data and constants'
task :update_bank_holidays do
new_records = DfE::ReferenceData::Generators::BankHolidays.download_latest_file
if new_records.empty?
puts 'No new bank holidays found.'
else
puts "#{new_records.size} new bank holiday(s) added:"
new_records.each { |r| puts " #{r['date']} #{r['title']}" }
DfE::ReferenceData::Generators::BankHolidays.generate_bank_holidays_data_from_raw_data
puts 'lib/dfe/reference_data/bank_holidays.rb updated.'
end
end
desc 'Prepare a new version for release, version can be major, minor, patch or x.y.z (as per gem-release gem)'
task :prepare_release, %i[version] do |_, args|
bump_version = args.fetch(:version)
current_branch = `git branch --show-current`.chomp
raise 'could not get current branch' if current_branch.empty?
sh 'git', 'checkout', '-b', "v#{bump_version}" if current_branch == 'main'
sh 'gem', 'bump', '-v', bump_version, '--no-commit', '--file', 'lib/dfe/reference_data/version.rb'
version = `bundle exec ruby -e 'puts DfE::ReferenceData::VERSION'`.chomp
raise 'could not retrieve version' if version.empty?
v_version = "v#{version}"
sh 'bundle', 'exec', 'github_changelog_generator', '--no-verbose', '--user', 'DFE-Digital', '--project', 'dfe-reference-data', '--output', 'CHANGELOG.md', '--future-release', v_version
sh 'git', 'commit', '-a', '-m', v_version
puts <<~EOMESSAGE
Release #{v_version} is almost ready! Before you push:
- Check that the CHANGELOG.md has no empty sections with no changes listed,
duplicate version numbers (e.g. two v1.5.1 entries) or non-version entries
(e.g. "push"). There should also only typically be a section added for the
latest version being cut, and no changes to previous entries.
git show -- CHANGELOG.md
EOMESSAGE
end
# Update the docs in docs/bigquery.md to reflect any changes to this list:
BIGQUERY_TABLES = [
['qualifications', DfE::ReferenceData::Qualifications::QUALIFICATIONS],
['degree_grades', DfE::ReferenceData::Degrees::GRADES],
['degree_institutions', DfE::ReferenceData::Degrees::INSTITUTIONS],
['degree_subjects', DfE::ReferenceData::Degrees::SUBJECTS_INCLUDING_GENERICS],
['degree_types', DfE::ReferenceData::Degrees::ALL_TYPES],
['itt_subjects', DfE::ReferenceData::ITT::SUBJECTS],
['itt_incentives', DfE::ReferenceData::ITT::INCENTIVES],
['itt_categories', DfE::ReferenceData::ITT::CATEGORIES],
['itt_publish_categories', DfE::ReferenceData::ITT::PUBLISH_CATEGORIES],
['itt_register_categories', DfE::ReferenceData::ITT::REGISTER_CATEGORIES],
['itt_tad_categories', DfE::ReferenceData::ITT::TAD_CATEGORIES],
['itt_cycles', DfE::ReferenceData::ITT::CYCLES],
['ead_disabilities_and_health_conditions', DfE::ReferenceData::EqualityAndDiversity::DISABILITIES_AND_HEALTH_CONDITIONS],
['cah_categories_l1', DfE::ReferenceData::CommonAggregationHierarchy::CAH_CATEGORIES_L1],
['cah_categories_l2', DfE::ReferenceData::CommonAggregationHierarchy::CAH_CATEGORIES_L2],
['cah_categories_l3', DfE::ReferenceData::CommonAggregationHierarchy::CAH_CATEGORIES_L3],
['hecos_cah_subject_mappings', DfE::ReferenceData::CommonAggregationHierarchy::HECOS_CAH_SUBJECT_MAPPINGS],
['bank_holidays', DfE::ReferenceData::BankHolidays::BANK_HOLIDAYS]
].freeze
desc 'Insert records into BigQuery tables from the reference data lists'
task :update_bigquery_tables do
DfE::ReferenceData::BigQuery::Config.configure do |config|
config.project = ENV['BIGQUERY_PROJECT'] || 'cross-teacher-services'
config.dataset = ENV['BIGQUERY_DATASET'] || 'dfe_reference_data_dev'
config.tables = BIGQUERY_TABLES
config.version = `bundle exec ruby -e 'puts DfE::ReferenceData::VERSION'`.chomp
config.commit = `git rev-parse HEAD`.chomp
# Suffix table names with '_latest' to push to the same table
config.table_name_suffix = '_latest'
puts "Updating #{config.project}.#{config.dataset} with version #{config.version}:"
end
DfE::ReferenceData::BigQuery.update_tables
end
desc 'Convert reference data to SQLite'
task :convert_to_sqlite do
version = DfE::ReferenceData::VERSION
output_file = File.join(__dir__, 'reference_data.sqlite3')
versioned_output_file = output_file.sub('.sqlite3', "_v#{version}.sqlite3")
DfE::ReferenceData::BigQuery::Converter.convert_to_sqlite(versioned_output_file, BIGQUERY_TABLES)
end
namespace :v2 do
desc 'Generate countries hash entries - one off script'
task :generate_countries_hash do
DfE::ReferenceData::Helpers::V2::CountryListCompiler.new.generate_countries_hash
end
desc 'Generate territories hash entries - one off script'
task :generate_territories_hash do
DfE::ReferenceData::Helpers::V2::CountryListCompiler.new.generate_territories_hash
end
end