Skip to content

Commit d2e8a96

Browse files
authored
Merge pull request #1128 from CircleCI-Public/develop
Cutting a new release
2 parents 5390914 + f862a56 commit d2e8a96

16 files changed

+194
-86
lines changed

.circleci/brew-deploy.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,6 @@ jobs:
265265
echo $SNAPCRAFT_LOGIN_FILE | base64 --decode --ignore-garbage > .snapcraft/snapcraft.cfg
266266
snapcraft push *.snap --release stable
267267
268-
brew-deploy:
269-
executor: mac
270-
environment:
271-
USER: circleci
272-
TRAVIS: circleci
273-
DESTDIR: /Users/distiller/dest
274-
steps:
275-
- checkout
276-
- force-http-1
277-
- run: |
278-
mkdir $DESTDIR
279-
curl -fLSs https://circle.ci/cli | DESTDIR="$DESTDIR" bash
280-
- run: |
281-
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
282-
git config --global user.name "$GH_NAME" > /dev/null 2>&1
283-
- run: brew --version
284-
- run: brew tap --force homebrew/core
285-
- run: ./.circleci/brew-deploy.sh
286-
287268
chocolatey-deploy:
288269
executor: windows/default
289270
steps:
@@ -368,16 +349,6 @@ workflows:
368349
- chocolatey-deploy:
369350
requires:
370351
- deploy
371-
# Only deploy to homebrew after manual approval.
372-
- run-brew-deploy-gate:
373-
type: approval
374-
requires:
375-
- deploy
376-
- brew-deploy:
377-
requires:
378-
- run-brew-deploy-gate
379-
context:
380-
- devex-release
381352
- deploy:
382353
requires:
383354
- cucumber

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,13 @@ We publish the tool to [Homebrew](https://brew.sh/). The tool is [part of `homeb
160160

161161
The particular considerations that we make are:
162162

163-
164163
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).
165-
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).
164+
165+
#### Releasing to Homebrew
166+
167+
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.
168+
169+
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.
166170

167171
### Snap
168172

cmd/context.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"io"
67
"os"
@@ -67,6 +68,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
6768
return validateToken(config)
6869
}
6970

71+
jsonFormat := false
72+
7073
command := &cobra.Command{
7174
Use: "context",
7275
Long: `Contexts provide a mechanism for securing and sharing environment variables across
@@ -94,13 +97,14 @@ are injected at runtime.`,
9497
return err
9598
}
9699

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

