diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 000000000..7aeda5c04 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,6 @@ +--- +- id: config-validate + name: Validate CircleCI config + entry: circleci config validate --skip-update-check + language: golang + files: .circleci/config.yml diff --git a/Dockerfile b/Dockerfile index b5194eb1f..7cdf842f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM cimg/go:1.20 +LABEL maintainer="Developer Experience Team " + ENV CIRCLECI_CLI_SKIP_UPDATE_CHECK true COPY ./dist/circleci-cli_linux_amd64/circleci /usr/local/bin diff --git a/README.md b/README.md index ec03bea08..18beace6c 100644 --- a/README.md +++ b/README.md @@ -112,10 +112,9 @@ CircleCI host has been set. Setup complete. Your configuration has been saved. ``` +If you are using this tool on `circleci.com`, accept the provided default `CircleCI Host`. -If you are using this tool on `circleci.com`. accept the provided default `CircleCI Host`. - -Server users will have to change the default value to your custom address (i.e. `circleci.my-org.com`). +Server users will have to change the default value to your custom address (e.g., `circleci.my-org.com`). **Note**: Server does not yet support config processing and orbs, you will only be able to use `circleci local execute` (previously `circleci build`) for now. @@ -153,7 +152,7 @@ The following commands are affected: ## Platforms, Deployment and Package Managers -The tool is deployed through a number of channels. The primary release channel is through [GitHub Releases](https://github.com/CircleCI-Public/circleci-cli/releases). Green builds on the `main` branch will publish a new GitHub release. These releases contain binaries for macOS, Linux and Windows. These releases are published from (CircleCI)[https://app.circleci.com/pipelines/github/CircleCI-Public/circleci-cli] using (GoReleaser)[https://goreleaser.com/]. +The tool is deployed through a number of channels. The primary release channel is through [GitHub Releases](https://github.com/CircleCI-Public/circleci-cli/releases). Green builds on the `main` branch will publish a new GitHub release. These releases contain binaries for macOS, Linux and Windows. These releases are published from (CircleCI)[https://app.circleci.com/pipelines/github/CircleCI-Public/circleci-cli] using [GoReleaser](https://goreleaser.com/). ### Homebrew diff --git a/cmd/orb.go b/cmd/orb.go index 326b0a616..1f8ef230c 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -1059,6 +1059,7 @@ type OrbSchema struct { type ExampleUsageSchema struct { Version string `yaml:"version,omitempty"` + Setup bool `yaml:"setup,omitempty"` Orbs interface{} `yaml:"orbs,omitempty"` Jobs interface{} `yaml:"jobs,omitempty"` Workflows interface{} `yaml:"workflows"` diff --git a/cmd/orb_test.go b/cmd/orb_test.go index ded63dbe3..2ab23c889 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -3311,6 +3311,20 @@ Windows Server 2010 - run: name: Say hello command: <> + +examples: + example: + description: | + An example of how to use the orb. + usage: + version: 2.1 + orbs: + orb-name: company/orb-name@1.2.3 + setup: true + workflows: + create-pipeline: + jobs: + orb-name: create-pipeline-x `)) script = clitest.OpenTmpFile(tempSettings.Home, filepath.Join("scripts", "script.sh")) script.Write([]byte(`echo Hello, world!`)) @@ -3330,10 +3344,7 @@ Windows Server 2010 It("Includes a script in the packed Orb file", func() { session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).ShouldNot(HaveOccurred()) - - Eventually(session.Out).Should(gbytes.Say(`commands: - orb: - steps: + Eventually(session.Out).Should(gbytes.Say(`steps: - run: command: echo Hello, world! name: Say hello @@ -3341,6 +3352,18 @@ Windows Server 2010 Eventually(session).Should(gexec.Exit(0)) }) + It("Includes the setup key when an orb example uses a dynamic pipeline", func() { + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Out).Should(gbytes.Say(`orbs: + orb-name: company/orb-name@1.2.3 + setup: true + version: 2.1 + workflows: +`)) + Eventually(session).Should(gexec.Exit(0)) + }) + }) Describe("Orb diff", func() { diff --git a/config/config.go b/config/config.go index d76dcad51..1affc5672 100644 --- a/config/config.go +++ b/config/config.go @@ -126,7 +126,7 @@ func (c *ConfigCompiler) ConfigQuery( return legacyResponse, nil } if originalErr != nil { - return nil, fmt.Errorf("config compilation request returned an error: %w", err) + return nil, fmt.Errorf("config compilation request returned an error: %w", originalErr) } if statusCode != 200 { diff --git a/local/local.go b/local/local.go index 320789c66..32e55320c 100644 --- a/local/local.go +++ b/local/local.go @@ -20,6 +20,7 @@ import ( var picardRepo = "circleci/picard" const DefaultConfigPath = ".circleci/config.yml" +const DefaultDockerSocketPath = "/var/run/docker.sock" func Execute(flags *pflag.FlagSet, cfg *settings.Config, args []string) error { var err error @@ -80,7 +81,8 @@ func Execute(flags *pflag.FlagSet, cfg *settings.Config, args []string) error { } job := args[0] - arguments := generateDockerCommand(processedConfigPath, image, pwd, job, processedArgs...) + dockerSocketPath, _ := flags.GetString("docker-socket-path") + arguments := generateDockerCommand(processedConfigPath, image, pwd, job, dockerSocketPath, processedArgs...) if cfg.Debug { _, err = fmt.Fprintf(os.Stderr, "Starting docker with args: %s", arguments) @@ -114,6 +116,7 @@ func AddFlagsForDocumentation(flags *pflag.FlagSet) { flags.String("branch", "", "Git branch") flags.String("repo-url", "", "Git Url") flags.StringArrayP("env", "e", nil, "Set environment variables, e.g. `-e VAR=VAL`") + flags.String("docker-socket-path", DefaultDockerSocketPath, "Path to the host's docker socket") } // Given the full set of flags that were passed to this command, return the path @@ -131,7 +134,7 @@ func buildAgentArguments(flags *pflag.FlagSet) ([]string, string) { // build a list of all supplied flags, that we will pass on to build-agent flags.Visit(func(flag *pflag.Flag) { - if flag.Name != "build-agent-version" && flag.Name != "org-slug" && flag.Name != "config" && flag.Name != "debug" && flag.Name != "org-id" { + if flag.Name != "build-agent-version" && flag.Name != "org-slug" && flag.Name != "config" && flag.Name != "debug" && flag.Name != "org-id" && flag.Name != "docker-socket-path" { result = append(result, unparseFlag(flags, flag)...) } }) @@ -272,10 +275,10 @@ func writeStringToTempFile(data string) (string, error) { return f.Name(), nil } -func generateDockerCommand(configPath, image, pwd string, job string, arguments ...string) []string { +func generateDockerCommand(configPath, image, pwd string, job string, dockerSocketPath string, arguments ...string) []string { const configPathInsideContainer = "/tmp/local_build_config.yml" core := []string{"docker", "run", "--interactive", "--tty", "--rm", - "--volume", "/var/run/docker.sock:/var/run/docker.sock", + "--volume", fmt.Sprintf("%s:/var/run/docker.sock", dockerSocketPath), "--volume", fmt.Sprintf("%s:%s", configPath, configPathInsideContainer), "--volume", fmt.Sprintf("%s:%s", pwd, pwd), "--volume", fmt.Sprintf("%s:/root/.circleci", settings.SettingsPath()), diff --git a/local/local_test.go b/local/local_test.go index 598806ca9..5a290f722 100644 --- a/local/local_test.go +++ b/local/local_test.go @@ -17,7 +17,7 @@ var _ = Describe("build", func() { It("can generate a command line", func() { home, err := os.UserHomeDir() Expect(err).NotTo(HaveOccurred()) - Expect(generateDockerCommand("/config/path", "docker-image-name", "/current/directory", "build", "extra-1", "extra-2")).To(ConsistOf( + Expect(generateDockerCommand("/config/path", "docker-image-name", "/current/directory", "build", "/var/run/docker.sock", "extra-1", "extra-2")).To(ConsistOf( "docker", "run", "--interactive",