Skip to content

Commit

Permalink
Merge pull request #126 from DFE-Digital/sql-artifact
Browse files Browse the repository at this point in the history
Release a Sql artifact
  • Loading branch information
goodviber authored Nov 20, 2024
2 parents 5ce64bb + f98cce0 commit a9af3f8
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.0
ruby-version: 3.2.0
bundler-cache: true
- name: Run linters with autofix
run: bundle exec rubocop --auto-correct-all
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7.0'
ruby-version: '3.2.0'
bundler-cache: true
- name: Install SQLite3 Gem
run: gem install sqlite3 -v '~> 1.4.0'
Expand All @@ -22,8 +22,7 @@ jobs:
BIGQUERY_DATASET: dfe_reference_data
- name: Convert Reference Data to SQLite
run: bundle exec rake convert_to_sqlite
- name: Upload SQLite Database
uses: actions/upload-artifact@v4
with:
name: reference_data_db_${{ github.ref_name }}
path: reference_data_${{ github.ref_name }}.db
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create ${{ github.ref_name }} reference_data_${{ github.ref_name }}.sqlite3 --notes "Reference data for ${{ github.ref_name }}"
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
ruby:
- '2.7.0'
- '3.2.0'

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Metrics/ModuleLength:

AllCops:
NewCops: enable
TargetRubyVersion: 2.7.0
TargetRubyVersion: 3.1.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ If the master data being in Ruby becomes a bottleneck (eg, because non-Ruby-conf
Until we sort out our RubyGems account, dependents will pull the gem from GitHub. The process is:

- Run `rake prepare_release[minor|major|patch|pre|<specific version number>]` (note those are literal square brackets, eg `prepare_release[1.0.0]`) to bump the version number in `lib/dfe/reference_data/version.rb`
- Update `CHANGELOG.md`, following the existing pattern
- Check the `CHANGELOG.md`, follows the existing pattern
- Add any upgrade notes for breaking changes to the bottom of this file
- Run `rake tag_and_push_release` to prepare and tag a release commit and push it to github
- Mark a Github release by going to https://github.com/DFE-Digital/dfe-reference-data/releases
- A release will be generated with a SQLite artifact at https://github.com/DFE-Digital/dfe-reference-data/releases

# History

Expand Down
21 changes: 16 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ task :prepare_release, %i[version] do |_, args|
version = `bundle exec ruby -e 'puts DfE::ReferenceData::VERSION'`.chomp
raise 'could not retrieve version' if version.empty?

# v_version = "v#{version}"
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

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
# This thing gets horribly confused sometimes, let's do it by hand
# sh 'bundle', 'exec', 'github_changelog_generator', '--no-verbose', '--user', 'DFE-Digital', '--project', 'dfe-reference-data', '--output', 'CHANGELOG.md', '--future-release', v_version
EOMESSAGE
end

desc 'Commit current changes (eg, the changes made by prepare_release and any upgrade notes written to README.md), tag, and push to origin'
Expand Down Expand Up @@ -95,7 +106,7 @@ end
desc 'Convert reference data to SQLite'
task :convert_to_sqlite do
version = DfE::ReferenceData::VERSION
output_file = File.join(__dir__, 'reference_data.db')
versioned_output_file = output_file.sub('.db', "_v#{version}.db")
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
4 changes: 2 additions & 2 deletions bin/import_cah_mappings
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ begin
l3 = row['CAH3_Code']
l3_label = row['CAH3_Label']

cah_l3[l3] = { name: l3_label, l1: l1, l2: l2 }
cah_l3[l3] = { name: l3_label, l1:, l2: }

if cah_l2.key?(l2)
cah_l2[l2][:l3_children].add(l3)
else
cah_l2[l2] = { name: l2_label, l1: l1, l3_children: Set[l3] }
cah_l2[l2] = { name: l2_label, l1:, l3_children: Set[l3] }
end

if cah_l1.key?(l1)
Expand Down
2 changes: 1 addition & 1 deletion dfe-reference-data.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require_relative 'lib/dfe/reference_data/version'

require 'English'
Gem::Specification.new do |s|
s.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
s.required_ruby_version = Gem::Requirement.new('>= 3.1.0')
s.name = 'dfe-reference-data'
s.version = DfE::ReferenceData::VERSION
s.summary = 'Reference data for Department for Education services'
Expand Down
14 changes: 7 additions & 7 deletions lib/dfe/reference_data/bigquery/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ def kind(field_schema)
def bigquery_schema_create_field(schema, name, description, field_schema, mode)
case kind(field_schema)
when :code
schema.string name, description: description, mode: mode
schema.string name, description:, mode:
when :string
schema.string name, description: description, mode: mode
schema.string name, description:, mode:
when :symbol
schema.string name, description: description, mode: mode
schema.string name, description:, mode:
when :boolean
schema.boolean name, description: description, mode: mode
schema.boolean name, description:, mode:
when :integer
schema.integer name, description: description, mode: mode
schema.integer name, description:, mode:
when :real
schema.float name, description: description, mode: mode
schema.float name, description:, mode:
when :datetime
schema.datetime name, description: description, mode: mode
schema.datetime name, description:, mode:
when :daterange
schema.record name, description: description, mode: mode do |recordschema|
recordschema.date 'begin', mode: :required
Expand Down
12 changes: 6 additions & 6 deletions lib/dfe/reference_data/hardcoded_reference_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def initialize(data, schema: nil, list_description: nil, list_usage_guidance: ni
@data = {}

data.each_entry do |id, record|
@data[id] = Record.new(record.merge({ id: id }))
@data[id] = Record.new(record.merge({ id: }))
end

super(schema: schema,
list_description: list_description,
list_usage_guidance: list_usage_guidance,
list_docs_url: list_docs_url,
field_descriptions: field_descriptions)
super(schema:,
list_description:,
list_usage_guidance:,
list_docs_url:,
field_descriptions:)
end
# rubocop:enable Metrics/ParameterLists

Expand Down
2 changes: 1 addition & 1 deletion lib/dfe/reference_data/helpers/sqlite_conversion_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def convert_basic_type_for_sqlite(value)
end

def convert_to_sqlite_type(field_type)
case field_type.to_s.downcase # Convert both symbols and strings to lowercase strings
case field_type.to_s.downcase # Convert both symbols and strings to lowercase strings
when 'boolean', 'integer'
'INTEGER'
else
Expand Down
10 changes: 5 additions & 5 deletions lib/dfe/reference_data/joined_reference_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def initialize(lists, schema: nil, list_description: nil, list_usage_guidance: n

@lists = lists

super(schema: schema,
list_description: list_description,
list_usage_guidance: list_usage_guidance,
list_docs_url: list_docs_url,
field_descriptions: field_descriptions)
super(schema:,
list_description:,
list_usage_guidance:,
list_docs_url:,
field_descriptions:)
end
# rubocop:enable Metrics/ParameterLists

Expand Down
12 changes: 6 additions & 6 deletions lib/dfe/reference_data/tweaked_reference_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def initialize(base, overrides, schema: nil, list_description: nil, list_usage_g
schema = base.schema
end

super(schema: schema,
list_description: list_description,
list_usage_guidance: list_usage_guidance,
list_docs_url: list_docs_url,
field_descriptions: field_descriptions)
super(schema:,
list_description:,
list_usage_guidance:,
list_docs_url:,
field_descriptions:)

@base = base
@overrides = overrides
Expand All @@ -50,7 +50,7 @@ def all_as_hash
elsif (existing = new_all[id])
new_all[id] = existing.merge(override)
else
new_all[id] = Record.new(override.merge({ id: id }))
new_all[id] = Record.new(override.merge({ id: }))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/dfe/reference_data/bigquery/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end

let(:version) { DfE::ReferenceData::VERSION }
let(:versioned_output_file) { "reference_data_v#{version}.db" }
let(:versioned_output_file) { "reference_data_v#{version}.sqlite3" }

before do
allow($stdout).to receive(:puts)
Expand Down

0 comments on commit a9af3f8

Please sign in to comment.