# Prod Cloud Clinic Release Helper

## Current Design

- Source repo is `pingcap-inc/clinic`.
- The release entrypoint for the Clinic server is `.github/workflows/clinic_cd.yml`.
- A production release is not complete when the Clinic workflow succeeds. That workflow builds and pushes an image, then dispatches `tidbcloud/app-delivery` to update the GitOps config.
- The live source of truth for production is the Kubernetes deployment image in `clinic-prod-cloud/deploy/clinic`.
- The app-delivery PR must only update `clinic/clinic-api/envs/prod-cloud/kustomization.yaml` for this helper.

## Risks

- Accidentally deploying `prod-op` would change the wrong production environment.
- Treating the GitHub Actions run as the final state would miss failed or delayed GitOps rollout.
- Merging the wrong app-delivery PR could deploy an unrelated component or environment.
- Checks can take longer than expected; the helper must poll and report state instead of assuming success.

## Target Contract

- The helper only automates `env=prod-cloud` and `components=clinic`.
- It builds the image tag from the selected Clinic ref: `master-<sha>` by default.
- It only accepts an app-delivery PR whose title and diff match the target image tag and whose changed files are all under the prod-cloud Clinic API kustomization path.
- It waits for:
  - Clinic CD workflow completion.
  - app-delivery PR creation.
  - app-delivery checks success.
  - app-delivery PR merge.
  - live `clinic-prod-cloud` deployment image equals the target image.
  - `kubectl rollout status deploy/clinic` succeeds.
- It never triggers or merges anything for `prod-op`.

## Implementation Steps

1. Add a local shell helper under `tools/`.
2. Use `gh workflow run clinic_cd.yml --ref master -f env=prod-cloud -f components=clinic`.
3. Poll the Clinic workflow run until success or failure.
4. Locate the app-delivery PR by exact image tag.
5. Validate the PR changed files and title before approval or merge.
6. Approve, wait for checks, merge, then poll the live K8s deployment image and rollout.

## Verification Checklist

- Run shell syntax validation on the helper.
- Confirm the helper has no `prod-op` deploy path.
- Confirm it references the expected prod-cloud K8s context, namespace, and deployment.
- For real usage, run with `--yes` only after confirming the displayed target commit and image tag.
