-
Notifications
You must be signed in to change notification settings - Fork 62
Vendor the API client into the CLI, drop the planetscale-go dependency #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
281fa92
Vendor the API client from planetscale-go into internal/planetscale.
no-itsbackpack 7ada02e
Document the vendored API client for agents and contributors.
no-itsbackpack 0d1f4ed
Fix import grouping after the client import path rewrite (go fmt).
no-itsbackpack 9c2f6d1
Sync the vendored client to planetscale-go v0.176.0.
no-itsbackpack 2c893ad
Retrigger CI.
no-itsbackpack 320acc1
Merge origin/main (postgres role with-replication) into the vendored-…
no-itsbackpack a453e9d
Sync the vendored client to planetscale-go v0.178.0 and merge main.
no-itsbackpack 89bc30a
Promote go-humanize to a direct dependency (used by branch infra outp…
no-itsbackpack 3b58255
Add test guarding against reintroducing planetscale-go
no-itsbackpack cc14ba6
Merge branch 'main' into remove-planetscale-go-dependancy
no-itsbackpack a973291
Restore upstream client.go so the vendored copy is byte-identical
no-itsbackpack 1eb0099
Add workflow mirroring the client back to planetscale-go
no-itsbackpack fe792c9
Merge remote branch (main merged, includes d1 sqlite3 fix)
no-itsbackpack 821ffa1
Use the CLI GitHub App for mirror auth
no-itsbackpack 63882ee
Temporarily trigger mirror workflow on branch push for testing
no-itsbackpack b8364d8
Run mirror job in the release environment for app credentials
no-itsbackpack f616b4f
Keep internal API endpoints out of the planetscale-go mirror
no-itsbackpack c21deca
Rename mirror workflow and script to sync-planetscale-go
no-itsbackpack 81724b6
Skip deployment records for the sync job's environment use
no-itsbackpack 5838b9c
Fetch tags in planetscale-go checkout so gorelease finds its base
no-itsbackpack f96daec
Remove temporary push trigger now that the sync workflow is verified
no-itsbackpack adee0bd
Merge main: global-keyspace move-tables works against the vendored cl…
no-itsbackpack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| name: Sync client to planetscale-go | ||
|
|
||
| # The API client at internal/planetscale is canonical (see doc/api-client.md). | ||
| # This workflow copies it into planetscale/planetscale-go and opens a PR there | ||
| # so external users of the module can pick up new endpoints. It never pushes | ||
| # to main directly: a human reviews the PR, including the gorelease API report, | ||
| # and decides the version to tag. | ||
| # | ||
| # Auth comes from the CLI GitHub App (same as release.yml); the app must be | ||
| # installed on planetscale-go with contents and pull request write access. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| sync: | ||
| runs-on: ubuntu-latest | ||
| # The CLI app credentials (CLI_APP_ID, CLI_APP_PRIVATE_KEY) are scoped to | ||
| # the release environment. This job only reads secrets and deploys | ||
| # nothing, so skip creating deployment records. | ||
| environment: | ||
| name: release | ||
| deployment: false | ||
| steps: | ||
| - uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | ||
| id: app-token | ||
| with: | ||
| app-id: ${{ vars.CLI_APP_ID }} | ||
| private-key: ${{ secrets.CLI_APP_PRIVATE_KEY }} | ||
| permission-contents: write | ||
| permission-pull-requests: write | ||
| owner: planetscale | ||
| repositories: planetscale-go | ||
|
|
||
| - name: Check out cli | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| path: cli | ||
|
|
||
| - name: Check out planetscale-go | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| repository: planetscale/planetscale-go | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| path: planetscale-go | ||
| # gorelease needs the tag history to find the base version. | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| with: | ||
| go-version-file: cli/go.mod | ||
|
|
||
| - name: Sync client files | ||
| run: ./cli/script/sync-planetscale-go.sh cli planetscale-go | ||
|
|
||
| - name: Check for changes | ||
| id: changes | ||
| working-directory: planetscale-go | ||
| run: | | ||
| if git diff --quiet; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| echo "planetscale-go is already up to date" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| git diff --stat | ||
| fi | ||
|
|
||
| - name: Build and test synced copy | ||
| if: steps.changes.outputs.changed == 'true' | ||
| working-directory: planetscale-go | ||
| run: | | ||
| go mod tidy | ||
| go build ./... | ||
| go test ./... | ||
|
|
||
| - name: Commit to sync branch | ||
| if: steps.changes.outputs.changed == 'true' | ||
| id: commit | ||
| working-directory: planetscale-go | ||
| run: | | ||
| source_sha=$(git -C ../cli rev-parse --short HEAD) | ||
| branch="sync-cli-${source_sha}" | ||
| echo "branch=$branch" >> "$GITHUB_OUTPUT" | ||
| if git ls-remote --exit-code origin "refs/heads/$branch" > /dev/null 2>&1; then | ||
| echo "exists=true" >> "$GITHUB_OUTPUT" | ||
| echo "Branch $branch already exists, nothing to do" | ||
| exit 0 | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| fi | ||
| echo "exists=false" >> "$GITHUB_OUTPUT" | ||
| git config user.name "planetscale-cli[bot]" | ||
| git config user.email "272331943+planetscale-cli[bot]@users.noreply.github.com" | ||
| git checkout -b "$branch" | ||
| git add -A | ||
| git commit -m "Sync API client from planetscale/cli@${source_sha}" | ||
|
|
||
| - name: API compatibility report | ||
| if: steps.changes.outputs.changed == 'true' && steps.commit.outputs.exists == 'false' | ||
| working-directory: planetscale-go | ||
| run: | | ||
| # gorelease requires a clean tree, hence running after the commit. | ||
| go install golang.org/x/exp/cmd/gorelease@latest | ||
| base=$(git describe --tags --abbrev=0) | ||
| echo "Comparing against $base" | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| { | ||
| echo '## gorelease report (base: '"$base"')' | ||
| echo '```' | ||
| gorelease -base="$base" 2>&1 || true | ||
| echo '```' | ||
| } > /tmp/gorelease-report.md | ||
| cat /tmp/gorelease-report.md | ||
|
|
||
| - name: Open pull request | ||
| if: steps.changes.outputs.changed == 'true' && steps.commit.outputs.exists == 'false' | ||
| working-directory: planetscale-go | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| run: | | ||
| source_sha=$(git -C ../cli rev-parse --short HEAD) | ||
| branch="${{ steps.commit.outputs.branch }}" | ||
| git push origin "$branch" | ||
| { | ||
| echo "Automated sync of the API client from planetscale/cli@${source_sha}." | ||
| echo | ||
| echo "The client in the cli repo (internal/planetscale) is the source of" | ||
| echo "truth; this repo is a read-only mirror for external module users." | ||
| echo | ||
| echo "Review the API report below before merging. If it lists incompatible" | ||
| echo "changes, the next tag needs to reflect that." | ||
| echo | ||
| cat /tmp/gorelease-report.md | ||
| } > /tmp/pr-body.md | ||
| gh pr create \ | ||
| --repo planetscale/planetscale-go \ | ||
| --head "$branch" \ | ||
| --title "Sync API client from cli@${source_sha}" \ | ||
| --body-file /tmp/pr-body.md | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # API client (`internal/planetscale`) | ||
|
|
||
| **The CLI no longer depends on `github.com/planetscale/planetscale-go`.** | ||
|
|
||
| As of July 2026, the Go API client that used to live in the planetscale-go | ||
| repository is vendored into this repo at `internal/planetscale/` and is | ||
| maintained here. The import path is: | ||
|
|
||
| ```go | ||
| import ps "github.com/planetscale/cli/internal/planetscale" | ||
| ``` | ||
|
|
||
| ## Why | ||
|
|
||
| Every API change used to require two PRs and a release dance: change | ||
| planetscale-go, tag a release, bump `go.mod` here, then write the CLI | ||
| feature. The CLI was the only internal consumer of planetscale-go, and the | ||
| published OpenAPI spec covers under half of the endpoints the CLI uses | ||
| (none of the vtctld/workflow/data-import surface), so generating a client | ||
| from the spec was not an option. Copying the client in removes the | ||
| cross-repo step entirely. | ||
|
|
||
| ## What this means when adding or changing an endpoint | ||
|
|
||
| - Add the endpoint to api-bb, then add the method/types directly in | ||
| `internal/planetscale/` in the same CLI PR. There is no SDK release to | ||
| wait for and no version to bump. | ||
| - Do **not** add `github.com/planetscale/planetscale-go` back to `go.mod`, | ||
| and do not update the planetscale-go repo as a prerequisite for CLI work. | ||
| A test (`TestNoPlanetscaleGoDependency` in `internal/planetscale/`) fails | ||
| the build if the module shows up in `go.mod` or in any import. | ||
| - Service interfaces (e.g. `DatabasesService`) live next to their | ||
| implementations; hand-written mocks are in `internal/mock/` and must be | ||
| updated when an interface changes, same as before. | ||
| - The client's `User-Agent` starts with `pscale-cli/<version>`, set by the | ||
| CLI at startup via `planetscale.WithUserAgent` (see `internal/cmd/root.go`). | ||
| `WithUserAgent` keeps upstream's prepend semantics so the package stays | ||
| byte-identical to what the sync publishes (see below); the full header | ||
| is `pscale-cli/<version> planetscale-go/unknown`. | ||
| - Keep this package self-contained: do not import other CLI packages from | ||
| `internal/planetscale/`. The synced copy must build against | ||
| planetscale-go's own minimal `go.mod`. | ||
| - Only public (`v1/...`) endpoints are synced to planetscale-go. If the | ||
| CLI needs an internal (non-v1) endpoint, put the whole service in a | ||
| `*_internal.go` file (tests in `*_internal_test.go`); the sync script | ||
| skips those. Internal services must not be wired into the `Client` | ||
| struct in `client.go`, since that file is synced: expose them via a | ||
| method or constructor defined in the internal file itself. If a synced | ||
| file accidentally references an internal symbol, the sync workflow's | ||
| standalone build fails, so mistakes cannot ship silently. | ||
| (`d1_import_notifications.go` predates this rule: it hits an internal | ||
| endpoint but is already published in planetscale-go, so it stays.) | ||
|
|
||
| ## The planetscale-go repository | ||
|
|
||
| The public planetscale-go module still exists for external users, but it | ||
| is now a read-only mirror of this package. The CLI copy is the source of | ||
| truth; do not make client changes in the planetscale-go repo. | ||
|
|
||
| The sync is the `Sync client to planetscale-go` workflow | ||
| (`.github/workflows/sync-planetscale-go.yml`), which uses | ||
| `script/sync-planetscale-go.sh`. It runs on CLI releases | ||
| or manually, copies `internal/planetscale/` into planetscale-go (minus | ||
| `doc.go`, `dependency_test.go`, and `*_internal.go` files, which are | ||
| CLI-only), builds and tests | ||
| the copy standalone, and opens a PR there with a `gorelease` API | ||
| compatibility report. It never pushes to main: a human reviews the PR and | ||
| picks the next tag, bumping the major version if the report shows | ||
| incompatible changes. Auth comes from the CLI GitHub App (the same one | ||
| release.yml uses), which must be installed on planetscale-go. |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.