ci: publish the schemas and spec to contextgraphprotocol.org on merge - #78
Conversation
This repository has no website of its own, so what it publishes is artifacts: schema/*.json and reference-vectors.ndjson under /schema, SPEC.md and docs/ under /spec, on the microsite's CDN. It then asks cgp-website to rebuild, because the rendered documentation there quotes this specification and the two would otherwise drift with nothing to say which is current. validate-examples.py runs in this workflow rather than only in ci.yml. Reading another workflow's result needs a workflow_run trigger, whose failure mode is publishing anyway when the dependency is skipped. The schema upload carries no --delete: a published schema URL is a contract other implementations resolve, and removing one must not be something a rename here does silently. The spec upload does, because those are documents. Schemas' $id still resolves to raw.githubusercontent.com and the validator still checks that copy byte-for-byte. What lands on the site is a mirror on a branded host, not a new canonical location. The dispatch step needs a token that can write to another repository, which GITHUB_TOKEN cannot by design. Without SITE_DISPATCH_TOKEN it warns and the job still succeeds, so a missing convenience cannot hide a successful publish.
There was a problem hiding this comment.
Sorry @macanderson, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Reviewer's GuideAdds an automated GitHub Actions workflow that validates JSON schema examples and publishes schemas and spec artifacts to contextgraphprotocol.org on merges to main, documenting the behavior and required one‑time setup in PUBLISHING.md. Sequence diagram for publishing validated artifactssequenceDiagram
participant GitHub as GitHubActions
participant Validator as validate-examples.py
participant S3 as S3Bucket
participant CloudFront
participant Website as cgp-website
GitHub->>Validator: python3 schema/validate-examples.py
Validator-->>GitHub: validation succeeds
GitHub->>S3: aws s3 sync schema/ to schema/ without --delete
GitHub->>S3: aws s3 sync spec/ to spec/ with --delete
GitHub->>CloudFront: aws cloudfront create-invalidation for /schema/* and /spec/*
GitHub->>S3: curl published schema and jq -e .title
GitHub->>Website: repository_dispatch rebuild request
Website-->>GitHub: rebuild request accepted
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
The mechanism is now proven end-to-end. One thing had to be fixed to get there, and it affected this role too — it is The immutable-id format — owner and repository each carrying their numeric The same record retired a guess I had hedged against: the environment name in |
This PR is the event ADR 0008's guard anticipated in a comment: the repo starts publishing artifacts to a host of its own, so URLs on that host stop being 404s. The guard failed the PR that makes its premise obsolete. Adding the host to SERVED_HOSTS would have been the wrong shape. This repo publishes exactly two prefixes of the apex bucket (/schema/ and /spec/) and owns nothing else there, so a bare host entry would re-bless contextgraphprotocol.org/badges/conformant.svg — the precise 404 ADR 0008 was written about. So SERVED_HOSTS becomes SERVED_PREFIXES, mapping each published URL prefix to the repo directory whose bytes land there. That also strengthens the guard: the "does this artifact exist" half was previously applied only to raw URLs, and now covers every served prefix. Verified against both directions: /badges/ on the apex still fails, and a /schema/ URL on the apex naming a file not in schema/ fails the existence half.
What
On merge to
main, this repository publishes its artifacts tocontextgraphprotocol.organd asks the microsite to rebuild.schema/*.json/schema/…schema/reference-vectors.ndjson/schema/reference-vectors.ndjsonSPEC.md/spec/SPEC.mddocs/**/spec/docs/…This repository has no website of its own — the site is built from
macanderson/cgp-website— so what it publishes is artifacts, into two prefixesof that site's bucket that belong to this repository and nothing else.
What it deliberately does not change
The schemas'
$idstill resolves toraw.githubusercontent.com, andvalidate-examples.pystill checks the copy served there byte-for-byte. Whatlands on the site is a mirror on a branded host, not a new canonical
location. Promoting
$idwould change what every validator resolves — aprotocol-visible decision, not a deployment one, and out of scope here. Filed as
a follow-up.
Design notes worth a reviewer's attention
validate-examples.pyruns in this workflow, not just inci.yml.Observing another workflow's result needs a
workflow_runtrigger, whosefailure mode is publishing anyway when the dependency is skipped. The
distinction that matters is between "the schema validated somewhere" and "the
bytes about to be published validated".
--deleteon the schema upload. A published schema URL is a contractother implementations resolve; removing one is a breaking change and must not
be what a rename in this repository does silently on merge. Retiring one is an
aws s3 rmmade out loud. Thespec/upload does use--delete— those aredocuments, and renaming them is ordinary editing.
--content-typeis spelled out. S3 guesses from the extension and wouldserve
.ndjsonasapplication/octet-stream, which browsers download ratherthan show.
/schema/*and/spec/*. A/*would alsoevict the microsite's pages, which this merge did not change — paid for, and a
cold edge for readers who were not affected.
serves its 404 page with a
200, so a status check alone would pass for apublish that landed nowhere. It pipes the response through
jq -e '.title'.repository's workflows, which use floating tags. A tag is mutable and this is
the only job here holding credentials that can write to a production bucket.
I did not touch the other workflows.
The seam with cgp-website
Both repositories write the same bucket. Two arrangements keep them apart, and
they are belt and braces on purpose:
cgp-website's deploy excludesschema/andspec/from its--deletesync (ci: publish contextgraphprotocol.org to AWS on merge to main cgp-website#14). Without it,
--deletewould removeeverything this publishes — silently, because deleting a file the sync did not
expect is not an error.
site's role is explicitly denied them. So if the excludes are ever dropped,
that deploy fails loudly instead of corrupting this output.
Verification
python3 schema/validate-examples.pyrun locally: OK — all examplesvalidate, including the
$id-resolves-byte-identical check. That mattershere because the publish job is gated on it — if it were failing today,
nothing would ever publish.
run:block extracted andbash -n-checked.uses:SHAs resolved against the GitHub API rather than copied.last segment contains a dot, so
/schema/*.jsonand/spec/**/*.mdreach S3unrewritten. Read from
modules/static-site/rewrite.js.tftpl, not assumed.main.First merge is the test;
workflow_dispatchre-runs it.One-time setup needed
productionenvironment — created. The AWS role trusts exactlyrepo:macanderson/context-graph-protocol:environment:production; there is nostored AWS key.
SITE_DISPATCH_TOKEN— not created, and I cannot create it. Writing toanother repository is something
GITHUB_TOKENcannot do by design, so therebuild trigger needs a fine-grained PAT with
Contents: read-writeonmacanderson/cgp-website. Until it exists that step warns and the job stillsucceeds: the schemas and spec publish either way, and only the site rebuild
waits for
cgp-website's next own merge. This is the single manual step.Infrastructure (OIDC provider, the role, its prefix-scoped policy) is applied and
lives in
oxagen-aws-infra—stacks/ci-deploy/.Summary by Sourcery
Publish validated protocol schemas and documentation to contextgraphprotocol.org without changing their canonical raw GitHub identities.
New Features:
Bug Fixes:
Enhancements:
CI:
Deployment:
Documentation: