Skip to content

Commit

Permalink
Add timeout for ruby bundle lock
Browse files Browse the repository at this point in the history
  • Loading branch information
sfowl committed Nov 8, 2023
1 parent 6109f6c commit b3e63e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- run: bundle config --local path $PWD/vendor/bundle

- name: Set up Node
Expand Down
4 changes: 4 additions & 0 deletions deplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ func BuildWant() []Dependency {
"internal/bytealg",
"internal/cpu",
"internal/fmtsort",
"internal/goarch",
"internal/goexperiment",
"internal/goos",
"internal/itoa",
"internal/oserror",
"internal/poll",
"internal/race",
"internal/reflectlite",
"internal/safefilepath",
"internal/syscall/execenv",
"internal/syscall/unix",
"internal/testlog",
Expand All @@ -48,6 +51,7 @@ func BuildWant() []Dependency {
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"runtime/internal/syscall",
"sort",
"strconv",
"sync",
Expand Down
7 changes: 6 additions & 1 deletion internal/scan/ruby.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package scan

import (
"context"
"embed"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

log "github.com/sirupsen/logrus"
)
Expand All @@ -28,7 +30,9 @@ 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("env", fmt.Sprintf("--chdir=%s", baseDir), "bundle", "lock")
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(300)*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "env", fmt.Sprintf("--chdir=%s", baseDir), "bundle", "lock")
data, err := cmd.CombinedOutput()
if err != nil {
log.Errorf("couldn't create %s: %v", lockPath, err)
Expand All @@ -52,6 +56,7 @@ func runGemlockParser(lockPath string) (map[string]string, error) {
log.Errorf("Could not create ruby script %s: %s", scriptName, err)
return gathered, err
}
defer os.Remove(g.Name())
err = os.WriteFile(g.Name(), rubyScript, 0644)
if err != nil {
log.Errorf("Could not write ruby script to %s: %s", g.Name(), err)
Expand Down

0 comments on commit b3e63e1

Please sign in to comment.