Skip to content

Commit

Permalink
feat: support pinning versions with new auto-upgrade functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-crumbaugh committed Apr 12, 2024
1 parent d8fc52b commit fb8452a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"fmt"

"github.com/hashicorp/go-version"
"github.com/speakeasy-api/sdk-generation-action/internal/configuration"
"github.com/speakeasy-api/sdk-generation-action/internal/git"
"github.com/speakeasy-api/sdk-generation-action/internal/run"
Expand All @@ -20,14 +19,19 @@ func RunWorkflow() error {
return err
}

resolvedVersion, err := cli.Download(environment.GetPinnedSpeakeasyVersion(), g)
// The top-level CLI can always use latest. The CLI itself manages pinned versions.
resolvedVersion, err := cli.Download("latest", g)
if err != nil {
return err
}

minimumVersionForRun := version.Must(version.NewVersion("1.161.0"))
if !cli.IsAtLeastVersion(minimumVersionForRun) {
return fmt.Errorf("action requires at least version %s of the speakeasy CLI", minimumVersionForRun)
pinnedVersion := cli.GetVersion(environment.GetPinnedSpeakeasyVersion())
if pinnedVersion != "latest" {
resolvedVersion = pinnedVersion
// This environment variable is read by the CLI to determine which version should be used to execute `run`
if err := environment.SetCLIVersionToUse(pinnedVersion); err != nil {
return fmt.Errorf("failed to set pinned speakeasy version: %w", err)
}
}

mode := environment.GetMode()
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/speakeasy.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func runSpeakeasyCommand(args ...string) (string, error) {
cmd.Dir = filepath.Join(environment.GetWorkspace(), "repo", environment.GetWorkingDirectory())
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "SPEAKEASY_RUN_LOCATION=action")

// TODO: remove
fmt.Println("Running speakeasy command with env: ", strings.Join(cmd.Env, " "))

output, err := cmd.CombinedOutput()
if err != nil {
return string(output), fmt.Errorf("error running speakeasy command: speakeasy %s - %w\n %s", strings.Join(args, " "), err, string(output))
Expand Down
4 changes: 4 additions & 0 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@ func GetWorkspace() string {
func ShouldOutputTests() bool {
return os.Getenv("INPUT_OUTPUT_TESTS") == "true"
}

func SetCLIVersionToUse(version string) error {
return os.Setenv("PINNED_VERSION", version)
}

0 comments on commit fb8452a

Please sign in to comment.