Skip to content

Commit

Permalink
Merge branch 'main' into sentry-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge authored Dec 15, 2023
2 parents 407f21c + 6d96e66 commit 5f0e617
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 137 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -67,4 +67,4 @@ jobs:
run: go build .

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
14 changes: 8 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

var (
createVscodeWorkspace = new(bool)
useOrioleDB bool
createVscodeSettings = new(bool)
useOrioleDB bool

initCmd = &cobra.Command{
GroupID: groupLocalDev,
Expand All @@ -30,10 +30,10 @@ var (
},
RunE: func(cmd *cobra.Command, args []string) error {
fsys := afero.NewOsFs()
if !cmd.Flags().Changed("with-vscode-workspace") {
createVscodeWorkspace = nil
if !cmd.Flags().Changed("with-vscode-settings") && !cmd.Flags().Changed("with-vscode-workspace") {
createVscodeSettings = nil
}
return _init.Run(fsys, createVscodeWorkspace, useOrioleDB)
return _init.Run(fsys, createVscodeSettings, useOrioleDB)
},
PostRun: func(cmd *cobra.Command, args []string) {
fmt.Println("Finished " + utils.Aqua("supabase init") + ".")
Expand All @@ -43,7 +43,9 @@ var (

func init() {
flags := initCmd.Flags()
flags.BoolVar(createVscodeWorkspace, "with-vscode-workspace", false, "Generate VS Code workspace.")
flags.BoolVar(createVscodeSettings, "with-vscode-workspace", false, "Generate VS Code workspace.")
cobra.CheckErr(flags.MarkHidden("with-vscode-workspace"))
flags.BoolVar(createVscodeSettings, "with-vscode-settings", false, "Generate VS Code settings for Deno.")
flags.BoolVar(&useOrioleDB, "use-orioledb", false, "Use OrioleDB storage engine for Postgres")
rootCmd.AddCommand(initCmd)
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.20
require (
github.com/BurntSushi/toml v1.3.2
github.com/andybalholm/brotli v1.0.6
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/bubbles v0.17.1
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/containers/common v0.57.1
Expand All @@ -20,7 +20,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2
github.com/golang-jwt/jwt/v5 v5.2.0
github.com/google/go-github/v53 v53.2.0
github.com/google/uuid v1.4.0
github.com/google/uuid v1.5.0
github.com/jackc/pgx/v4 v4.18.1
github.com/joho/godotenv v1.5.1
github.com/matoous/go-nanoid/v2 v2.0.0
Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/prometheus/procfs v0.6.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=
github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg=
github.com/charmbracelet/bubbles v0.17.1 h1:0SIyjOnkrsfDo88YvPgAWvZMwXe26TP6drRvmkjyUu4=
github.com/charmbracelet/bubbles v0.17.1/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc=
github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
Expand Down Expand Up @@ -240,8 +240,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand Down Expand Up @@ -505,8 +505,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
3 changes: 3 additions & 0 deletions internal/db/dump/templates/dump_data.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

# Disable triggers so that data dump can be restored exactly as it is
echo "SET session_replication_role = replica;\n"

# Explanation of pg_dump flags:
#
# --exclude-schema omit data from internal schemas as they are maintained by platform
Expand Down
4 changes: 3 additions & 1 deletion internal/db/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ func NewContainerConfig() container.Config {
"POSTGRES_PASSWORD=" + utils.Config.Db.Password,
"POSTGRES_HOST=/var/run/postgresql",
"POSTGRES_INITDB_ARGS=--lc-ctype=C.UTF-8",
"POSTGRES_INITDB_ARGS=--lc-collate=C.UTF-8",
"JWT_SECRET=" + utils.Config.Auth.JwtSecret,
fmt.Sprintf("JWT_EXP=%d", utils.Config.Auth.JwtExpiry),
}
if len(utils.Config.Experimental.OrioleDBVersion) > 0 {
env = append(env,
"POSTGRES_INITDB_ARGS=--lc-collate=C",
fmt.Sprintf("S3_ENABLED=%t", true),
"S3_HOST="+utils.Config.Experimental.S3Host,
"S3_REGION="+utils.Config.Experimental.S3Region,
"S3_ACCESS_KEY="+utils.Config.Experimental.S3AccessKey,
"S3_SECRET_KEY="+utils.Config.Experimental.S3SecretKey,
)
} else {
env = append(env, "POSTGRES_INITDB_ARGS=--lc-collate=C.UTF-8")
}
config := container.Config{
Image: utils.Config.Db.Image,
Expand Down
106 changes: 68 additions & 38 deletions internal/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package init

import (
_ "embed"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"

Expand All @@ -12,19 +14,21 @@ import (
)

var (
vscodeDir = ".vscode"
extensionsPath = filepath.Join(vscodeDir, "extensions.json")
settingsPath = filepath.Join(vscodeDir, "settings.json")

//go:embed templates/.gitignore
initGitignore []byte
//go:embed templates/.vscode/extensions.json
vscodeExtensions string
//go:embed templates/.vscode/settings.json
vscodeSettings string
//go:embed templates/.code-workspace
vscodeWorkspaceConfig string

errAlreadyInitialized = errors.New("Project already initialized. Remove " + utils.Bold(utils.ConfigPath) + " to reinitialize.")
)

func Run(fsys afero.Fs, createVscodeWorkspace *bool, useOrioleDB bool) error {
func Run(fsys afero.Fs, createVscodeSettings *bool, useOrioleDB bool) error {
// Sanity checks.
{
if _, err := fsys.Stat(utils.ConfigPath); err == nil {
Expand All @@ -51,13 +55,13 @@ func Run(fsys afero.Fs, createVscodeWorkspace *bool, useOrioleDB bool) error {
}
}

// 4. Generate VS Code workspace settings.
if createVscodeWorkspace != nil {
if *createVscodeWorkspace {
// 4. Generate VS Code settings.
if createVscodeSettings != nil {
if *createVscodeSettings {
return writeVscodeConfig(fsys)
}
} else {
if isVscode := utils.PromptYesNo("Generate VS Code workspace settings?", false, os.Stdin); isVscode {
if isVscode := utils.PromptYesNo("Generate VS Code settings for Deno?", false, os.Stdin); isVscode {
return writeVscodeConfig(fsys)
}
}
Expand Down Expand Up @@ -90,39 +94,65 @@ func updateGitIgnore(ignorePath string, fsys afero.Fs) error {
return nil
}

func writeVscodeConfig(fsys afero.Fs) error {
{
// Create mutli-root code-workspace.
cwd, err := os.Getwd()
if err != nil {
return err
}
codeWorkspaceConfigPath := filepath.Join(cwd, filepath.Base(cwd)+".code-workspace")
if _, err := fsys.Stat(codeWorkspaceConfigPath); !errors.Is(err, os.ErrNotExist) {
// TODO: prompt to overwrite if config already exists
return err
}
if err := afero.WriteFile(fsys, codeWorkspaceConfigPath, []byte(vscodeWorkspaceConfig), 0644); err != nil {
return err
}
fmt.Println("Open the " + utils.Aqua(filepath.Base(codeWorkspaceConfigPath)) + " file in VS Code.")
type VSCodeSettings map[string]interface{}

func loadUserSettings(path string, fsys afero.Fs) (VSCodeSettings, error) {
// Open our jsonFile
jsonFile, err := fsys.Open(path)
if err != nil {
return nil, fmt.Errorf("failed to load %s: %w", utils.Bold(path), err)
}
defer jsonFile.Close()
// Parse and unmarshal JSON file.
var userSettings VSCodeSettings
dec := json.NewDecoder(jsonFile)
if err := dec.Decode(&userSettings); err != nil {
return nil, fmt.Errorf("failed to parse %s: %w", utils.Bold(path), err)
}
return userSettings, nil
}

{
// Create functions workspace settings.
vscodeDir := filepath.Join(utils.FunctionsDir, ".vscode")
if _, err := fsys.Stat(vscodeDir); !errors.Is(err, os.ErrNotExist) {
return err
}
if err := utils.MkdirIfNotExistFS(fsys, vscodeDir); err != nil {
return err
}
if err := afero.WriteFile(fsys, filepath.Join(vscodeDir, "extensions.json"), []byte(vscodeExtensions), 0644); err != nil {
return err
}
if err := afero.WriteFile(fsys, filepath.Join(vscodeDir, "settings.json"), []byte(vscodeSettings), 0644); err != nil {
return err
}
func saveUserSettings(path string, settings VSCodeSettings, fsys afero.Fs) error {
// Open our jsonFile
jsonFile, err := fsys.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return fmt.Errorf("failed to open %s: %w", utils.Bold(path), err)
}
defer jsonFile.Close()
// Marshal JSON to file.
enc := json.NewEncoder(jsonFile)
enc.SetIndent("", " ")
if err := enc.Encode(settings); err != nil {
return fmt.Errorf("failed to save %s: %w", utils.Bold(path), err)
}
return nil
}

func updateJsonFile(path string, template string, fsys afero.Fs) error {
userSettings, err := loadUserSettings(path, fsys)
if errors.Is(err, os.ErrNotExist) || errors.Is(err, io.EOF) {
return afero.WriteFile(fsys, path, []byte(template), 0644)
} else if err != nil {
return err
}
// Merge template into user settings.
if err := json.Unmarshal([]byte(template), &userSettings); err != nil {
return fmt.Errorf("failed to copy template: %w", err)
}
return saveUserSettings(path, userSettings, fsys)
}

func writeVscodeConfig(fsys afero.Fs) error {
// Create VS Code settings for Deno.
if err := utils.MkdirIfNotExistFS(fsys, vscodeDir); err != nil {
return err
}
if err := updateJsonFile(extensionsPath, vscodeExtensions, fsys); err != nil {
return err
}
if err := updateJsonFile(settingsPath, vscodeSettings, fsys); err != nil {
return err
}
fmt.Println("Generated VS Code settings in " + utils.Bold(settingsPath) + ". Please install the recommended extension!")
return nil
}
Loading

0 comments on commit 5f0e617

Please sign in to comment.