Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Cleanup #179

Merged
merged 6 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Cleanup
  • Loading branch information
cmoog committed Nov 5, 2020
commit 6b28887857dabb10ecb56028da657bb422228aa7
15 changes: 11 additions & 4 deletions ci/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ pushd() { builtin pushd "$@" >/dev/null; }
popd() { builtin popd >/dev/null; }

set -euo pipefail
cd "$(dirname "$0")"

cd "$(git rev-parse --show-toplevel)/ci/steps"

tag=$(git describe --tags)

build() {
echo "Building coder-cli for $GOOS-$GOARCH..."
echo "--- building coder-cli for $GOOS-$GOARCH"

tmpdir=$(mktemp -d)
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
Expand All @@ -29,9 +30,15 @@ build() {
tar -czf "$artifact" coder
;;
"darwin")
if [[ ${CI-} ]]; then
artifact="coder-cli-$GOOS-$GOARCH.zip"
gon -log-level debug ./gon.json
mv coder.zip $artifact
else
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
echo "--- warning: not in ci, skipping signed release of darwin"
fi
;;
esac
popd
Expand All @@ -46,8 +53,8 @@ build() {
if [[ "$(uname)" == "Darwin" ]]; then
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build
else
echo "Warning: Darwin builds don't work on Linux."
echo "Please use an OSX machine to build Darwin tars."
echo "--- warning: Darwin builds don't work on Linux."
echo "--- please use an OSX machine to build Darwin tars."
fi

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 build
Expand Down
3 changes: 2 additions & 1 deletion ci/steps/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

set -euo pipefail

echo "Formatting..."
cd "$(git rev-parse --show-toplevel)"

echo "--- formatting"
go mod tidy
gofmt -w -s .
goimports -w "-local=$$(go list -m)" .
Expand Down
6 changes: 2 additions & 4 deletions ci/steps/gendocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

set -euo pipefail

echo "Generating docs..."

cd "$(dirname "$0")"
cd ../../
cd "$(git rev-parse --show-toplevel)"

echo "--- regenerating documentation"
rm -rf ./docs
mkdir ./docs
go run ./cmd/coder gen-docs ./docs
Expand Down
8 changes: 2 additions & 6 deletions ci/steps/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

set -eo pipefail

log() {
echo "--- $@"
}

cd "$(git rev-parse --show-toplevel)"

log "building integration test image"
echo "--- building integration test image"
docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest .

log "starting integration tests"
echo "--- starting integration tests"
go test ./ci/integration -count=1
5 changes: 1 addition & 4 deletions ci/steps/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

set -euo pipefail

echo "Linting..."

cd "$(dirname "$0")"
cd ../../
cd "$(git rev-parse --show-toplevel)"

echo "--- golangci-lint"
golangci-lint run -c .golangci.yml
3 changes: 1 addition & 2 deletions ci/steps/unit_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

echo "--- go test..."

echo "--- running unit tests"
go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)
18 changes: 8 additions & 10 deletions coder-sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ func (c *Client) newHTTPClient() (*http.Client, error) {
return nil, err
}

jar.SetCookies(c.BaseURL, []*http.Cookie{
{
Name: "session_token",
Value: c.Token,
MaxAge: 86400,
Path: "/",
HttpOnly: true,
Secure: c.BaseURL.Scheme == "https",
},
})
jar.SetCookies(c.BaseURL, []*http.Cookie{{
Name: "session_token",
Value: c.Token,
MaxAge: 86400,
Path: "/",
HttpOnly: true,
Secure: c.BaseURL.Scheme == "https",
}})

return &http.Client{Jar: jar}, nil
}
14 changes: 7 additions & 7 deletions coder-sdk/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var ErrPermissions = xerrors.New("insufficient permissions")
// ErrAuthentication describes the error case in which the requester has invalid authentication.
var ErrAuthentication = xerrors.New("invalid authentication")

// APIError is the expected payload format for our errors.
type APIError struct {
Err APIErrorMsg `json:"error"`
// apiError is the expected payload format for our errors.
type apiError struct {
Err apiErrorMsg `json:"error"`
}

// APIErrorMsg contains the rich error information returned by API errors.
type APIErrorMsg struct {
// apiErrorMsg contains the rich error information returned by API errors.
type apiErrorMsg struct {
Msg string `json:"msg"`
}

Expand All @@ -33,9 +33,9 @@ type HTTPError struct {
}

func (e *HTTPError) Error() string {
var msg APIError
var msg apiError
// Try to decode the payload as an error, if it fails or if there is no error message,
// return the response URL with the dump.
// return the response URL with the status.
if err := json.NewDecoder(e.Response.Body).Decode(&msg); err != nil || msg.Err.Msg == "" {
return fmt.Sprintf("%s: %d %s", e.Request.URL, e.StatusCode, e.Status)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func configSSHCmd() *cobra.Command {
}

func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
startToken := "# ------------START-CODER-ENTERPRISE-----------"
const startToken = "# ------------START-CODER-ENTERPRISE-----------"
startMessage := `# The following has been auto-generated by "coder config-ssh"
# to make accessing your Coder Enterprise environments easier.
#
Expand All @@ -46,7 +46,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
# coder config-ssh --remove
#
# You should not hand-edit this section, unless you are deleting it.`
endToken := "# ------------END-CODER-ENTERPRISE------------"
const endToken = "# ------------END-CODER-ENTERPRISE------------"

return func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
return nil
},
}
cmd.Flags().StringVarP(&org, "org", "o", "", "ID of the organization the environment should be created under.")
cmd.Flags().StringVarP(&org, "org", "o", "", "name of the organization the environment should be created under.")
cmd.Flags().StringVarP(&tag, "tag", "t", defaultImgTag, "tag of the image the environment will be based off of.")
cmd.Flags().Float32VarP(&cpu, "cpu", "c", 0, "number of cpu cores the environment should be provisioned with.")
cmd.Flags().Float32VarP(&memory, "memory", "m", 0, "GB of RAM an environment should be provisioned with.")
Expand Down