Skip to content

Commit

Permalink
Merge branch 'v15.beta.1' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRooney committed Mar 21, 2024
2 parents 2259275 + 6f2f38a commit f1a80ff
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 109 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
Expand All @@ -19,7 +18,6 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2.1.0
with:
Expand Down
Empty file.
2 changes: 0 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ on:
- reopened
- synchronize
- ready_for_review
env:
GOPRIVATE: "github.com/speakeasy-api"
jobs:
build:
name: Build
Expand Down
32 changes: 19 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,57 @@ module github.com/speakeasy-api/sdk-generation-action
go 1.21.0

require (
github.com/go-git/go-git/v5 v5.4.2
github.com/go-git/go-git/v5 v5.11.0
github.com/google/go-github/v54 v54.0.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.6.0
github.com/pb33f/libopenapi v0.14.0
github.com/speakeasy-api/git-diff-parser v0.0.3
github.com/speakeasy-api/sdk-gen-config v1.7.4
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.4.1
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/oauth2 v0.11.0
gopkg.in/yaml.v3 v3.0.1
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/AlekSi/pointer v1.2.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ericlagergren/decimal v0.0.0-20240305081647-93d586550569 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
157 changes: 81 additions & 76 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions internal/actions/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type logProxyEntry struct {
Tags map[string]interface{} `json:"tags"`
}

func LogActionResult() {
func LogActionResult() error {
key := os.Getenv("SPEAKEASY_API_KEY")
if key == "" {
fmt.Print("no SPEAKEASY_API_KEY provided.")
return
return nil
}

logLevel := logProxyLevelInfo
Expand Down Expand Up @@ -90,7 +90,7 @@ func LogActionResult() {
body, err := json.Marshal(&request)
if err != nil {
fmt.Print("failure sending log to speakeasy.")
return
return nil
}

baseURL := os.Getenv("SPEAKEASY_SERVER_URL")
Expand All @@ -101,7 +101,7 @@ func LogActionResult() {
req, err := http.NewRequest("POST", baseURL+"/v1/log/proxy", bytes.NewBuffer(body))
if err != nil {
fmt.Print("failure sending log to speakeasy.")
return
return nil
}

req.Header.Set("Content-Type", "application/json")
Expand All @@ -113,7 +113,7 @@ func LogActionResult() {
resp, err := client.Do(req)
if err != nil {
fmt.Print("failure sending log to speakeasy.")
return
return nil
}

defer resp.Body.Close()
Expand All @@ -122,5 +122,5 @@ func LogActionResult() {
fmt.Printf("failure sending log to speakeasy with status %s.", resp.Status)
}

return
return nil
}
2 changes: 1 addition & 1 deletion internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func RunWorkflow() error {
}()

genInfo, outputs, err := run.Run(g)
outputs["resolved_speakeasy_version"] = resolvedVersion
if err != nil {
if err := setOutputs(outputs); err != nil {
logging.Debug("failed to set outputs: %v", err)
}
return err
}
outputs["resolved_speakeasy_version"] = resolvedVersion

anythingRegenerated := false

Expand Down
50 changes: 49 additions & 1 deletion internal/cli/speakeasy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"archive/tar"
"archive/zip"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path"
Expand All @@ -21,7 +23,7 @@ type Git interface {
GetDownloadLink(version string) (string, string, error)
}

func Download(pinnedVersion string, g Git) (string, error) {
func GetVersion(pinnedVersion string) string {
if pinnedVersion == "" {
pinnedVersion = "latest"
}
Expand All @@ -34,11 +36,21 @@ func Download(pinnedVersion string, g Git) (string, error) {
}
}

return version
}

func Download(pinnedVersion string, g Git) (string, error) {
version := GetVersion(pinnedVersion)

link, version, err := g.GetDownloadLink(version)
if err != nil {
return version, err
}

if _, err := os.Stat(filepath.Join(environment.GetBaseDir(), "bin", "speakeasy")); err == nil {
return version, nil
}

fmt.Println("Downloading speakeasy cli version: ", version)

downloadPath := filepath.Join(os.TempDir(), "speakeasy"+path.Ext(link))
Expand Down Expand Up @@ -183,3 +195,39 @@ func extractTarGZ(archive, dest string) error {

return nil
}

func CheckFreeUsageAccess() (bool, error) {
apiURL := "https://api.speakeasyapi.dev/v1/workspace/access?passive=true"

req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return false, fmt.Errorf("error creating the request: %w", err)
}

apiKey := os.Getenv("SPEAKEASY_API_KEY")
req.Header.Set("x-api-key", apiKey)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return false, fmt.Errorf("error making the API request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("API request failed with status code: %d", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return false, fmt.Errorf("error reading the response body: %w", err)
}
var accessDetails struct {
GenerationAllowed bool `json:"generation_allowed"`
}
if err := json.Unmarshal(body, &accessDetails); err != nil {
return false, fmt.Errorf("error unmarshaling the response: %w", err)
}

return accessDetails.GenerationAllowed, nil
}
1 change: 0 additions & 1 deletion internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func GetPinnedSpeakeasyVersion() string {
func GetMaxSuggestions() string {
return os.Getenv("INPUT_MAX_SUGGESTIONS")
}

func GetMaxValidationWarnings() (int, error) {
maxVal := os.Getenv("INPUT_MAX_VALIDATION_WARNINGS")
if maxVal == "" {
Expand Down
16 changes: 16 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -65,6 +66,13 @@ func (g *Git) CloneRepo() error {

workspace := environment.GetWorkspace()

// Remove the repo if it exists
// Flow is useful when testing locally, but we're usually in a fresh image so unnecessary most of the time
repoDir := path.Join(workspace, "repo")
if err := os.RemoveAll(repoDir); err != nil {
return err
}

r, err := git.PlainClone(path.Join(workspace, "repo"), false, &git.CloneOptions{
URL: repoPath,
Progress: os.Stdout,
Expand Down Expand Up @@ -415,6 +423,14 @@ Based on:
- OpenAPI Doc %s %s
- Speakeasy CLI %s (%s) https://github.com/speakeasy-api/speakeasy%s`, releaseInfo.DocVersion, releaseInfo.DocLocation, releaseInfo.SpeakeasyVersion, releaseInfo.GenerationVersion, changelog)

// TODO: To be removed after we start blocking on usage limits.
if accessAllowed, err := cli.CheckFreeUsageAccess(); err == nil && !accessAllowed {
warningDate := time.Date(2024, time.March, 18, 0, 0, 0, 0, time.UTC)
daysToLimit := int(math.Round(warningDate.Sub(time.Now().Truncate(24*time.Hour)).Hours() / 24))
body += "\n\n\n" + fmt.Sprintf(`## 🚀 Time to Upgrade 🚀
You have exceeded the limit of one free generated SDK. Please reach out to the Speakeasy team in the next %d days to ensure continued access`, daysToLimit) + "\n\n"
}

const maxBodyLength = 65536

if len(body) > maxBodyLength {
Expand Down
Loading

0 comments on commit f1a80ff

Please sign in to comment.