Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (r *Runner) Run(ctx context.Context, patterns []string) error {
if r.config.DirName != "" {
r.program, err = sdkbuild.RubyProgramFromDir(
filepath.Join(r.rootDir, r.config.DirName),
r.rootDir,
filepath.Join(r.rootDir, "harness", "ruby"),
)
}
if err == nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/run_ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro
// Get version from harness/ruby/Gemfile if not present.
// If no version constraint is specified in the Gemfile, version stays empty
// and the package manager will resolve to the latest release.
rubyDir := filepath.Join(p.rootDir, "harness", "ruby")
version := p.config.Version
if version == "" {
b, err := os.ReadFile(filepath.Join(p.rootDir, "harness", "ruby", "Gemfile"))
b, err := os.ReadFile(filepath.Join(rubyDir, "Gemfile"))
if err != nil {
return nil, fmt.Errorf("failed reading harness/ruby/Gemfile: %w", err)
}
Expand All @@ -41,9 +42,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro
}

prog, err := sdkbuild.BuildRubyProgram(ctx, sdkbuild.BuildRubyProgramOptions{
BaseDir: p.rootDir,
DirName: p.config.DirName,
Version: version,
BaseDir: p.rootDir,
SourceDir: rubyDir,
DirName: p.config.DirName,
Version: version,
})
if err != nil {
return nil, fmt.Errorf("failed preparing: %w", err)
Expand Down
23 changes: 13 additions & 10 deletions sdkbuild/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
type BuildRubyProgramOptions struct {
// Directory that will have a temporary directory created underneath.
BaseDir string
// Directory containing the Ruby source (gemspec + runner.rb).
SourceDir string
// If not set, no version constraint is applied and the package manager
// resolves to the latest release. If it contains a slash it is assumed
// to be a path to the Ruby SDK repo. Otherwise it is a specific version
Expand Down Expand Up @@ -42,7 +44,7 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru
return nil, fmt.Errorf("base dir required")
}

sourceDir := filepath.Join(options.BaseDir, "harness", "ruby")
sourceDir := options.SourceDir

// Create temp dir if needed that we will remove if creating is unsuccessful
success := false
Expand Down Expand Up @@ -74,7 +76,9 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru
return cmd.Run()
}

// Build the Gemfile content
// Build the Gemfile content. We use Bundler's `gemspec` directive to
// auto-discover the gemspec in the source directory (via path: option).
// This works for any gem name (harness, omes, etc.).
var gemfileContent string
if strings.ContainsAny(options.Version, `/\`) {
// It's a path to a local SDK repo
Expand All @@ -94,21 +98,20 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"

gem "temporalio", path: %q
gem "harness", path: %q
gemspec path: %q
`, gemPath, sourceDir)
} else if options.Version != "" {
version := strings.TrimPrefix(options.Version, "v")
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"

gem "temporalio", "%s"
gem "harness", path: %q
gemspec path: %q
`, version, sourceDir)
} else {
// No version constraint — Bundler resolves to latest from RubyGems
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"

gem "temporalio"
gem "harness", path: %q
gemspec path: %q
`, sourceDir)
}

Expand Down Expand Up @@ -155,13 +158,13 @@ gem "harness", path: %q
}

// RubyProgramFromDir recreates the Ruby program from a Dir() result of a
// BuildRubyProgram(). Note, the base directory of dir when it was built must
// also be present.
func RubyProgramFromDir(dir string, rootDir string) (*RubyProgram, error) {
// BuildRubyProgram(). The sourceDir should point to the directory containing
// the gemspec and runner.rb.
func RubyProgramFromDir(dir string, sourceDir string) (*RubyProgram, error) {
if _, err := os.Stat(filepath.Join(dir, "Gemfile")); err != nil {
return nil, fmt.Errorf("failed finding Gemfile in dir: %w", err)
}
return &RubyProgram{dir: dir, source: filepath.Join(rootDir, "harness", "ruby")}, nil
return &RubyProgram{dir: dir, source: sourceDir}, nil
}

// Dir is the directory to run in.
Expand Down
Loading