Skip to content

Scratch asset importing#755

Merged
zetter-rpf merged 8 commits intomainfrom
scratch-asset-importing
Apr 2, 2026
Merged

Scratch asset importing#755
zetter-rpf merged 8 commits intomainfrom
scratch-asset-importing

Conversation

@zetter-rpf
Copy link
Copy Markdown
Contributor

@zetter-rpf zetter-rpf commented Mar 27, 2026

Status

What's changed?

  • This adds rake tasks that allow us import Scratch library assets.
  • This also sets the CORP to fix one issue that stops assets from displaying.

See commits for more.

Note that assets won't yet display as there's other issues preventing them. See https://github.com/orgs/RaspberryPiFoundation/projects/51/views/82?pane=issue&itemId=164355876&issue=RaspberryPiFoundation%7Cdigital-editor-issues%7C1229 for details.

Steps to perform after deploying to production

@cla-bot cla-bot bot added the cla-signed label Mar 27, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

Test coverage

89.92% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/23837678777

We have permission from the Scratch Foundation to use the library assets available with Scratch.

These tasks imports them assets defined in the in the library configuration files. See [1] for instructions on how to run.

RaspberryPiFoundation/digital-editor-issues#1229
It's good practice when performing a lots of requests to add in time so not to overload any servers.
When running rake tasks locally there can be a lot of output from SQL queries and active storage, making it harder to see warnings.
Make it possible to configure the Rails log level in development using environment variables.
This is just like the code in production.rb except it uses the development default of debug.
Some of these tasks may take a while, the ruby progress bar library makes it easy to get a sense of progress.

I've not shown the progress bar in tests as it messes the test output.
The library uses an <img> tag to load and embed the assets, which is different to how assets are loaded in projects
For this to work, the asset needs to have a Cross-Origin-Resource-Policy set.
@zetter-rpf zetter-rpf force-pushed the scratch-asset-importing branch from 9e3c755 to 23387d7 Compare March 31, 2026 13:28
@zetter-rpf zetter-rpf marked this pull request as ready for review March 31, 2026 16:05
Copilot AI review requested due to automatic review settings March 31, 2026 16:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds tooling to import Scratch library assets into the app’s ScratchAsset/ActiveStorage store, and updates CORP behavior so Scratch asset requests can be embedded cross-origin.

Changes:

  • Introduces ScratchConfigImporter and ScratchAssetImporter plus rake tasks to import backdrops/costumes/sounds/sprites from Scratch config JSON.
  • Extends CorpMiddleware to set Cross-Origin-Resource-Policy: cross-origin for the Scratch asset GET endpoint.
  • Adds ruby-progressbar and supporting specs + example env vars.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
lib/scratch_asset_importer.rb Implements asset fetching + persistence into ScratchAsset with optional progress output.
lib/scratch_config_importer.rb Fetches/parses config JSON and extracts asset filenames to import.
lib/tasks/scratch_assets.rake Adds rake tasks for importing different Scratch asset categories.
lib/corp_middleware.rb Expands CORP header logic to include Scratch asset endpoint paths.
spec/lib/scratch_asset_importer_spec.rb Adds importer behavior specs (create, skip existing, partial failures).
spec/lib/scratch_config_importer_spec.rb Adds config parsing/extraction specs for importer handoff.
spec/lib/corp_middleware_spec.rb Adds coverage for CORP header on Scratch asset requests.
Gemfile / Gemfile.lock Adds ruby-progressbar dependency.
config/environments/development.rb Makes log level configurable via RAILS_LOG_LEVEL.
.env.example Documents Scratch asset import env vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

There's a chance it won't be loaded when we use it
If the page 500s or 400s, this would be a clearer error.
@adrian-rpf adrian-rpf requested a review from mwtrew April 2, 2026 09:21
Copy link
Copy Markdown
Contributor

@mwtrew mwtrew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@zetter-rpf zetter-rpf merged commit 960a4ce into main Apr 2, 2026
5 checks passed
@zetter-rpf zetter-rpf deleted the scratch-asset-importing branch April 2, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants