Skip to content

Commit

Permalink
chore: Move DefaultGenerationFile from cli (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbx9da4 authored Jun 14, 2024
1 parent ff46971 commit db4f350
Showing 1 changed file with 64 additions and 8 deletions.
72 changes: 64 additions & 8 deletions configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"strings"

"github.com/AlekSi/pointer"
Expand All @@ -15,14 +16,16 @@ const (
GithubWritePermission = "write"

// Constants to be used as keys in the config files
Languages = "languages"
Mode = "mode"
GithubAccessToken = "github_access_token"
SpeakeasyApiKey = "speakeasy_api_key"
SpeakeasyServerURL = "speakeasy_server_url"
OpenAPIDocAuthHeader = "openapi_doc_auth_header"
OpenAPIDocAuthToken = "openapi_doc_auth_token"
OpenAPIDocs = "openapi_docs"
Languages = "languages"
Mode = "mode"
GithubAccessToken = "github_access_token"
SpeakeasyApiKey = "speakeasy_api_key"
SpeakeasyServerURL = "speakeasy_server_url"
OpenAPIDocAuthHeader = "openapi_doc_auth_header"
OpenAPIDocAuthToken = "openapi_doc_auth_token"
OpenAPIDocs = "openapi_docs"
DefaultGithubTokenSecretName = "GITHUB_TOKEN"
DefaultSpeakeasyAPIKeySecretName = "SPEAKEASY_API_KEY"
)

type OptionalPropertyRenderingOption string
Expand Down Expand Up @@ -317,3 +320,56 @@ func (c *Configuration) GetGenerationFieldsMap() (map[string]any, error) {
func ptr(a any) *any {
return &a
}

func DefaultGenerationFile() *GenerateWorkflow {
secrets := make(map[string]string)
secrets[GithubAccessToken] = FormatGithubSecretName(DefaultGithubTokenSecretName)
secrets[SpeakeasyApiKey] = FormatGithubSecretName(DefaultSpeakeasyAPIKeySecretName)
return &GenerateWorkflow{
Name: "Generate",
On: GenerateOn{
WorkflowDispatch: WorkflowDispatch{
Inputs: Inputs{
Force: Force{
Description: "Force generation of SDKs",
Type: "boolean",
Default: false,
},
},
},
Schedule: []Schedule{
{
Cron: "0 0 * * *",
},
},
},
Jobs: Jobs{
Generate: Job{
Uses: "speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15",
With: map[string]any{
"speakeasy_version": "latest",
"force": "${{ github.event.inputs.force }}",
Mode: "pr",
},
Secrets: secrets,
},
},
Permissions: Permissions{
Checks: GithubWritePermission,
Statuses: GithubWritePermission,
Contents: GithubWritePermission,
PullRequests: GithubWritePermission,
},
}
}

func FormatGithubSecretName(name string) string {
return fmt.Sprintf("${{ secrets.%s }}", strings.ToUpper(formatGithubSecret(name)))

Check failure on line 367 in configuration.go

View workflow job for this annotation

GitHub Actions / test

undefined: formatGithubSecret
}

func FormatGithubSecret(secret string) string {
if secret != "" && secret[0] == '$' {
secret = secret[1:]
}
return strings.ToLower(secret)
}

0 comments on commit db4f350

Please sign in to comment.