Skip to content

CS-10959: add lint scripts for packages/observability/#4614

Open
lukemelia wants to merge 4 commits intomainfrom
cs-10959-add-lint-scripts-for-packagesobservability
Open

CS-10959: add lint scripts for packages/observability/#4614
lukemelia wants to merge 4 commits intomainfrom
cs-10959-add-lint-scripts-for-packagesobservability

Conversation

@lukemelia
Copy link
Copy Markdown
Contributor

Summary

Adds a self-contained lint script to packages/observability/ covering the package's actual content — shell scripts, JSON manifests, YAML, plus a regression check on the secret-redaction code path. No JS/TS in this package, so ESLint / TS aren't applicable.

What runs (scripts/lint.sh):

  1. shellcheck on scripts/**/*.sh
  2. jq empty on every JSON file under grafanactl/resources/ and provisioning/
  3. Manifest shape — every dashboards/folders manifest has top-level apiVersion + kind + metadata.name (offline schema sanity, no live Grafana required)
  4. Secret-shape scan — every templating.list[] constant variable named grafana_secret must equal REPLACE_AT_APPLY_TIME. Regression check on extract-amg.sh's redaction
  5. prettier --check on YAML (matches the rest of the repo's YAML formatting policy)
  6. grafanactl resources validate — opt-in via GRAFANACTL_VALIDATE_ENV=local|staging|production. The diff/apply CI workflows set this with GRAFANA_TOKEN already in env, giving manifest-vs-live-server validation at PR / merge time

Wiring:

  • package.json exposes "lint": "bash ./scripts/lint.sh" so root pnpm lint picks it up via --if-present
  • ci-lint.yaml runs it on every PR (no token, skips step 6)
  • observability-{diff,apply-staging,apply-production}.yml run it right after the SSM token fetch, with GRAFANACTL_VALIDATE_ENV set so step 6 contacts the right env. PRETTIER_SKIP=1 in those three avoids forcing a pnpm install for a check ci-lint already covers

Pre-existing shellcheck/prettier findings the new lint surfaced are fixed in the same commit so it passes clean: SC2295 in diff.sh, SC2317 in grafanactl-env.sh, SC2016 in render-config.sh, SC2034 in extract-amg.sh, and a prettier drift in docker-compose.yml.

Closes CS-10959. Follow-up to PR #4529 review (Hassan).

Test plan

Verified locally by planting each acceptance-criteria bad case, running pnpm --filter @cardstack/observability lint, confirming it fails, then reverting:

  • Clean lint passes on current state
  • Unquoted \$VAR in a shell script → fails (SC2086)
  • Manifest with no apiVersion → fails (missing required field(s): apiVersion)
  • Malformed JSON → fails (malformed JSON)
  • UUID-shaped value in dashboard templating.list[].grafana_secret.query → fails (is not REPLACE_AT_APPLY_TIME)
  • Root pnpm lint includes the package via --if-present
  • CS-10932 apply workflows + CS-10933 diff workflow run lint before push/diff (env vars set so grafanactl resources validate also runs there)
  • CI green on this PR

🤖 Generated with Claude Code

Add `pnpm --filter @cardstack/observability lint` covering shellcheck,
JSON syntax, App Platform manifest shape, prettier (YAML), and a
secret-shape regression check on dashboard JSON. Wire into ci-lint.yaml
plus the observability-{diff,apply-staging,apply-production} workflows;
the latter three set GRAFANACTL_VALIDATE_ENV so `grafanactl resources
validate` runs against the live Grafana for that env.

Also fixes a few pre-existing shellcheck findings the new lint surfaced
(SC2295 in diff.sh, SC2317 in grafanactl-env.sh, SC2016 in
render-config.sh, SC2034 in extract-amg.sh) and a prettier drift in
docker-compose.yml so the lint passes clean on current state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 a dedicated lint entrypoint for packages/observability/ (shell/JSON/YAML + manifest/secret sanity checks) and wires it into CI and the observability diff/apply workflows to catch issues earlier in the Grafana “dashboards as code” pipeline.

Changes:

  • Introduces packages/observability/scripts/lint.sh and exposes it via packages/observability/package.json as pnpm --filter @cardstack/observability lint.
  • Integrates observability linting into .github/workflows/ci-lint.yaml and into the observability diff/apply workflows (with optional grafanactl resources validate when tokens are available).
  • Includes small script/workflow hygiene fixes (ShellCheck suppressions, quoting tweak, YAML formatting).

Reviewed changes

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

Show a summary per file
File Description
packages/observability/scripts/lint.sh New package-scoped lint script covering shellcheck, jq validation, manifest shape, secret redaction regression, prettier YAML, and optional grafanactl validation.
packages/observability/package.json Adds lint script entrypoint for the observability package.
.github/workflows/ci-lint.yaml Runs observability lint on PRs/pushes as part of the main lint workflow.
.github/workflows/observability-diff.yml Runs observability lint (with live validation) before computing/posting the staging diff.
.github/workflows/observability-apply-staging.yml Runs observability lint (with live validation) before applying to staging.
.github/workflows/observability-apply-production.yml Runs observability lint (with live validation) before applying to production.
packages/observability/scripts/render-config.sh Adds targeted ShellCheck suppression around envsubst allow-list usage.
packages/observability/scripts/grafanactl-env.sh Adds ShellCheck suppression for sourced-vs-executed return/exit behavior.
packages/observability/scripts/diff.sh Adjusts prefix-stripping in JSON normalization loop.
packages/observability/scripts/migrations/extract-amg.sh Simplifies fail_on_collision signature and updates call sites.
packages/observability/docker-compose.yml Prettier-driven formatting adjustment for the Loki healthcheck test array.

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

Comment thread packages/observability/scripts/diff.sh
Comment thread .github/workflows/observability-apply-staging.yml
Comment thread .github/workflows/observability-apply-production.yml
lukemelia and others added 3 commits May 4, 2026 13:32
Copilot caught that the staging and production apply workflows on
this branch dropped the `fetch REALM_SERVER_URL` SSM call, but
apply.sh's required_env_vars guard still hard-fails for non-local
envs if REALM_SERVER_URL is unset (CS-10923). The drop was
unintentional reformatting collateral; the value is still needed at
apply time to substitute the dashboards' realm_server constant
template variable.

Also confirmed there are no IAM grants to revoke — the SSM paths
/staging/boxel-grafana/realm_server_url and the production
counterpart are still in cardstack/infra's
configs/boxel-observability-apply/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ipts-for-packagesobservability

# Conflicts:
#	.github/workflows/observability-diff.yml
1. shellcheck SC2016 on diff.sh:177
   `JQ_NORMALIZE='...'` is a jq script that uses jq's own `\$url`
   bound via `--arg url`, so the single-quoting is intentional —
   shell expansion would break the jq variable reference. Same
   pattern as render-config.sh:31. Added a targeted
   `# shellcheck disable=SC2016` directive immediately above the
   assignment with the rationale, rather than excluding the rule
   globally.

2. PRETTIER_SKIP honored before the pnpm-availability check
   The diff/apply workflows intentionally skip `pnpm install` to
   stay fast and pass `PRETTIER_SKIP=1`, but the script's old order
   errored on missing pnpm before checking the skip flag. Reordered
   so PRETTIER_SKIP=1 short-circuits cleanly even when pnpm isn't on
   PATH.

Re-ran `pnpm --filter @cardstack/observability lint` (clean
shellcheck output) and `PRETTIER_SKIP=1 bash scripts/lint.sh`
("PRETTIER_SKIP=1 — skipping prettier check" + "lint OK").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Observability diff (vs staging)

No dashboard / folder changes detected against the staging Grafana.

(Run: https://github.com/cardstack/boxel/actions/runs/25341067849)

@lukemelia lukemelia marked this pull request as ready for review May 4, 2026 20:22
@lukemelia lukemelia requested review from a team and habdelra May 4, 2026 20:22
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.

2 participants