# Agent CLI Setup

Use these common values as a starting point for agent-driven flows:

```bash
export REPO=tidbcloud/metrics-integration
export RELEASE_SHA="$(git rev-parse HEAD)"
```

For a `dev` release, this is usually enough:

```bash
export TARGET_ENV=dev
export RELEASE_SHA="$(git rev-parse HEAD)"
```

For a normal `prod` tagged release:

```bash
export TARGET_ENV=prod
export TAG=release/v2026-03-24
export PREV_TAG="$(gh release list -R "$REPO" --exclude-drafts --exclude-pre-releases --limit 2 --json tagName --jq '.[1].tagName')"
```

After the prod tag is created:

```bash
export RELEASE_SHA="$(git rev-list -n 1 "$TAG")"
```

## Common CLI Helpers

### Inspect the target commit for a dev release

```bash
git fetch origin
git checkout main
git pull --ff-only origin main

echo "Target SHA: $RELEASE_SHA"
git log --oneline -n 20 "$RELEASE_SHA"
git diff --stat "${RELEASE_SHA}^..${RELEASE_SHA}" || true
```

### Inspect what changed since the previous prod release

```bash
git fetch origin --tags
git checkout main
git pull --ff-only origin main

echo "Previous release: $PREV_TAG"
git log --oneline "${PREV_TAG}..HEAD"
git diff --stat "${PREV_TAG}..HEAD"
```

### Create the prod tag and GitHub Release without using the web UI

This is the recommended normal-release path because the tag push automatically starts:

- `prod-ci-global.yaml`
- `prod-ci-regional.yaml`
- `prod-ci-pipeline.yaml`

```bash
git tag -a "$TAG" -m "prod release $TAG"
git push origin "$TAG"
gh release create "$TAG" -R "$REPO" --verify-tag --generate-notes --title "$TAG"
export RELEASE_SHA="$(git rev-list -n 1 "$TAG")"
```

### Watch a workflow run from the terminal

```bash
RUN_ID="$(gh run list -R "$REPO" \
  --workflow prod-ci-global.yaml \
  --commit "$RELEASE_SHA" \
  --event push \
  --limit 1 \
  --json databaseId \
  --jq '.[0].databaseId')"

gh run watch -R "$REPO" "$RUN_ID" --compact --exit-status
gh run view -R "$REPO" "$RUN_ID" --log-failed
```

Replace the workflow file name as needed.
