Skip to content

chore(site): Add XState Inspector #869

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
site @coder/coder-frontend
site @coder/frontend
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
Expand All @@ -36,7 +36,7 @@ updates:
- package-ecosystem: "npm"
directory: "/site/"
schedule:
interval: "daily"
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:

- run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
- run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: "make --output-sync -j gen"
- run: ./scripts/check_unstaged.sh

Expand Down
21 changes: 0 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,6 @@ linters-settings:
- name: var-declaration
- name: var-naming
- name: waitgroup-by-value
varnamelen:
ignore-names:
- err
- rw
- r
- i
- db
- t
- id
- wg
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
# variables, or "const <name>" for constants.
ignore-decls:
- rw http.ResponseWriter
- r *http.Request
- t testing.T
- t testing.TB
- ok bool
- wg sync.WaitGroup

issues:
# Rules listed here: https://github.com/securego/gosec#available-rules
Expand Down Expand Up @@ -264,5 +244,4 @@ linters:
- unconvert
- unused
- varcheck
- varnamelen
- wastedassign
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ archives:
- coder
files:
- README.md
format_overrides:
- goos: windows
format: zip

before:
hooks:
Expand Down
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ build: site/out bin
# Runs migrations to output a dump of the database.
coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
go run coderd/database/dump/main.go
.PHONY: coderd/database/dump.sql

# Generates Go code for querying the database.
coderd/database/generate: fmt/sql coderd/database/dump.sql coderd/database/query.sql
cd coderd/database && sqlc generate && rm db_tmp.go
cd coderd/database && gofmt -w -r 'Querier -> querier' *.go
cd coderd/database && gofmt -w -r 'Queries -> sqlQuerier' *.go
coderd/database/generate: fmt/sql coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
coderd/database/generate.sh
.PHONY: coderd/database/generate

fmt/prettier:
Expand All @@ -30,13 +29,18 @@ else
endif
.PHONY: fmt/prettier

