Commit Graph

20 Commits

Author SHA1 Message Date
Bolaji Olajide
4d57eb1188
fix(sg): make sg gen output more readable (#64406)
Closes DINF-78

The output of `sg gen` is a bit hard to read when there's an error, this
is because the new line character `\n` isn't rendered as a new line. It
turns out the `%q` formatting directive used to quote a string doesn't
render the `\n` character as a new line.

| Before |
|---|
| ![CleanShot 2024-08-12 at 11 17
57@2x](https://github.com/user-attachments/assets/e03ec503-e437-4b68-80b3-fe34ac8848fb)
|

| After  |
|---|
| ![CleanShot 2024-08-12 at 10 53
35@2x](https://github.com/user-attachments/assets/5b7aac63-27b6-4de0-9c56-3b739f0ee0f9)
|

I also added a func to extract error messages from a bazel command to
avoid long output message when a bazel command fails and give the user
relevant messages related to the error.

| Before  |
|---|


https://github.com/user-attachments/assets/2d029ec1-5804-41bf-a675-8642e169ea80


| After  |
|---|
| ![CleanShot 2024-08-12 at 14 45
59@2x](https://github.com/user-attachments/assets/7d567fd6-de37-48aa-b2b5-03dc591fc77a)
|

## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

* Manual testing

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 06:22:21 -05:00
Jean-Hadrien Chabran
4591d989a6
chore(local): clear ambiguity in between sg version|live (#64122)
Context: As I was catching up with my Slack notifications, I spotted
this
[conversation](https://sourcegraph.slack.com/archives/C04MYFW01NV/p1721137862832899?thread_ts=1721136881.733869&cid=C04MYFW01NV)
and this PR is a 5m fix to avoid the problem to happen again.

What: If you haven't used `sg` in a while, it's easy to think that `sg
version` refers to the currently deployed Sourcegraph instance and not
the CLI. This commit adds a little preamble on stderr to not mess with
script usage while still reminding the user that it's the CLI version
that gets printed out.

Before: we printed the version without any context
After: we also print the following on stderr: `👉 Showing the current
version of the sg CLI, if you're looking for deployed Sourcegraph
instances version, please use `sg live` instead.`. Stderr so we don't
break things like `$(sg version)`.

Note: at a broader level, we should generalize this pattern, we don't
use too much `sg` raw output in scripts, but for the few places where
it's the case, it's a footgun.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

Locally tested + CI. 

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

- `sg version` explicitly mentions that it's the CLI version that's
printed out, not any instance version.

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-07 18:34:38 +02:00
Robert Lin
1ff9bc70eb
sg-binary-release: stamp with GitHub release name (#62176)
We have nice release names in https://github.com/sourcegraph/sg/releases, but it's not actually programmatically available - this causes a discrepancy between the `sg` version one might pull, and the version of `sg` that is known in-code, and means that we can't do something like #62134.

This change adds a `ReleaseName` variable to be stamped at build/release time, and updates a few references to `BuildCommit` where I think it might be more prudent to report `ReleaseName` instead, and also fixes some yellow squiggles in my IDE on files I visited (sorry) and some noisy `-v` output (sorry again)

## Test plan

```
$ go build -ldflags "-s -w -X main.BuildCommit=$(git rev-list -1 HEAD .) -X main.ReleaseName=hello-world" -o ./sg ./dev/sg                       
$ ./sg version
hello-world
$ ./sg -v version
Version: hello-world
Build commit: b23db0be5e
```
2024-04-25 08:10:55 -07:00
Robert Lin
331f156083
sg msp: initial prototype (#55905)
The eventual goal is to be able to generate a spec somewhat close to the infrastructure definitions for Cody Gateway today based on the way we generate infrastructure for Cloud - see go/rfc-msp . This PR is a first-step prototype to demonstrate CDKTF integration, draft out the sketch as proposed in go/rfc-msp, and lay out some basic architecture for the stuff. A barebones CDKTF setup that imitates ~most of the Cody Gateway setup can be generated and interacted with (see test plan), but has not been applied live anywhere - a few components are still missing, and a migration plan needs to be determined.

The current goal is to land this PR as-is and iterate from here. The new command set `sg msp` is only included with the `msp` build tag, so it won't be distributed just yet. To install a version of `sg` that includes a functional `sg msp` command, run:

```
go build -tags=msp -o=./sg ./dev/sg && ./sg install -f -p=false
```

In a vanilla build of `sg`, you'll get an error when trying to use `sg msp`:

![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/15c6cde2-25c2-439e-b41d-b674cc36f23f)

## Binary size

Thanks to Michael's improvements to generated CDKTF Go modules, we are not looking at a 500MB increase in `sg` binary sizes, but we are still faced with a ~20% increase at the moment:

```sh
# Fresh sg installation
$ curl --proto '=https' --tlsv1.2 -sSLf https://install.sg.dev | sh
$ du -h $(which sg) 
132M    /Users/robert@sourcegraph.com/.sg/sg
# MSP-enabled sg build
$ go build -tags=msp -o=./sg ./dev/sg && du -h ./sg 
161M    ./sg
```

However, the _default_ build of `sg` continues to not include `msp`, so the binary size remains the same:

```sh
$ go build -o=./sg ./dev/sg && du -h ./sg      
132M    ./sg
```

## Architecture

See `dev/managedservicesplatform/internal/stack/README.md` and `dev/managedservicesplatform/internal/resource/README.md` for some rudimentary docs on some CDKTF conventions.

## Specifications

Set up initial specifications here: https://github.com/sourcegraph/managed-services

## Test plan

Currently:

```
go build -tags=msp -o=./sg ./dev/sg && ./sg msp generate -o=./tmp ./dev/sg/msp/example/example-service.service.yaml dev
```

And check out the `./tmp` output. Each module is plan-able out of the box right now, as we default to a local Terraform backend:

```
cd ./tmp
asdf install # a .tool-versions is generated
cd stacks/project 
terraform init
terraform plan
```

---------

Co-authored-by: Joe Chen <joe@sourcegraph.com>
2023-09-07 17:24:34 -07:00
Robert Lin
0a4c119b65
dev/sg: add pending spinner to manual 'sg update', fix autoupdate output (#38679) 2022-07-12 12:44:21 -07:00
Robert Lin
769cf30a25
dev/sg: add background package, move updates to background (#38497)
Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
2022-07-12 09:38:28 -07:00
William Bezuidenhout
44e993025e
refactor(sg): use cli.Action instead of execAdaptor (#36735)
* migrate all sg commands to use *cli.Action
* remove execAdaptor
2022-06-07 18:42:19 +02:00
Robert Lin
7105127ec5
dev/sg: fix sg auto-update analytics (#35398)
syscall.Exec will cause the current command's finalizer to not run, so we make a custom call to Persist to make sure the auto_update event is tracked in success scenarios.

Also logs unexpected error events and skip events during auto-updates.
2022-05-13 11:12:23 +02:00
Robert Lin
4abaacec73
dev/sg: rework output and add Buildkite log headers (#35269)
Four major changes:

- Rename stdout to std, so that it reads nicer: std.Out instead of stdout.Out
- Wrap output.Output with std.Output so that we can build wrappers on top. This wrapper is also used to generate Buildkite log output anchors (https://buildkite.com/docs/pipelines/managing-log-output), which helps us manage CI output.
- Migrating printing.go into std.Output, and rename a few to make them more purposeful: orangeLinef -> WriteAlertf, and so on. This will help us align sg output across the tool. Moving to std.Out also allows sg packages outside of main to share formatting primitives.
- Add aliases for Line and Linef that does not provide all arguments: output.Styled, output.Emoji, and friends. The pattern of omitting output.Style or emoji is so common that I think it is worth introducing special aliases for them to avoid constantly having to enter blank arguments.

Minor changes:

- Add an error handler that writes pretty failure notice instead
- Introduce NewEmptyExitErr for denoting exit errors, instead of using os.Exit
2022-05-11 17:42:18 +00:00
Robert Lin
a4b1952846
dev/sg: track local sg analytics that can be submitted manually (#35033) 2022-05-09 09:06:35 -07:00
Robert Lin
71f56507ac
dev/sg: detect completion mode and omit setup (#33874) 2022-04-14 09:46:38 +02:00
Robert Lin
d1a0fd7ad1
dev/ci: fetch before update/changelog check, remove debug print (#33868) 2022-04-13 17:55:29 +00:00
Robert Lin
fc1e1b36e0
dev/sg: improve update clarity, fix changelog (#33860) 2022-04-13 17:23:17 +00:00
Robert Lin
66062653ce
dev/sg: migrate to urfave/cli (#33758)
This enables better flag handlers, a nicer way to build commands, aliases for commands and flags, and more!
2022-04-13 14:57:29 +00:00
Robert Lin
58434a8249
dev/sg: use TrimPrefix instead of TrimLeft (#32022) 2022-03-02 08:46:29 -08:00
Robert Lin
e3b35a01fa
dev/sg: only look for revisions in main (#32012) 2022-03-01 14:38:43 -08:00
Robert Lin
7648403b96
dev/sg: do not show merges in sg version changelog (#30726) 2022-02-07 10:04:34 +01:00
Robert Lin
3d4eefe801
dev/sg: introduce 'sg version changelog' (#30697) 2022-02-05 09:07:00 -08:00
Thorsten Ball
75375dd6f5
sg: be consistent and always use stdout.Out, not global out (#29182) 2021-12-17 13:57:57 +00:00
Thorsten Ball
36805e227e
Add 'sg version' cmd and fix setting of commit (#26563) 2021-10-25 09:31:52 +00:00