Skip to content

Commit 663eda4

Browse files
author
JulesFaucherre
authored
Merge pull request #999 from CircleCI-Public/develop
Release
2 parents b8e132d + 4be7e3a commit 663eda4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2351
-94
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ jobs:
137137
working_directory: integration_tests
138138
environment:
139139
TESTING: "true"
140+
- run:
141+
name: "Make sure simple command do not cause any timeout"
142+
command: circleci version
143+
140144
test:
141145
executor: go
142146
steps:
@@ -378,12 +382,14 @@ workflows:
378382
- devex-release
379383
- deploy:
380384
requires:
385+
- cucumber
381386
- test
382387
- test_mac
383388
- coverage
384389
- lint
385390
- deploy-test
386391
- shellcheck/check
392+
- vulnerability-scan
387393
filters:
388394
branches:
389395
only: main

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GOOS=$(shell go env GOOS)
44
GOARCH=$(shell go env GOARCH)
55

66
build: always
7-
go build -o build/$(GOOS)/$(GOARCH)/circleci
7+
go build -o build/$(GOOS)/$(GOARCH)/circleci -ldflags='-X github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=https://api.segment.io'
88

99
build-all: build/linux/amd64/circleci build/darwin/amd64/circleci
1010

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ Please see the [documentation](https://circleci-public.github.io/circleci-cli) o
180180

181181
## Server compatibility
182182

183-
There are some difference of behavior depending on the version you use:
184-
- config validation will use the GraphQL API until **Server v4.0.5, v4.1.3, v4.2.0**. The above versions will use the new route `compile-config-with-defaults`
185-
- `circleci orb validate` will only allow you to validate orbs using other private orbs with the option `--org-slug` from version **Server v4.2.0**
183+
| Functionality | Impacted commands | Change description | Compatibility with Server |
184+
| --- | --- | --- | --- |
185+
| Config compilation and validation | <ul><li>`circleci config validate`</li><li>`circleci config process`</li><li>`circleci local execute`</li> | The config validation has been moved from the GraphQL API to a specific API endpoint | <ul><li>**Server v4.0.5, v4.1.3, v4.2.0 and above**: Commands use the new specific endpoint</li><li>**Previous version**: Commands use the GraphQL API</li></ul> |
186+
| Orb compilation and validation of orb using private orbs | <ul><li>`circleci orb process`</li><li>`circleci orb validate`</li></ul> | To support the validation of orbs requesting private orbs (see [issue](https://github.com/CircleCI-Public/circleci-cli/issues/751)). A field `ownerId` has been added to the GraphQL orb validation endpoint. Thus allowing the `Impacted commands` to use the `--org-id` parameter to enable the orb compilation / validation | <ul><li>**Server v4.2.0 and above**: The field is accessible so you can use the parameter</li><li>**Previous versions**: The field does not exist making the functionality unavailable</li></ul> |
187+
188+
## Telemetry
189+
190+
The CircleCI CLI includes a telemetry feature that collects basic errors and feature usage data in order to help us improve the experience for everyone.
191+
192+
Telemetry works on an opt-in basis: when running a command for the first time, you will be asked for consent to enable telemetry. For non-TTY STDIN, telemetry is disabled by default, ensuring that scripts that use the CLI run smoothly.
193+
194+
You can disable or enable telemetry anytime in one of the following ways:
195+
196+
* Run the commands `circleci telemetry enable` or `circleci telemetry disable`
197+
198+
* Set the `CIRCLECI_CLI_TELEMETRY_OPTOUT` environment variable to `1` or `true` to disable it
199+

Taskfile.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ tasks:
4747
build:
4848
desc: Build main
4949
cmds:
50-
- go build -v -o build/darwin/amd64/circleci .
51-
50+
# LDFlags sets the segment endpoint to an empty string thus letting the analytics library set the default endpoint on its own
51+
# Not setting the `SegmentEndpoint` variable would let the value in the code ie "http://localhost"
52+
- go build -v -o build/$(go env GOOS)/$(go env GOARCH)/circleci -ldflags='-X github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=https://api.segment.io' .
53+
5254
build-linux:
5355
desc: Build main
5456
cmds:
5557
- go build -v -o build/linux/amd64/circleci .
56-
58+
5759
cover:
5860
desc: tests and generates a cover profile
5961
cmds:
60-
- TESTING=true go test -race -coverprofile=coverage.txt ./...
62+
- TESTING=true go test -race -coverprofile=coverage.txt ./...

api/api.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"io"
77
"log"
88
"net/http"
9+
"net/url"
910
"os"
1011
"sort"
1112
"strings"
1213

1314
"github.com/CircleCI-Public/circleci-cli/api/graphql"
15+
"github.com/CircleCI-Public/circleci-cli/api/rest"
1416
"github.com/CircleCI-Public/circleci-cli/references"
1517
"github.com/CircleCI-Public/circleci-cli/settings"
1618
"github.com/Masterminds/semver"
@@ -1818,3 +1820,20 @@ func FollowProject(config settings.Config, vcs string, owner string, projectName
18181820

18191821
return fr, nil
18201822
}
1823+
1824+
type Me struct {
1825+
ID string `json:"id"`
1826+
Login string `json:"login"`
1827+
Name string `json:"name"`
1828+
}
1829+
1830+
func GetMe(client *rest.Client) (Me, error) {
1831+
req, err := client.NewRequest("GET", &url.URL{Path: "me"}, nil)
1832+
if err != nil {
1833+
return Me{}, errors.Wrap(err, "Unable to get user info")
1834+
}
1835+
1836+
var me Me
1837+
_, err = client.DoRequest(req, &me)
1838+
return me, err
1839+
}

api/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
// An EnvironmentVariable has a Variable, a ContextID (its owner), and a
88
// CreatedAt date.
99
type EnvironmentVariable struct {
10-
Variable string
11-
ContextID string
12-
CreatedAt time.Time
10+
Variable string `json:"variable"`
11+
ContextID string `json:"context_id"`
12+
CreatedAt time.Time `json:"created_at"`
13+
UpdatedAt time.Time `json:"updated_at"`
1314
}
1415

1516
// A Context is the owner of EnvironmentVariables.

clitest/clitest.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111
"runtime"
1212

1313
"github.com/CircleCI-Public/circleci-cli/api/graphql"
14+
"github.com/CircleCI-Public/circleci-cli/settings"
1415
"github.com/onsi/gomega/gexec"
1516
"github.com/onsi/gomega/ghttp"
1617
"github.com/onsi/gomega/types"
18+
"gopkg.in/yaml.v3"
1719

1820
"github.com/onsi/gomega"
1921
)
@@ -30,10 +32,12 @@ func ShouldFail() types.GomegaMatcher {
3032

3133
// TempSettings contains useful settings for testing the CLI
3234
type TempSettings struct {
33-
Home string
34-
TestServer *ghttp.Server
35-
Config *TmpFile
36-
Update *TmpFile
35+
Home string
36+
TestServer *ghttp.Server
37+
Config *TmpFile
38+
Update *TmpFile
39+
Telemetry *TmpFile
40+
TelemetryDestPath string
3741
}
3842

3943
// Close should be called in an AfterEach and cleans up the temp directory and server process
@@ -68,6 +72,16 @@ func WithTempSettings() *TempSettings {
6872
gomega.Expect(os.Mkdir(settingsPath, 0700)).To(gomega.Succeed())
6973

7074
tempSettings.Config = OpenTmpFile(settingsPath, "cli.yml")
75+
tempSettings.Telemetry = OpenTmpFile(settingsPath, "telemetry.yml")
76+
content, err := yaml.Marshal(settings.TelemetrySettings{
77+
IsEnabled: false,
78+
HasAnsweredPrompt: true,
79+
})
80+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
81+
_, err = tempSettings.Telemetry.File.Write(content)
82+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
83+
tempSettings.TelemetryDestPath = filepath.Join(tempSettings.Home, "telemetry-content")
84+
7185
tempSettings.Update = OpenTmpFile(settingsPath, "update_check.yml")
7286

7387
tempSettings.TestServer = ghttp.NewServer()

clitest/telemetry.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package clitest
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
7+
"github.com/CircleCI-Public/circleci-cli/telemetry"
8+
"github.com/onsi/gomega"
9+
)
10+
11+
func CompareTelemetryEvent(settings *TempSettings, expected []telemetry.Event) {
12+
content, err := os.ReadFile(settings.TelemetryDestPath)
13+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
14+
15+
result := []telemetry.Event{}
16+
err = json.Unmarshal(content, &result)
17+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
18+
gomega.Expect(result).To(gomega.Equal(expected))
19+
}

cmd/build.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"github.com/CircleCI-Public/circleci-cli/local"
55
"github.com/CircleCI-Public/circleci-cli/settings"
6+
"github.com/CircleCI-Public/circleci-cli/telemetry"
67
"github.com/spf13/cobra"
78
)
89

@@ -16,7 +17,14 @@ func newLocalExecuteCommand(config *settings.Config) *cobra.Command {
1617
return nil
1718
},
1819
RunE: func(cmd *cobra.Command, _ []string) error {
19-
return local.Execute(cmd.Flags(), config, args)
20+
err := local.Execute(cmd.Flags(), config, args)
21+
22+
telemetryClient, ok := telemetry.FromContext(cmd.Context())
23+
if ok {
24+
_ = telemetryClient.Track(telemetry.CreateLocalExecuteEvent(telemetry.GetCommandInformation(cmd, true)))
25+
}
26+
27+
return err
2028
},
2129
Args: cobra.MinimumNArgs(1),
2230
}

cmd/cmd_suite_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"os/exec"
77
"testing"
8+
"time"
89

910
. "github.com/onsi/ginkgo"
1011
. "github.com/onsi/gomega"
@@ -14,6 +15,8 @@ import (
1415
var pathCLI string
1516

1617
var _ = BeforeSuite(func() {
18+
SetDefaultEventuallyTimeout(time.Second * 30)
19+
1720
var err error
1821
pathCLI, err = gexec.Build("github.com/CircleCI-Public/circleci-cli")
1922
Ω(err).ShouldNot(HaveOccurred())

0 commit comments

Comments
 (0)