Skip to content

Commit

Permalink
improve goroutine management
Browse files Browse the repository at this point in the history
  • Loading branch information
quinna-h committed Feb 1, 2025
1 parent acbdf92 commit 559a01d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/apps/new_latest_major_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand All @@ -17,6 +18,7 @@ import (
"sort"
"strings"
"sync"
"time"

"os/exec"

Expand Down Expand Up @@ -101,16 +103,15 @@ func getGoModVersion(repository string, pkg string) (string, string, error) {
}

func fetchGoModGit(repoURL, tag string, results chan<- PackageResult) {
// Ensure WG counter is decreased
log.Printf("Fetching go.mod for repo: %s, tag: %s", repoURL, tag)
if !strings.HasSuffix(repoURL, ".git") {
repoURL = repoURL + ".git"
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

fs := memfs.New()
storer := memory.NewStorage()

repo, err := git.Clone(storer, fs, &git.CloneOptions{
repo, err := git.CloneContext(ctx, storer, fs, &git.CloneOptions{
URL: repoURL,
Depth: 1,
SingleBranch: true,
Expand All @@ -119,10 +120,19 @@ func fetchGoModGit(repoURL, tag string, results chan<- PackageResult) {
NoCheckout: true,
})
if err != nil {
results <- PackageResult{Error: fmt.Errorf("failed to clone repo: %w", err)}
select {
case results <- PackageResult{Error: fmt.Errorf("failed to clone repo: %w", err)}:
case <-ctx.Done():
log.Printf("Context cancelled while sending result")
}
return
}

// if err != nil {
// results <- PackageResult{Error: fmt.Errorf("failed to clone repo: %w", err)}
// return
// }

worktree, err := repo.Worktree()
if err != nil {
results <- PackageResult{Error: fmt.Errorf("failed to get worktree: %w", err)}
Expand Down

0 comments on commit 559a01d

Please sign in to comment.