Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #939

Merged
merged 20 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1e54f4d
feat: allow installer to download releases for ARM64
kelvintaywl Nov 15, 2022
2259641
Merge pull request #929 from CircleCI-Public/main
JulesFaucherre May 4, 2023
a061e18
fix: use bold rather than backticks around command output
wyardley May 4, 2023
9fdccf5
Merge pull request #807 from kelvintaywl-cci/update-install.sh
JulesFaucherre May 10, 2023
15acfb8
Make the install script a little bit safer when being piped
Nov 28, 2019
f3f5e9b
Merge pull request #352 from CircleCI-Public/safer-pipe-install
rlegan May 10, 2023
dee7fee
chore: Updated goreleaser version
JulesFaucherre May 10, 2023
854fc38
fix: Added backward compatibility for orb validation
JulesFaucherre May 9, 2023
824968d
Merge pull request #933 from CircleCI-Public/update-go-releaser
JulesFaucherre May 10, 2023
5da0619
Merge pull request #930 from wyardley/wyardley/update-warning-backticks
JulesFaucherre May 10, 2023
b7d2142
Merge pull request #934 from CircleCI-Public/fix/DEVEX-1019/backward-…
JulesFaucherre May 10, 2023
f6c133c
doc: Added doc about server compatibility
JulesFaucherre May 10, 2023
30eec41
test: Added test for compatibility
JulesFaucherre May 10, 2023
70ca79d
Merge pull request #936 from CircleCI-Public/DEVEX-1019/added-doc
JulesFaucherre May 11, 2023
4d9dbe5
docs: remove preview message. Now GA
KyleTryon May 15, 2023
766a863
feat: make orb visibility a prompt
KyleTryon May 15, 2023
0ef4187
lint: format
KyleTryon May 15, 2023
fbb0d7c
Merge pull request #938 from CircleCI-Public/docs/orb-init-warning
JulesFaucherre May 16, 2023
c02e09b
Merge remote-tracking branch 'origin/main' into merge-main
JulesFaucherre May 16, 2023
ead2360
Merge pull request #940 from CircleCI-Public/merge-main
JulesFaucherre May 16, 2023
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ commands:
parameters:
GORELEASER_URL:
type: string
default: https://github.com/goreleaser/goreleaser/releases/download/v0.127.0/goreleaser_amd64.deb
default: https://github.com/goreleaser/goreleaser/releases/download/v0.184.0/goreleaser_amd64.deb
steps:
- restore_cache:
keys: [v5-goreleaser-]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ Development instructions for the CircleCI CLI can be found in [HACKING.md](HACKI

Please see the [documentation](https://circleci-public.github.io/circleci-cli) or `circleci help` for more.

## Server compatibility

There are some difference of behavior depending on the version you use:
- 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`
- `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**
126 changes: 106 additions & 20 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,28 @@ func OrbQuery(cl *graphql.Client, configPath string, ownerId string) (*ConfigRes
return nil, err
}

query := `
request, err := makeOrbRequest(cl, config, ownerId)
if err != nil {
return nil, err
}

err = cl.Run(request, &response)
if err != nil {
return nil, errors.Wrap(err, "Unable to validate config")
}

if len(response.OrbConfig.ConfigResponse.Errors) > 0 {
return nil, response.OrbConfig.ConfigResponse.Errors
}

return &response.OrbConfig.ConfigResponse, nil
}

func makeOrbRequest(cl *graphql.Client, configContent string, ownerId string) (*graphql.Request, error) {
handlesOwner := orbQueryHandleOwnerId(cl)

if handlesOwner {
query := `
query ValidateOrb ($config: String!, $owner: UUID) {
orbConfig(orbYaml: $config, ownerId: $owner) {
valid,
Expand All @@ -531,26 +552,91 @@ func OrbQuery(cl *graphql.Client, configPath string, ownerId string) (*ConfigRes
}
}`

request := graphql.NewRequest(query)
request.Var("config", config)
request := graphql.NewRequest(query)
request.Var("config", configContent)

if ownerId != "" {
request.Var("owner", ownerId)
}

request.SetToken(cl.Token)
return request, nil
}

if ownerId != "" {
request.Var("owner", ownerId)
return nil, errors.Errorf("Your version of Server does not support validating orbs that refer to other private orbs. Please see the README for more information on server compatibility: https://github.com/CircleCI-Public/circleci-cli#server-compatibility")
}
query := `
query ValidateOrb ($config: String!) {
orbConfig(orbYaml: $config) {
valid,
errors { message },
sourceYaml,
outputYaml
}
}`

request := graphql.NewRequest(query)
request.Var("config", configContent)

request.SetToken(cl.Token)
return request, nil
}

err = cl.Run(request, &response)
type OrbIntrospectionResponse struct {
Schema struct {
Query struct {
Fields []struct {
Name string `json:"name"`
Args []struct {
Name string `json:"name"`
} `json:"args"`
} `json:"fields"`
} `json:"queryType"`
} `json:"__schema"`
}

func orbQueryHandleOwnerId(cl *graphql.Client) bool {
query := `
query ValidateOrb {
__schema {
queryType {
fields(includeDeprecated: true) {
name
args {
name
__typename
type {
name
}
}
}
}
}
}`
request := graphql.NewRequest(query)
response := OrbIntrospectionResponse{}
err := cl.Run(request, &response)
if err != nil {
return nil, errors.Wrap(err, "Unable to validate config")
return false
}

if len(response.OrbConfig.ConfigResponse.Errors) > 0 {
return nil, response.OrbConfig.ConfigResponse.Errors
request.SetToken(cl.Token)

// Find the orbConfig query method, look at its arguments, if it has the "ownerId" argument, return true
for _, field := range response.Schema.Query.Fields {
if field.Name == "orbConfig" {
for _, arg := range field.Args {
if arg.Name == "ownerId" {
return true
}
}
}
}

return &response.OrbConfig.ConfigResponse, nil
// else return false, ownerId is not supported

return false
}

// OrbImportVersion publishes a new version of an orb using the provided source and id.
Expand Down Expand Up @@ -1239,18 +1325,18 @@ func OrbSetOrbListStatus(cl *graphql.Client, namespace string, orb string, list
var response OrbSetOrbListStatusResponse

query := `
mutation($orbId: UUID!, $list: Boolean!) {
setOrbListStatus(
orbId: $orbId,
list: $list
) {
listed
errors {
message
type
}
}
mutation($orbId: UUID!, $list: Boolean!) {
setOrbListStatus(
orbId: $orbId,
list: $list
) {
listed
errors {
message
type
}
}
}
`

request := graphql.NewRequest(query)
Expand Down
11 changes: 11 additions & 0 deletions clitest/data/orb_with_private.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2.1

orbs:
vuln-scanner: cci-internal/[email protected]

jobs:
some-job:
executor: vuln-scanner/default
steps:
- run:
command: echo "Hello world"
4 changes: 3 additions & 1 deletion cmd/disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/CircleCI-Public/circleci-cli/version"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +40,8 @@ func newDisabledCommand(config *settings.Config, command string) *cobra.Command
}

func disableCommand(opts disableOptions) {
fmt.Printf("`%s` is not available because this tool was installed using `%s`.\n", opts.command, version.PackageManager())
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s is not available because this tool was installed using %s.\n", bold(opts.command), bold(version.PackageManager()))

if opts.command == "update" {
fmt.Println("Please consult the package manager's documentation on how to update the CLI.")
Expand Down
17 changes: 16 additions & 1 deletion cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,22 @@ func inlineIncludes(node *yaml.Node, orbRoot string) error {
func initOrb(opts orbOptions) error {
orbPath := opts.args[0]
var err error
fmt.Println("Note: This command is in preview. Please report any bugs! https://github.com/CircleCI-Public/circleci-cli/issues/new/choose")

if !opts.private {
prompt := &survey.Select{
Message: "Would you like to create a public or private orb?",
Options: []string{"Public", "Private"},
}
var selectedOption string
err := survey.AskOne(prompt, &selectedOption)
if err != nil {
return errors.Wrap(err, "Unexpected error")
}

if selectedOption == "Private" {
opts.private = true
}
}

orbInformThatOrbCannotBeDeletedMessage()

Expand Down
Loading