fmt/sql: ./coderd/database/query.sql
npx sql-formatter \
--language postgresql \
--lines-between-queries 2 \
./coderd/database/query.sql \
--output ./coderd/database/query.sql
sed -i 's/@ /@/g' ./coderd/database/query.sql
fmt/sql: $(wildcard coderd/database/queries/*.sql)
# TODO: this is slightly slow
for fi in coderd/database/queries/*.sql; do \
npx sql-formatter \
--language postgresql \
--lines-between-queries 2 \
--tab-indent \
$$fi \
--output $$fi; \
done

sed -i 's/@ /@/g' ./coderd/database/queries/*.sql

fmt: fmt/prettier fmt/sql
.PHONY: fmt
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ $ coder workspaces create my-first-workspace
$ coder ssh my-first-workspace
```

### Working with Projects

You can edit the Terraform from a sample project:

```sh
$ coder projects init
$ cd gcp-linux/
$ vim main.tf
$ coder projects update gcp-linux
```

## Development

The code structure is inspired by [Basics of Unix Philosophy](https://homepage.cs.uri.edu/~thenry/resources/unix_art/ch01s06.html) and [Effective Go](https://go.dev/doc/effective_go).
Expand Down
31 changes: 31 additions & 0 deletions cli/cliui/cliui_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build darwin
// +build darwin

package cliui

import (
"golang.org/x/sys/unix"

"golang.org/x/xerrors"
)

func removeLineLengthLimit(inputFD int) (func(), error) {
termios, err := unix.IoctlGetTermios(inputFD, unix.TIOCGETA)
if err != nil {
return nil, xerrors.Errorf("get termios: %w", err)
}
newState := *termios
// MacOS has a default line limit of 1024. See:
// https://unix.stackexchange.com/questions/204815/terminal-does-not-accept-pasted-or-typed-lines-of-more-than-1024-characters
//
// This removes canonical input processing, so deletes will not function
// as expected. This _seems_ fine for most use-cases, but is unfortunate.
newState.Lflag &^= unix.ICANON
err = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, &newState)
if err != nil {
return nil, xerrors.Errorf("set termios: %w", err)
}
return func() {
_ = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, termios)
}, nil
}
10 changes: 10 additions & 0 deletions cli/cliui/cliui_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !darwin
// +build !darwin

package cliui

import "golang.org/x/xerrors"

func removeLineLengthLimit(_ int) (func(), error) {
return nil, xerrors.New("not implemented")
}
12 changes: 12 additions & 0 deletions cli/cliui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/signal"
"runtime"
"strings"

"github.com/bgentry/speakeasy"
Expand Down Expand Up @@ -42,10 +43,21 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
go func() {
var line string
var err error

inFile, valid := cmd.InOrStdin().(*os.File)
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
line, err = speakeasy.Ask("")
} else {
if runtime.GOOS == "darwin" && valid {
var restore func()
restore, err = removeLineLengthLimit(int(inFile.Fd()))
if err != nil {
errCh <- err
return
}
defer restore()
}

reader := bufio.NewReader(cmd.InOrStdin())
line, err = reader.ReadString('\n')

Expand Down
2 changes: 1 addition & 1 deletion cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func configSSH() *cobra.Command {
sshConfigContent = sshConfigContent[:startIndex-1] + sshConfigContent[endIndex+len(sshEndToken):]
}

workspaces, err := client.WorkspacesByUser(cmd.Context(), "")
workspaces, err := client.WorkspacesByUser(cmd.Context(), codersdk.Me)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/pty/ptytest"
"github.com/stretchr/testify/require"
)

func TestConfigSSH(t *testing.T) {
Expand All @@ -20,7 +22,7 @@ func TestConfigSSH(t *testing.T) {
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, project.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
tempFile, err := os.CreateTemp(t.TempDir(), "")
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func login() *cobra.Command {
}

_, err = client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
Email: email,
Username: username,
Organization: username,
Password: password,
Email: email,
Username: username,
OrganizationName: username,
Password: password,
})
if err != nil {
return xerrors.Errorf("create initial user: %w", err)
Expand Down Expand Up @@ -167,7 +167,7 @@ func login() *cobra.Command {
Secret: true,
Validate: func(token string) error {
client.SessionToken = token
_, err := client.User(cmd.Context(), "me")
_, err := client.User(cmd.Context(), codersdk.Me)
if err != nil {
return xerrors.New("That's not a valid token!")
}
Expand All @@ -180,7 +180,7 @@ func login() *cobra.Command {

// Login to get user data - verify it is OK before persisting
client.SessionToken = sessionToken
resp, err := client.User(cmd.Context(), "me")
resp, err := client.User(cmd.Context(), codersdk.Me)
if err != nil {
return xerrors.Errorf("get user: %w", err)
}
Expand Down
28 changes: 16 additions & 12 deletions cli/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"

"github.com/google/uuid"
"github.com/spf13/cobra"
"golang.org/x/xerrors"

Expand All @@ -20,42 +21,45 @@ func parameters() *cobra.Command {
return cmd
}

func parseScopeAndID(ctx context.Context, client *codersdk.Client, organization codersdk.Organization, rawScope string, name string) (codersdk.ParameterScope, string, error) {
func parseScopeAndID(ctx context.Context, client *codersdk.Client, organization codersdk.Organization, rawScope string, name string) (codersdk.ParameterScope, uuid.UUID, error) {
scope, err := parseParameterScope(rawScope)
if err != nil {
return scope, "", err
return scope, uuid.Nil, err
}
var scopeID string

var scopeID uuid.UUID
switch scope {
case codersdk.ParameterOrganization:
if name == "" {
scopeID = organization.ID
} else {
org, err := client.OrganizationByName(ctx, "", name)
org, err := client.OrganizationByName(ctx, codersdk.Me, name)
if err != nil {
return scope, "", err
return scope, uuid.Nil, err
}
scopeID = org.ID
}
case codersdk.ParameterProject:
project, err := client.ProjectByName(ctx, organization.ID, name)
if err != nil {
return scope, "", err
return scope, uuid.Nil, err
}
scopeID = project.ID.String()
scopeID = project.ID
case codersdk.ParameterUser:
user, err := client.User(ctx, name)
uid, _ := uuid.Parse(name)
user, err := client.User(ctx, uid)
if err != nil {
return scope, "", err
return scope, uuid.Nil, err
}
scopeID = user.ID
case codersdk.ParameterWorkspace:
workspace, err := client.WorkspaceByName(ctx, "", name)
workspace, err := client.WorkspaceByName(ctx, codersdk.Me, name)
if err != nil {
return scope, "", err
return scope, uuid.Nil, err
}
scopeID = workspace.ID.String()
scopeID = workspace.ID
}

return scope, scopeID, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {

// currentOrganization returns the currently active organization for the authenticated user.
func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
orgs, err := client.OrganizationsByUser(cmd.Context(), "me")
orgs, err := client.OrganizationsByUser(cmd.Context(), codersdk.Me)
if err != nil {
return codersdk.Organization{}, nil
}
Expand Down
Loading