Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to publish JSON schema for Wrangler #2596

Closed
wants to merge 10 commits into from

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Jan 23, 2023

What this PR solves / how to test:

This adds a GitHub action to generate and publish a JSON schema for wrangler PRs. The next step will be to add it to schemastore.org for automatic inclusion in e.g. VSCode.

How to test:

  • Create a new JSON file and open it in VSCode (this can also work with TOML (i.e. wrangler.toml), but I haven't been able to figure this out in VSCode yet)
  • Add the key "$schema": "https://json-schema.devprod.cloudflare.dev/penalosa/generate-json-schema.json"
  • Verify that VSCode will complain if you try to add properties or values that don't conform to the shape of a Wrangler configuration file.

Associated docs issues/PR:

  • TBD

Author has included the following, where applicable:

  • Tests
  • Changeset

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Fixes #2376

@penalosa penalosa requested a review from a team as a code owner January 23, 2023 22:17
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2023

⚠️ No Changeset found

Latest commit: 3468c0f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2023

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/runs/3991396461/npm-package-wrangler-2596

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2596/npm-package-wrangler-2596

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/runs/3991396461/npm-package-wrangler-2596 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3991396461/npm-package-cloudflare-pages-shared-2596

"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler publish",
Copy link
Contributor

Choose a reason for hiding this comment

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

You npm run publish from the Action workflow, but it's called deploy here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦

@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Merging #2596 (3468c0f) into main (0697f28) will decrease coverage by 0.10%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2596      +/-   ##
==========================================
- Coverage   73.32%   73.23%   -0.10%     
==========================================
  Files         159      159              
  Lines        9800     9847      +47     
  Branches     2583     2622      +39     
==========================================
+ Hits         7186     7211      +25     
- Misses       2614     2636      +22     
Impacted Files Coverage Δ
packages/wrangler/src/api/dev.ts 60.21% <0.00%> (-8.88%) ⬇️
packages/wrangler/src/config/index.ts 96.26% <0.00%> (-2.97%) ⬇️
packages/wrangler/src/docs/index.ts 27.27% <0.00%> (-1.30%) ⬇️
packages/wrangler/src/d1/list.tsx 29.62% <0.00%> (-1.14%) ⬇️
packages/wrangler/src/pubsub/pubsub-commands.ts 60.11% <0.00%> (-0.24%) ⬇️
packages/wrangler/src/init.ts 94.75% <0.00%> (ø)
packages/wrangler/src/index.ts 83.73% <0.00%> (ø)
packages/wrangler/src/delete.ts 100.00% <0.00%> (ø)
packages/wrangler/src/d1/index.ts 84.61% <0.00%> (ø)
packages/wrangler/src/kv/index.ts 100.00% <0.00%> (ø)
... and 33 more

@penalosa penalosa requested review from GregBrimble and a team January 23, 2023 23:17
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
const matches = url.pathname.match(/\/(.*?)\.json/);
Copy link
Contributor

@GregBrimble GregBrimble Jan 23, 2023

Choose a reason for hiding this comment

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

Is this json-schema-worker exclusively for testing? Or is the idea that we'll serve a production version from here too? If it's just the former, I reckon you could probably just re-use the prerelease-registry and save yourself the maintenance of this new service.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I might be missing the point of this PR.
But can't we just publish the schema inside the npm package of wrangler when we build?

This is what the Angular CLI does. So when you create a new Angular project you just stick a path to that schema in the config file. E.g. https://stackblitz.com/edit/angular-ivy-ycid3w?file=angular.json:

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",

https://unpkg.com/browse/@angular/[email protected]/lib/config/schema.json

@penalosa
Copy link
Contributor Author

This requires more thought (especially around depreciated fields, which aren't handled by this)

@penalosa penalosa closed this Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature Request: wrangler.json support
3 participants