deploy: attribution, overwrite protection, and view metrics#10
Merged
Conversation
Record who deployed (user@hostname via X-Shared-Deployer) and when in a per-site meta/<site>.json, guard deploys with a force-with-lease style version check (409 + interactive overwrite prompt, --force to skip), and count per-site HTML page views with periodic flush. Views and last deployer surface in shared list, shared versions, /api/sites, and the homepage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Deploys were anonymous and last-write-wins: nothing recorded who deployed a site, and deploying from a stale checkout silently clobbered someone else's (or your own other machine's) newer deploy. There was also no usage signal at all — no way to tell if a site is ever visited or how often it changes.
This borrows the pattern used by Wrangler / Theme Kit /
git push --force-with-lease: record identity+source per deploy, do a compare-and-swap on "which version do you think you're replacing", and name the conflicting deployer in the warning.What
Attribution — the CLI sends
X-Shared-Deployer: user@hostname; every deploy and rollback is recorded (seq, time, deployer, source) in a new per-sitemeta/<site>.json(history capped at 50). Shown inshared list,shared versions(ascurrent), andGET /api/sites.Overwrite protection — the CLI remembers the last deployed version in
.shared/state.json(dotfiles are never uploaded) and sendsX-Shared-Prev-Version. On mismatch the server answers 409 with the conflicting deployer's identity and the CLI prompts:With no local state the CLI asks the server who deployed last and warns if it wasn't you.
--force/X-Shared-Force: 1skips the check; requests without a prev-version header (curl, older CLIs) are accepted unchecked, so nothing existing breaks.View metrics —
handleStaticcounts GETs of HTML documents (not assets/API) per site, batched in memory and flushed to meta every 30s with 30-day daily buckets. Totals appear inshared list,/api/sites, and the homepage cards.Rate limiting is untouched (stays global via
SHARED_AI_RATE), per earlier discussion.Verified
Exercised end-to-end against a local server: attributed deploy, legacy curl deploy (unchecked, bumps seq), stale-state deploy → 409 → decline cancels / accept overwrites, fresh-checkout warning for a different user, rollback recorded with
source: rollback, view counts visible immediately and persisted after the 30s flush with daily buckets.go vet,go test, cross-compile (linux/windows/darwin), andnix buildall pass.