105109
showContextCommand := &cobra.Command{
106110
Short: "Show a context",
@@ -206,23 +210,41 @@ are injected at runtime.`,
206210
return command
207211
}
208212

209-
func listContexts(contextClient context.ContextInterface, orgName string, orgId string) error {
213+
func listContexts(cmd *cobra.Command, contextClient context.ContextInterface, orgName string, orgId string) error {
210214
contexts, err := contextClient.Contexts()
211215
if err != nil {
212216
return err
213217
}
214218

215-
table := tablewriter.NewWriter(os.Stdout)
216-
table.SetHeader([]string{"Organization", "Org ID", "Name", "Created At"})
217-
for _, context := range contexts {
218-
table.Append([]string{
219-
orgName,
220-
orgId,
221-
context.Name,
222-
context.CreatedAt.Format(time.RFC3339),
223-
})
219+
jsonVal, err := cmd.Flags().GetBool("json")
220+
if err != nil {
221+
return err
224222
}
225-
table.Render()
223+
224+
if jsonVal {
225+
// return JSON formatted for output
226+
jsonCtxs, err := json.Marshal(contexts)
227+
if err != nil {
228+
return err
229+
}
230+
jsonWriter := cmd.OutOrStdout()
231+
if _, err := jsonWriter.Write(jsonCtxs); err != nil {
232+
return err
233+
}
234+
} else {
235+
table := tablewriter.NewWriter(os.Stdout)
236+
table.SetHeader([]string{"Organization", "Org ID", "Name", "Created At"})
237+
for _, context := range contexts {
238+
table.Append([]string{
239+
orgName,
240+
orgId,
241+
context.Name,
242+
context.CreatedAt.Format(time.RFC3339),
243+
})
244+
}
245+
table.Render()
246+
}
247+
226248
return nil
227249
}
228250

cmd/create_telemetry_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ func TestLoadTelemetrySettings(t *testing.T) {
6060
UniqueID: uniqueId,
6161
},
6262
telemetryEvents: []telemetry.Event{
63-
{Object: "cli-telemetry", Action: "enabled",
63+
{
64+
Object: "cli-telemetry", Action: "enabled",
6465
Properties: map[string]interface{}{
6566
"UUID": uniqueId,
6667
"user_id": userId,
6768
"is_self_hosted": false,
68-
}},
69+
},
70+
},
6971
},
7072
},
7173
},

cmd/info/info.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package info
22

33
import (
4+
"encoding/json"
5+
46
"github.com/CircleCI-Public/circleci-cli/api/info"
57
"github.com/CircleCI-Public/circleci-cli/cmd/validator"
68
"github.com/CircleCI-Public/circleci-cli/settings"
@@ -20,6 +22,8 @@ type infoOptions struct {
2022
func NewInfoCommand(config *settings.Config, preRunE validator.Validator) *cobra.Command {
2123
client, _ := info.NewInfoClient(*config)
2224

25+
jsonFormat := false
26+
2327
opts := infoOptions{
2428
cfg: config,
2529
validator: preRunE,
@@ -29,6 +33,8 @@ func NewInfoCommand(config *settings.Config, preRunE validator.Validator) *cobra
2933
Short: "Check information associated to your user account.",
3034
}
3135
orgInfoCmd := orgInfoCommand(client, opts)
36+
orgInfoCmd.PersistentFlags().BoolVar(&jsonFormat, "json", false,
37+
"Return output back in JSON format")
3238
infoCommand.AddCommand(orgInfoCmd)
3339

3440
return infoCommand
@@ -63,15 +69,33 @@ func getOrgInformation(cmd *cobra.Command, client info.InfoClient) error {
6369
return err
6470
}
6571

66-
table := tablewriter.NewWriter(cmd.OutOrStdout())
72+
jsonVal, err := cmd.Flags().GetBool("json")
73+
if err != nil {
74+
return err
75+
}
6776

68-
table.SetHeader([]string{"ID", "Name"})
77+
if jsonVal {
78+
// return JSON formatted for output
79+
jsonResp, err := json.Marshal(resp)
80+
if err != nil {
81+
return err
82+
}
83+
jsonWriter := cmd.OutOrStdout()
84+
if _, err := jsonWriter.Write(jsonResp); err != nil {
85+
return err
86+
}
87+
} else {
88+
table := tablewriter.NewWriter(cmd.OutOrStdout())
6989

70-
for _, info := range *resp {
71-
table.Append([]string{
72-
info.ID, info.Name,
73-
})
90+
table.SetHeader([]string{"ID", "Name"})
91+
92+
for _, info := range *resp {
93+
table.Append([]string{
94+
info.ID, info.Name,
95+
})
96+
}
97+
table.Render()
7498
}
75-
table.Render()
99+
76100
return nil
77101
}

cmd/info/info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestTelemetry(t *testing.T) {
152152
assert.DeepEqual(t, telemetryClient.events, []telemetry.Event{
153153
telemetry.CreateInfoEvent(telemetry.CommandInfo{
154154
Name: "org",
155-
LocalArgs: map[string]string{"help": "false"},
155+
LocalArgs: map[string]string{"help": "false", "json": "false"},
156156
}, nil),
157157
})
158158
}

cmd/project/environment_variable.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package project
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"strings"
67

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

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

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

45+
listVarsCommand.PersistentFlags().BoolVar(&jsonFormat, "json", false,
46+
"Return output back in JSON format")
47+
createVarCommand.PersistentFlags().BoolVar(&jsonFormat, "json", false,
48+
"Return output back in JSON format")
49+
4250
cmd.AddCommand(listVarsCommand)
4351
cmd.AddCommand(createVarCommand)
4452
return cmd
@@ -50,14 +58,31 @@ func listProjectEnvironmentVariables(cmd *cobra.Command, client projectapi.Proje
5058
return err
5159
}
5260

53-
table := tablewriter.NewWriter(cmd.OutOrStdout())
61+
jsonVal, err := cmd.Flags().GetBool("json")
62+
if err != nil {
63+
return err
64+
}
65+
66+
if jsonVal {
67+
// return JSON formatted for output
68+
jsonEnvVars, err := json.Marshal(envVars)
69+
if err != nil {
70+
return err
71+
}
72+
jsonWriter := cmd.OutOrStdout()
73+
if _, err := jsonWriter.Write(jsonEnvVars); err != nil {
74+
return err
75+
}
76+
} else {
77+
table := tablewriter.NewWriter(cmd.OutOrStdout())
5478

55-
table.SetHeader([]string{"Environment Variable", "Value"})
79+
table.SetHeader([]string{"Environment Variable", "Value"})
5680

57-
for _, envVar := range envVars {
58-
table.Append([]string{envVar.Name, envVar.Value})
81+
for _, envVar := range envVars {
82+
table.Append([]string{envVar.Name, envVar.Value})
83+
}
84+
table.Render()
5985
}
60-
table.Render()
6186

6287
return nil
6388
}
@@ -95,11 +120,28 @@ func createProjectEnvironmentVariable(cmd *cobra.Command, client projectapi.Proj
95120
return err
96121
}
97122

98-
table := tablewriter.NewWriter(cmd.OutOrStdout())
123+
jsonVal, err := cmd.Flags().GetBool("json")
124+
if err != nil {
125+
return err
126+
}
99127

100-
table.SetHeader([]string{"Environment Variable", "Value"})
101-
table.Append([]string{v.Name, v.Value})
102-
table.Render()
128+
if jsonVal {
129+
// return JSON formatted for output
130+
jsonV, err := json.Marshal(v)
131+
if err != nil {
132+
return err
133+
}
134+
jsonWriter := cmd.OutOrStdout()
135+
if _, err := jsonWriter.Write(jsonV); err != nil {
136+
return err
137+
}
138+
} else {
139+
table := tablewriter.NewWriter(cmd.OutOrStdout())
140+
141+
table.SetHeader([]string{"Environment Variable", "Value"})
142+
table.Append([]string{v.Name, v.Value})
143+
table.Render()
144+
}
103145

104146
return nil
105147
}

0 commit comments

Comments
 (0)