Skip to content
Merged
2 changes: 2 additions & 0 deletions .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
POSTHOG_ENDPOINT: ${{ secrets.POSTHOG_ENDPOINT }}

- run: gh release edit v${{ needs.release.outputs.new-release-version }} --draft=false --prerelease
env:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X github.com/supabase/cli/internal/utils.Version={{.Version}} -X github.com/supabase/cli/internal/utils.SentryDsn={{ .Env.SENTRY_DSN }}
- -s -w -X github.com/supabase/cli/internal/utils.Version={{.Version}} -X github.com/supabase/cli/internal/utils.SentryDsn={{ .Env.SENTRY_DSN }} -X github.com/supabase/cli/internal/utils.PostHogAPIKey={{ .Env.POSTHOG_API_KEY }} -X github.com/supabase/cli/internal/utils.PostHogEndpoint={{ .Env.POSTHOG_ENDPOINT }}
env:
- CGO_ENABLED=0
targets:
Expand Down
1 change: 1 addition & 0 deletions cmd/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ var (
func init() {
branchFlags := branchesCmd.PersistentFlags()
branchFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(branchFlags.Lookup("project-ref"))
createFlags := branchCreateCmd.Flags()
createFlags.Var(&region, "region", "Select a region to deploy the branch database.")
createFlags.Var(&size, "size", "Select a desired instance size for the branch database.")
Expand Down
4 changes: 4 additions & 0 deletions cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ var (

func init() {
functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(functionsListCmd.Flags().Lookup("project-ref"))
functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(functionsDeleteCmd.Flags().Lookup("project-ref"))
deployFlags := functionsDeployCmd.Flags()
deployFlags.BoolVar(&useApi, "use-api", false, "Bundle functions server-side without using Docker.")
deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
Expand All @@ -150,6 +152,7 @@ func init() {
deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
deployFlags.BoolVar(&prune, "prune", false, "Delete Functions that exist in Supabase project but not locally.")
deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(deployFlags.Lookup("project-ref"))
deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
Expand All @@ -162,6 +165,7 @@ func init() {
cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all"))
downloadFlags := functionsDownloadCmd.Flags()
downloadFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(downloadFlags.Lookup("project-ref"))
downloadFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
downloadFlags.BoolVar(&useApi, "use-api", false, "Unbundle functions server-side without using Docker.")
downloadFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to unbundle functions client-side.")
Expand Down
2 changes: 2 additions & 0 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func init() {
typeFlags.Bool("linked", false, "Generate types from the linked project.")
typeFlags.String("db-url", "", "Generate types from a database url.")
typeFlags.StringVar(&flags.ProjectRef, "project-id", "", "Generate types from a project ID.")
markFlagTelemetrySafe(typeFlags.Lookup("project-id"))
genTypesCmd.MarkFlagsMutuallyExclusive("local", "linked", "project-id", "db-url")
typeFlags.Var(&lang, "lang", "Output language of the generated types.")
typeFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
Expand All @@ -162,6 +163,7 @@ func init() {
genCmd.AddCommand(genTypesCmd)
keyFlags := genKeysCmd.Flags()
keyFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(keyFlags.Lookup("project-ref"))
keyFlags.StringSliceVar(&override, "override-name", []string{}, "Override specific variable names.")
genCmd.AddCommand(genKeysCmd)
signingKeyFlags := genSigningKeyCmd.Flags()
Expand Down
1 change: 1 addition & 0 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
func init() {
linkFlags := linkCmd.Flags()
linkFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(linkFlags.Lookup("project-ref"))
linkFlags.StringVarP(&dbPassword, "password", "p", "", "Password to your remote Postgres database.")
linkFlags.BoolVar(&skipPooler, "skip-pooler", false, "Use direct connection instead of pooler.")
// For some reason, BindPFlag only works for StringVarP instead of StringP
Expand Down
1 change: 1 addition & 0 deletions cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func init() {
// Build squash command
squashFlags := migrationSquashCmd.Flags()
squashFlags.StringVar(&migrationVersion, "version", "", "Squash up to the specified version.")
markFlagTelemetrySafe(squashFlags.Lookup("version"))
squashFlags.String("db-url", "", "Squashes migrations of the database specified by the connection string (must be percent-encoded).")
squashFlags.Bool("linked", false, "Squashes the migration history of the linked project.")
squashFlags.Bool("local", true, "Squashes the migration history of the local database.")
Expand Down
2 changes: 2 additions & 0 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func init() {
createFlags.BoolVarP(&interactive, "interactive", "i", true, "Enables interactive mode.")
cobra.CheckErr(createFlags.MarkHidden("interactive"))
createFlags.StringVar(&orgId, "org-id", "", "Organization ID to create the project in.")
markFlagTelemetrySafe(createFlags.Lookup("org-id"))
createFlags.StringVar(&dbPassword, "db-password", "", "Database password of the project.")
createFlags.Var(&region, "region", "Select a region close to you for the best performance.")
createFlags.String("plan", "", "Select a plan that suits your needs.")
Expand All @@ -143,6 +144,7 @@ func init() {

apiKeysFlags := projectsApiKeysCmd.Flags()
apiKeysFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
markFlagTelemetrySafe(apiKeysFlags.Lookup("project-ref"))

// Add commands to root
projectsCmd.AddCommand(projectsCreateCmd)
Expand Down
45 changes: 43 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/supabase/cli/internal/debug"
"github.com/supabase/cli/internal/telemetry"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -122,6 +123,24 @@ var (
fmt.Fprintln(os.Stderr, cmd.Root().Short)
fmt.Fprintf(os.Stderr, "Using profile: %s (%s)\n", utils.CurrentProfile.Name, utils.CurrentProfile.ProjectHost)
}
isTTY := telemetryIsTTY()
isCI := telemetryIsCI()
isAgent := telemetryIsAgent()
envSignals := telemetryEnvSignals()
service, err := telemetry.NewService(fsys, telemetry.Options{
Now: time.Now,
IsTTY: isTTY,
IsCI: isCI,
IsAgent: isAgent,
EnvSignals: envSignals,
CLIName: utils.Version,
})
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
} else {
ctx = telemetry.WithService(ctx, service)
}
ctx = telemetry.WithCommandContext(ctx, commandAnalyticsContext(cmd))
cmd.SetContext(ctx)
// Setup sentry last to ignore errors from parsing cli flags
apiHost, err := url.Parse(utils.GetSupabaseAPIHost())
Expand All @@ -137,11 +156,26 @@ var (

func Execute() {
defer recoverAndExit()
if err := rootCmd.Execute(); err != nil {
startedAt := time.Now()
executedCmd, err := rootCmd.ExecuteC()
if executedCmd != nil {
if service := telemetry.FromContext(executedCmd.Context()); service != nil {
_ = service.Capture(executedCmd.Context(), "cli_command_executed", map[string]any{
"exit_code": exitCode(err),
"duration_ms": time.Since(startedAt).Milliseconds(),
}, nil)
_ = service.Close()
}
}
if err != nil {
panic(err)
}
// Check upgrade last because --version flag is initialised after execute
version, err := checkUpgrade(rootCmd.Context(), afero.NewOsFs())
ctx := rootCmd.Context()
if executedCmd != nil {
ctx = executedCmd.Context()
}
version, err := checkUpgrade(ctx, afero.NewOsFs())
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
}
Expand All @@ -153,6 +187,13 @@ func Execute() {
}
}

func exitCode(err error) int {
if err != nil {
return 1
}
return 0
}

func checkUpgrade(ctx context.Context, fsys afero.Fs) (string, error) {
if shouldFetchRelease(fsys) {
version, err := utils.GetLatestRelease(ctx)
Expand Down
Loading
Loading