gov.uk content schemas tech monthly may 2015

42
GOV.UK Tech Monthly - Publishing 2.0 team 29th May 2015 David Heath Developer @dgheath21

Upload: david-heath

Post on 15-Aug-2015

86 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Gov.uk content schemas   tech monthly may 2015

GOV.UK Tech Monthly - Publishing 2.0 team29th May 2015

David HeathDeveloper@dgheath21

Page 2: Gov.uk content schemas   tech monthly may 2015

GOV.UK Content

Schemas

GOV.UKDavid Heath

Page 3: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

What’s it for?

David Heath

Page 4: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

What’s it for?- confidence

David Heath

Page 5: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

What’s it for?- confidence- go faster

David Heath

Page 6: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

Publishing pipeline overview

David Heath

Page 7: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

JSON JSON

{ “base_path”: ..., …}

{ “base_path”: ..., …}

Page 8: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

JSON JSON

{ “base_path”: ..., …}

{ “base_path”: ..., …}Transformation

Page 9: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Metadata

Details

Links

Content item{ base_path: format: public_updated_at: details: { ... }, links: { … }}

Page 10: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher

"required": [ "publishing_app", "rendering_app", "update_type", "format", "locale", "public_updated_at" ],

Frontend

"required": [ "base_path", "format", "locale", "public_updated_at" ],

Metadata changes

Page 11: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher Frontend

content_id currently optional (maybe required in future)

Absent

routes Routes (must be within base_path)

Absent

redirects Only for format==’redirect’ Absent

Page 12: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Links expansion (publisher)“links”: { “lead_organisations”: [ “ab517cc2-80df-48f2-8325-1b8af95b8f71” ]}

Page 13: Gov.uk content schemas   tech monthly may 2015

Links expansion (frontend)“links”: { “lead_organisations”: [ { "title": "Department for International Development", "base_path": "/government/organisations/dfid", "api_url": "https://www.gov.uk/api/organisations/dfid", "web_url": "https://www.gov.uk/government/organisations/dfid", "locale": "en" } ]}

@bradwright - GOV.UKGOV.UKDavid Heath

Page 14: Gov.uk content schemas   tech monthly may 2015

Details hash

stays the same :-)

@bradwright - GOV.UKGOV.UKDavid Heath

Page 15: Gov.uk content schemas   tech monthly may 2015

Content item transformation{ base_path: format: public_updated_at: details: { ... }, links: { … }}

@bradwright - GOV.UKGOV.UKDavid Heath

Metadata (fields change)

Details (stays same)

Links (expanded)

Page 16: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

How can we test this?

David Heath

Page 17: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

Page 18: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app FrontendContent

store

Page 19: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Test that this produces the right output

Test that this works with a variety of valid inputs

Page 20: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Page 21: Gov.uk content schemas   tech monthly may 2015

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Page 22: Gov.uk content schemas   tech monthly may 2015

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

Page 23: Gov.uk content schemas   tech monthly may 2015

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

Page 24: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

govuk-content-schemas

Page 25: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Page 26: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

details.json

metadata.json

links.jsonpublisher/schema.json

frontend/ schema.json

curated examplescurated examples

combine_publisher_schema

generate_frontend_schema

validate;

ensure_example_base_paths_unique

validated examples

Build process (Makefile)

Page 27: Gov.uk content schemas   tech monthly may 2015

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

Page 28: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testjenkins-schema.sh

# Clone govuk-content-schemas dependency for contract testsrm -rf tmp/govuk-content-schemasgit clone [email protected]:alphagov/govuk-content-schemas.git \ tmp/govuk-content-schemascd tmp/govuk-content-schemasgit checkout $SCHEMA_GIT_COMMITcd ../..

# Run teststime bundle install --path "${HOME}/bundles/${JOB_NAME}" --deploymentRAILS_ENV=test GOVUK_CONTENT_SCHEMAS_PATH=tmp/govuk-content-schemas time bundle exec rake test:publishing_schemas --trace

Page 29: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testtest_publishing_schemas.rake

namespace :test do Rake::TestTask.new(:publishing_schemas => "test:prepare") do |t| t.libs << 'test' t.test_files = FileList['test/unit/presenters/publishing_api_presenters/*_test.rb'] end Rake::Task['test:publishing_schemas'].comment = "Test publishing API presenters against external schemas"end

Page 30: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testtest/unit/presenters/publishing_api_presenters/case_study_test.rb

test "links hash includes world locations" do location = create(:world_location) case_study = create(:published_case_study, world_locations: [location]) presented_hash = present(case_study) assert_valid_against_schema(presented_hash, 'case_study') assert_equal [location.content_id], presented_hash[:links][:world_locations]end

Page 31: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher test- use govuk-content-schema-test-helpers- define jenkins-schema.sh- contract tests should ideally be stand-

alone (separate test file)

Page 32: Gov.uk content schemas   tech monthly may 2015

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

Page 33: Gov.uk content schemas   tech monthly may 2015

Frontend testtest/contracts/govuk_content_schemas_test.sh

class GovukContentSchemasTest < ActionDispatch::IntegrationTest include GovukContentSchemaExamples

all_examples_for_supported_formats.each do |content_item| test "can successfully render #{content_item['base_path']} schema example" do content_store_has_item(content_item['base_path'], content_item)

get content_item['base_path'].sub(/^\//, '')

assert_response :success end endend

@bradwright - GOV.UKGOV.UKDavid Heath

Page 34: Gov.uk content schemas   tech monthly may 2015

Adding a field to a format

1. Branch govuk-content-schemas2. Add optional field3. Push branch, all contract tests run4. Merge!

@bradwright - GOV.UKGOV.UKDavid Heath

Page 35: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UKDavid Heath

Page 36: Gov.uk content schemas   tech monthly may 2015

Adding a new format

1. Branch govuk-content-schemas2. Add schema and examples3. Make sure publisher and frontend

tests set up4. Push branch

@bradwright - GOV.UKGOV.UKDavid Heath

Page 37: Gov.uk content schemas   tech monthly may 2015

Dummy content store

@bradwright - GOV.UKGOV.UKDavid Heath

Page 38: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UKGOV.UK

Summing up

David Heath

Page 39: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UK

Your safetynet

Page 40: Gov.uk content schemas   tech monthly may 2015

@bradwright - GOV.UK

confidence

publisher

frontend

Page 41: Gov.uk content schemas   tech monthly may 2015

Links● https://github.com/alphagov/govuk-content-schemas● https://github.com/alphagov/govuk-content-schema-test-helpers● https://github.com/alphagov/govuk-dummy_content_store

@bradwright - GOV.UKGOV.UKDavid Heath

Page 42: Gov.uk content schemas   tech monthly may 2015

GOV.UK Tech Monthly - Publishing 2.0 team29th May 2015

David HeathDeveloper@dgheath21