Skip to content

cmd: add heygen update command - #50

Merged
somanshreddy merged 3 commits into
mainfrom
04-06-cmd_add_heygen_update_command
Apr 7, 2026
Merged

somanshreddy merged 3 commits into
mainfrom
04-06-cmd_add_heygen_update_command

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Apr 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds heygen update and heygen update check — explicit self-update commands for the CLI. No auto-update, no startup notifications, no network calls in --help or --version.

heygen update check — queries GitHub Releases for the latest stable version, returns JSON:

{"current": "v0.1.0", "latest": "v0.2.0", "update_available": true}

heygen update — downloads the latest stable release, verifies SHA256 checksum, replaces the binary. Returns JSON:

{"previous": "v0.1.0", "current": "v0.2.0", "message": "Updated heygen from v0.1.0 to v0.2.0"}

heygen update --version v0.1.0 — pins to a specific version. The v prefix is required; bare 0.1.0 returns exit 2 (usage error).

Design decisions:

  • skipAuth: true — no HeyGen API key needed. GitHub Releases are the source.
  • GitHub token sourced from GITHUB_TOKEN → GH_TOKEN → gh auth token (same chain as the installer). Empty token works once the repo is public.
  • Package manager detection: if binary is under /homebrew/, /Cellar/, /linuxbrew/, or node_modules/, returns a CLIError telling the user to use their package manager instead.
  • Local dev builds (no ldflags) get a clear error: "reinstall from a release build to use heygen update."
  • releaseUpdater interface abstracts go-selfupdate for testability. All tests use a mock — no real GitHub API calls.
  • Static hint in root --help: Use "heygen update check" to see if a newer version is available. No dynamic notifications.
  • version field added to cmdContext to pass the build-time version string to the update command.

Dependencies added: creativeprojects/go-selfupdate (GitHub Releases source, checksum validation, atomic binary replacement, rollback on failure) and Masterminds/semver (version parsing and validation).

Stacked on PR #49 (installer rewrite).

Testing

7 tests with mock releaseUpdater:

  • TestUpdateCheck_NewVersionAvailable — newer version returns update_available: true
  • TestUpdateCheck_AlreadyCurrent — same version returns update_available: false
  • TestUpdateCheck_LocalDevVersion — dev build returns exit 1 with "not release-tagged" error
  • TestUpdate_SkipsAuth — no API key needed, exit 0
  • TestUpdate_PackageManagerWarning — Homebrew path returns wrong_install_method error with brew hint
  • TestUpdate_JSONOutput — success returns valid JSON with previous/current/message
  • TestUpdate_RejectsBareVersion — --version 0.1.0 (no v) returns exit 2

Root help test updated to verify the static update hint line.

somanshreddy commented Apr 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

@somanshreddy
somanshreddy marked this pull request as ready for review April 6, 2026 20:09
@somanshreddy
somanshreddy requested a review from jrusso1020 April 6, 2026 20:27
@somanshreddy
somanshreddy force-pushed the 04-06-cmd_add_heygen_update_command branch from 09a7966 to 775033f Compare April 6, 2026 20:36
Comment thread README.md Outdated
Check for and apply updates after install:

