Skip to content
Merged
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
11 changes: 0 additions & 11 deletions .circleci/brew-deploy.sh

This file was deleted.

29 changes: 0 additions & 29 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,6 @@ jobs:
echo $SNAPCRAFT_LOGIN_FILE | base64 --decode --ignore-garbage > .snapcraft/snapcraft.cfg
snapcraft push *.snap --release stable

brew-deploy:
executor: mac
environment:
USER: circleci
TRAVIS: circleci
DESTDIR: /Users/distiller/dest
steps:
- checkout
- force-http-1
- run: |
mkdir $DESTDIR
curl -fLSs https://circle.ci/cli | DESTDIR="$DESTDIR" bash
- run: |
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
git config --global user.name "$GH_NAME" > /dev/null 2>&1
- run: brew --version
- run: brew tap --force homebrew/core
- run: ./.circleci/brew-deploy.sh

chocolatey-deploy:
executor: windows/default
steps:
Expand Down Expand Up @@ -368,16 +349,6 @@ workflows:
- chocolatey-deploy:
requires:
- deploy
# Only deploy to homebrew after manual approval.
- run-brew-deploy-gate:
type: approval
requires:
- deploy
- brew-deploy:
requires:
- run-brew-deploy-gate
context:
- devex-release
- deploy:
requires:
- cucumber
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ We publish the tool to [Homebrew](https://brew.sh/). The tool is [part of `homeb

The particular considerations that we make are:


1. Since Homebrew [doesn't "like tools that upgrade themselves"](https://docs.brew.sh/Acceptable-Formulae#we-dont-like-tools-that-upgrade-themselves), we disable the `circleci update` command when the tool is released through homebrew. We do this by [defining the PackageManager](https://github.com/Homebrew/homebrew-core/blob/eb1fdb84e2924289bcc8c85ee45081bf83dc024d/Formula/circleci.rb#L28) constant to `homebrew`, which allows us to [disable the `update` command at runtime](https://github.com/CircleCI-Public/circleci-cli/blob/67c7d52bace63846f87a1ed79f67f257c94a55b4/cmd/root.go#L119-L123).
1. We want to avoid every push to `main` from creating a Pull Request to the `circleci` formula on Homebrew. We want to avoid overloading the Homebrew team with pull requests to update our formula for small changes (changes to docs or other files that don't change functionality in the tool).

#### Releasing to Homebrew

This project is on Homebrew's special [autobump list](https://github.com/Homebrew/homebrew-core/blob/master/.github/autobump.txt) which effectively means that it will check our `main` branch every 3 hours for updates and create a PR automagically if there are any changes. This is great, but you do have to monitor the generated PRs to ensure they pass and do get merged in successfully. The PRs will be raised in this repo: [github.com/Homebrew/homebrew-core](https://github.com/Homebrew/homebrew-core) and you can search the Pull requests for `circleci` to see the generated PRs.

Upon successful merge, you'll be able to upgrade the tool by running `brew upgrade circleci` and then you can validate any changes you may have made.

### Snap

Expand Down
46 changes: 34 additions & 12 deletions cmd/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -67,6 +68,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
return validateToken(config)
}

jsonFormat := false

command := &cobra.Command{
Use: "context",
Long: `Contexts provide a mechanism for securing and sharing environment variables across
Expand Down Expand Up @@ -94,13 +97,14 @@ are injected at runtime.`,
return err
}

return listContexts(contextClient, org.Organization.Name, org.Organization.ID)
return listContexts(cmd, contextClient, org.Organization.Name, org.Organization.ID)
},
Args: MultiExactArgs(0, 2),
Example: `circleci context list --org-id 00000000-0000-0000-0000-000000000000
(deprecated usage) circleci context list <vcs-type> <org-name>`,
}
listCommand.Flags().StringVar(&orgID, "org-id", "", orgIDUsage)
listCommand.Flags().BoolVar(&jsonFormat, "json", false, "Return output back in JSON format")

