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

Fix running gemlock-parser.rb in relative path #30

Merged
merged 2 commits into from
Oct 19, 2023
Merged
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
11 changes: 7 additions & 4 deletions internal/scan/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scan

import (
"embed"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand All @@ -27,7 +28,7 @@ func GetRubyDeps(path string) (map[string]string, error) {
if os.IsNotExist(err) {
log.Debugf("Creating %s with `bundle lock`", lockPath)
// Create Gemfile.lock
cmd := exec.Command("bundle", "lock")
cmd := exec.Command("env", fmt.Sprintf("--chdir=%s", baseDir), "bundle", "lock")
data, err := cmd.CombinedOutput()
if err != nil {
log.Errorf("couldn't create %s: %v: %v", lockPath, err, string(data))
Expand Down Expand Up @@ -55,9 +56,11 @@ func runGemlockParser(lockPath string) (map[string]string, error) {
log.Errorf("Could not write ruby script to %s: %s", g.Name(), err)
return gathered, err
}
args := []string{g.Name(), lockPath}
log.Debugf("Running ruby %v", args)
cmd := exec.Command("ruby", args...)
dir := filepath.Dir(lockPath)
name := filepath.Base(lockPath)
args := []string{fmt.Sprintf("--chdir=%s", dir), "ruby", g.Name(), name}
log.Debugf("Running env %v", args)
cmd := exec.Command("env", args...)
data, err := cmd.Output()
if err != nil {
log.Errorf("Error running Gemfile.lock parser: %v: %s", err, string(data))
Expand Down
Loading