```bash
heygen update check

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be a separate command or a flag? just curious if we have examples here of

I coudl see heygen version being waht does the check vs heygen update does check + downloads

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, Cobra autogenerates the --version/-v flag on heygen.

We can add an explicit version subcommand as well. Though I think -v is a good standard.

Also, a quick comparison table on having version separate from an explicit update check:

Screenshot 2026-04-06 at 3.49.28 PM.png

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I wanted --version to also check for an update. Both codex and claude pushed back saying that this is usually a non-networked call.

But I still feel that it might be useful. What do you think? Running --version also checks if there is a newer version available. However, we would need to see how agents react to this behaviour (version flag for checking for a new version and then update to actually update the package)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrusso1020 The passive notice pattern above is below:

When you run any gh or stripe command, they occasionally print a message to stderr like:

A new release of gh is available: 2.44.0 → 2.45.0
https://github.com/cli/cli/releases/tag/v2.45.0

It's "passive" because:

  • You didn't ask for it — it just appears alongside your normal command output
  • It's on stderr so it doesn't break JSON piping
  • It has a 24-hour cooldown so it doesn't show every time
  • It's informational only — you still have to run brew upgrade gh yourself

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense to me I think --version could be teh default cobra and we could add version command to if we wnat to have custom logic?

I just find the update check command confusing/unnecessary can eitehr include that info with version or just have an update command

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. We can simplify to the below for now:

heygen --version — local version string (Cobra built-in, what everyone expects)
heygen update — checks for newer version + installs if available. If already current, tells you.

We can add a passive note as a follow up feature.

Comment thread cmd/heygen/root.go Resolved
Comment thread cmd/heygen/update.go
Comment on lines +71 to +74
newReleaseUpdater = func(prerelease bool) (releaseUpdater, error) {
source, err := selfupdate.NewGitHubSource(selfupdate.GitHubConfig{
APIToken: githubReleaseToken(),
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't have github account you can't download from here? is that a potential concern

@somanshreddy somanshreddy Apr 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only while the repo is private. This flow won't be used once the repo is public.

This code should already work for a public repo. An empty string will be returned if user doesn't have a GitHub account, and then it would proceed with an unauthenticated request to GitHub. It wouldn't throw an error when the repo is public.

@somanshreddy
somanshreddy force-pushed the 04-06-scripts_rewrite_installer_for_versioned_releases branch from b375061 to 5066125 Compare April 6, 2026 23:28
@somanshreddy
somanshreddy force-pushed the 04-06-cmd_add_heygen_update_command branch from 775033f to 4853044 Compare April 6, 2026 23:28
somanshreddy added a commit that referenced this pull request Apr 6, 2026
## Description

Adds a `.gitleaks.toml` allowlist so the PostHog project API token in `internal/analytics/analytics.go` doesn't fail the secrets CI check.

PostHog project tokens are public client-side ingest tokens by design — they're embedded in every frontend and CLI that uses PostHog. This is not a secret leak. The allowlist is scoped narrowly: only matches the exact `const posthogAPIKey = "phc_..."` assignment in that one file.

Without this, the `secrets` CI job fails on PRs #23, #49, and #50 (the entire M6 stack).

## Testing

CI `secrets` job should pass after this merges. Verified the allowlist regex matches the token assignment pattern.
somanshreddy added a commit that referenced this pull request Apr 6, 2026
## Description

Adds a manual GitHub Actions workflow for cutting stable releases. This is the first PR in the M6 release cycle stack (#23 → #49 → #50).

### Versioning Strategy

The CLI uses semver with a `v` prefix everywhere — git tags, `--version` output, `--version` flag input, JSON responses, install script.

| Build type | Tag format | Example | How triggered |
|---|---|---|---|
| **Stable** | `v{major}.{minor}.{patch}` | `v0.1.0` | Manual — GitHub Actions UI, operator inputs version |
| **Dev** | `v{base}-dev.{YYYYMMDD}.{shorthash}` | `v0.1.1-dev.20260406.abc1234` | Manual — GitHub Actions UI, version auto-computed |
| **Local** | — | `dev` | `go build` without ldflags |

**Semver ordering:** `v0.2.0` > `v0.1.1-dev.20260407.def` > `v0.1.1-dev.20260406.abc` > `v0.1.0`. Stable always beats prerelease. Dev builds sort chronologically by date.

**Dev version auto-derivation (PR #49):** The dev workflow reads the latest stable tag, bumps patch (`v0.1.0` → `v0.1.1`), and appends `-dev.YYYYMMDD.SHORTHASH`. No VERSION file, no manual bumps. Dev builds always sort above the latest stable.

**Bumping rules:** Pre-1.0 (`v0.x.y`): minor = features, patch = fixes, no stability guarantees. Post-1.0: full semver contract.

### This PR — Stable Release Workflow

**Trigger:** GitHub Actions UI → "Stable Release" → input version tag (e.g., `v0.1.0`) → "Run workflow"

**What it does:**
1. Validates version is semver format (`v0.1.0` — rejects `1.0` or `foo`)
2. Validates the tag doesn't already exist (prevents accidental overwrite)
3. Runs tests
4. Creates git tag on current `main` HEAD
5. GoReleaser builds platform binaries + `checksums.txt`, publishes as a stable GitHub release

**Downstream PRs:**
- PR #49 — rewrites dev release workflow + installer for versioned assets
- PR #50 — adds `heygen update` / `heygen update check` commands (channel-aware: stable users get stable updates, dev users get dev updates)

## Testing

Workflow syntax validated. GoReleaser config tested by `goreleaser-check` CI job. Version validation tested manually with valid/invalid inputs.
@somanshreddy
somanshreddy force-pushed the 04-06-scripts_rewrite_installer_for_versioned_releases branch 2 times, most recently from a7c9b3f to dd325d3 Compare April 6, 2026 23:43
@somanshreddy
somanshreddy force-pushed the 04-06-cmd_add_heygen_update_command branch from 4853044 to 510af22 Compare April 6, 2026 23:43
@somanshreddy
somanshreddy changed the base branch from 04-06-scripts_rewrite_installer_for_versioned_releases to graphite-base/50 April 6, 2026 23:54
@somanshreddy
somanshreddy force-pushed the 04-06-cmd_add_heygen_update_command branch from 510af22 to 4145847 Compare April 6, 2026 23:54
@graphite-app
graphite-app Bot changed the base branch from graphite-base/50 to main April 6, 2026 23:54
@somanshreddy
somanshreddy force-pushed the 04-06-cmd_add_heygen_update_command branch from 4145847 to ee30836 Compare April 6, 2026 23:55

somanshreddy commented Apr 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Apr 7, 1:01 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 7, 1:01 AM UTC: @somanshreddy merged this pull request with Graphite.

@somanshreddy
somanshreddy merged commit c9e2db1 into main Apr 7, 2026
9 checks passed
@somanshreddy
somanshreddy deleted the 04-06-cmd_add_heygen_update_command branch April 7, 2026 01:01
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