showContextCommand := &cobra.Command{
Short: "Show a context",
Expand Down Expand Up @@ -206,23 +210,41 @@ are injected at runtime.`,
return command
}

func listContexts(contextClient context.ContextInterface, orgName string, orgId string) error {
func listContexts(cmd *cobra.Command, contextClient context.ContextInterface, orgName string, orgId string) error {
contexts, err := contextClient.Contexts()
if err != nil {
return err
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Organization", "Org ID", "Name", "Created At"})
for _, context := range contexts {
table.Append([]string{
orgName,
orgId,
context.Name,
context.CreatedAt.Format(time.RFC3339),
})
jsonVal, err := cmd.Flags().GetBool("json")
if err != nil {
return err
}
table.Render()

if jsonVal {
// return JSON formatted for output
jsonCtxs, err := json.Marshal(contexts)
if err != nil {
return err
}
jsonWriter := cmd.OutOrStdout()
if _, err := jsonWriter.Write(jsonCtxs); err != nil {
return err
}
} else {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Organization", "Org ID", "Name", "Created At"})
for _, context := range contexts {
table.Append([]string{
orgName,
orgId,
context.Name,
context.CreatedAt.Format(time.RFC3339),
})
}
table.Render()
}

return nil
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/create_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ func TestLoadTelemetrySettings(t *testing.T) {
UniqueID: uniqueId,
},
telemetryEvents: []telemetry.Event{
{Object: "cli-telemetry", Action: "enabled",
{
Object: "cli-telemetry", Action: "enabled",
Properties: map[string]interface{}{
"UUID": uniqueId,
"user_id": userId,
"is_self_hosted": false,
}},
},
},
},
},
},
Expand Down
38 changes: 31 additions & 7 deletions cmd/info/info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package info

import (
"encoding/json"

"github.com/CircleCI-Public/circleci-cli/api/info"
"github.com/CircleCI-Public/circleci-cli/cmd/validator"
"github.com/CircleCI-Public/circleci-cli/settings"
Expand All @@ -20,6 +22,8 @@ type infoOptions struct {
func NewInfoCommand(config *settings.Config, preRunE validator.Validator) *cobra.Command {
client, _ := info.NewInfoClient(*config)

jsonFormat := false

opts := infoOptions{
cfg: config,
validator: preRunE,
Expand All @@ -29,6 +33,8 @@ func NewInfoCommand(config *settings.Config, preRunE validator.Validator) *cobra
Short: "Check information associated to your user account.",
}
orgInfoCmd := orgInfoCommand(client, opts)
orgInfoCmd.PersistentFlags().BoolVar(&jsonFormat, "json", false,
"Return output back in JSON format")
infoCommand.AddCommand(orgInfoCmd)

return infoCommand
Expand Down Expand Up @@ -63,15 +69,33 @@ func getOrgInformation(cmd *cobra.Command, client info.InfoClient) error {
return err
}

table := tablewriter.NewWriter(cmd.OutOrStdout())
jsonVal, err := cmd.Flags().GetBool("json")
if err != nil {
return err
}

table.SetHeader([]string{"ID", "Name"})
if jsonVal {
// return JSON formatted for output
jsonResp, err := json.Marshal(resp)
if err != nil {
return err
}
jsonWriter := cmd.OutOrStdout()
if _, err := jsonWriter.Write(jsonResp); err != nil {
return err
}
} else {
table := tablewriter.NewWriter(cmd.OutOrStdout())

for _, info := range *resp {
table.Append([]string{
info.ID, info.Name,
})
table.SetHeader([]string{"ID", "Name"})

for _, info := range *resp {
table.Append([]string{
info.ID, info.Name,
})
}
table.Render()
}
table.Render()

return nil
}
2 changes: 1 addition & 1 deletion cmd/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestTelemetry(t *testing.T) {
assert.DeepEqual(t, telemetryClient.events, []telemetry.Event{
telemetry.CreateInfoEvent(telemetry.CommandInfo{
Name: "org",
LocalArgs: map[string]string{"help": "false"},
LocalArgs: map[string]string{"help": "false", "json": "false"},
}, nil),
})
}
Expand Down
60 changes: 51 additions & 9 deletions cmd/project/environment_variable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project

import (
"encoding/json"
"fmt"
"strings"

Expand All @@ -16,6 +17,8 @@ func newProjectEnvironmentVariableCommand(ops *projectOpts, preRunE validator.Va
Short: "Operate on environment variables of projects",
}

jsonFormat := false

listVarsCommand := &cobra.Command{
Short: "List all environment variables of a project",
Use: "list <vcs-type> <org-name> <project-name>",
Expand All @@ -39,6 +42,11 @@ func newProjectEnvironmentVariableCommand(ops *projectOpts, preRunE validator.Va

createVarCommand.Flags().StringVar(&envValue, "env-value", "", "An environment variable value to be created. You can also pass it by stdin without this option.")

listVarsCommand.PersistentFlags().BoolVar(&jsonFormat, "json", false,
"Return output back in JSON format")
createVarCommand.PersistentFlags().BoolVar(&jsonFormat, "json", false,
"Return output back in JSON format")

cmd.AddCommand(listVarsCommand)
cmd.AddCommand(createVarCommand)
return cmd
Expand All @@ -50,14 +58,31 @@ func listProjectEnvironmentVariables(cmd *cobra.Command, client projectapi.Proje
return err
}

table := tablewriter.NewWriter(cmd.OutOrStdout())
jsonVal, err := cmd.Flags().GetBool("json")
if err != nil {
return err
}

if jsonVal {
// return JSON formatted for output
jsonEnvVars, err := json.Marshal(envVars)
if err != nil {
return err
}
jsonWriter := cmd.OutOrStdout()
if _, err := jsonWriter.Write(jsonEnvVars); err != nil {
return err
}
} else {
table := tablewriter.NewWriter(cmd.OutOrStdout())

table.SetHeader([]string{"Environment Variable", "Value"})
table.SetHeader([]string{"Environment Variable", "Value"})

for _, envVar := range envVars {
table.Append([]string{envVar.Name, envVar.Value})
for _, envVar := range envVars {
table.Append([]string{envVar.Name, envVar.Value})
}
table.Render()
}
table.Render()

return nil
}
Expand Down Expand Up @@ -95,11 +120,28 @@ func createProjectEnvironmentVariable(cmd *cobra.Command, client projectapi.Proj
return err
}

table := tablewriter.NewWriter(cmd.OutOrStdout())
jsonVal, err := cmd.Flags().GetBool("json")
if err != nil {
return err
}

table.SetHeader([]string{"Environment Variable", "Value"})
table.Append([]string{v.Name, v.Value})
table.Render()
if jsonVal {
// return JSON formatted for output
jsonV, err := json.Marshal(v)
if err != nil {
return err
}
jsonWriter := cmd.OutOrStdout()
if _, err := jsonWriter.Write(jsonV); err != nil {
return err
}
} else {
table := tablewriter.NewWriter(cmd.OutOrStdout())

table.SetHeader([]string{"Environment Variable", "Value"})
table.Append([]string{v.Name, v.Value})
table.Render()
}

return nil
}
Loading