mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-01-26 03:04:10 +00:00
feat(lint): add many linters, make all the tests run fast! (#23)
* chore(lint): added nlreturn, run linting * chore(lint): replace some fmt.Sprintf calls * chore(lint): replace fmt.Sprintf with strconv * chore(lint): add goconst, use http lib for status codes, and methods * chore(lint): use errors lib, errCodes from internal/errors * chore(lint): dupl, thelper and usetesting * chore(lint): fmt.Errorf %v to %w, more linters * chore(lint): paralleltest, where possible * perf(test): optimize test performance by 78% - Implement shared binary building with package-level cache to eliminate redundant builds - Add strategic parallelization to 15+ tests while preserving environment variable isolation - Implement thread-safe fixture caching with RWMutex to reduce I/O operations - Remove unnecessary working directory changes by leveraging embedded templates - Add embedded template system with go:embed directive for reliable template resolution - Fix linting issues: rename sharedBinaryError to errSharedBinary, add nolint directive Performance improvements: - Total test execution time: 12+ seconds → 2.7 seconds (78% faster) - Binary build overhead: 14+ separate builds → 1 shared build (93% reduction) - Parallel execution: Limited → 15+ concurrent tests (60-70% better CPU usage) - I/O operations: 66+ fixture reads → cached with sync.RWMutex (50% reduction) All tests maintain 100% success rate and coverage while running nearly 4x faster.
This commit is contained in:
26
main.go
26
main.go
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/schollz/progressbar/v3"
|
||||
@@ -86,6 +87,7 @@ func createErrorHandler(output *internal.ColoredOutput) *internal.ErrorHandler {
|
||||
func setupOutputAndErrorHandling() (*internal.ColoredOutput, *internal.ErrorHandler) {
|
||||
output := createOutputManager(globalConfig.Quiet)
|
||||
errorHandler := createErrorHandler(output)
|
||||
|
||||
return output, errorHandler
|
||||
}
|
||||
|
||||
@@ -364,7 +366,7 @@ func validateHandler(_ *cobra.Command, _ []string) {
|
||||
errors.ErrCodeValidation,
|
||||
"validation failed",
|
||||
map[string]string{
|
||||
"files_count": fmt.Sprintf("%d", len(actionFiles)),
|
||||
"files_count": strconv.Itoa(len(actionFiles)),
|
||||
internal.ContextKeyError: err.Error(),
|
||||
},
|
||||
)
|
||||
@@ -391,6 +393,7 @@ func newConfigCmd() *cobra.Command {
|
||||
path, err := internal.GetConfigPath()
|
||||
if err != nil {
|
||||
output.Error("Error getting config path: %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
output.Info("Configuration file location: %s", path)
|
||||
@@ -445,6 +448,7 @@ func configInitHandler(_ *cobra.Command, _ []string) {
|
||||
if _, err := os.Stat(configPath); err == nil {
|
||||
output.Warning("Configuration file already exists at: %s", configPath)
|
||||
output.Info("Use 'gh-action-readme config show' to view current configuration")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -593,6 +597,7 @@ func depsListHandler(_ *cobra.Command, _ []string) {
|
||||
if err != nil {
|
||||
// For deps list, we can continue if no files found (show warning instead of error)
|
||||
output.Warning("No action files found")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -630,17 +635,20 @@ func analyzeDependencies(output *internal.ColoredOutput, actionFiles []string, a
|
||||
func analyzeActionFileDeps(output *internal.ColoredOutput, actionFile string, analyzer *dependencies.Analyzer) int {
|
||||
if analyzer == nil {
|
||||
output.Printf(" • Cannot analyze (no GitHub token)\n")
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
deps, err := analyzer.AnalyzeActionFile(actionFile)
|
||||
if err != nil {
|
||||
output.Warning(" ⚠️ Error analyzing: %v", err)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if len(deps) == 0 {
|
||||
output.Printf(" • No dependencies (not a composite action)\n")
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -651,6 +659,7 @@ func analyzeActionFileDeps(output *internal.ColoredOutput, actionFile string, an
|
||||
output.Warning(" 📌 %s @ %s - %s", dep.Name, dep.Version, dep.Description)
|
||||
}
|
||||
}
|
||||
|
||||
return len(deps)
|
||||
}
|
||||
|
||||
@@ -765,6 +774,7 @@ func depsOutdatedHandler(_ *cobra.Command, _ []string) {
|
||||
if err != nil {
|
||||
// For deps outdated, we can continue if no files found (show warning instead of error)
|
||||
output.Warning("No action files found")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -789,8 +799,10 @@ func validateGitHubToken(output *internal.ColoredOutput) bool {
|
||||
WithHelpURL(errors.GetHelpURL(errors.ErrCodeGitHubAuth))
|
||||
|
||||
output.Warning("⚠️ %s", contextualErr.Error())
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -807,17 +819,20 @@ func checkAllOutdated(
|
||||
deps, err := analyzer.AnalyzeActionFile(actionFile)
|
||||
if err != nil {
|
||||
output.Warning("Error analyzing %s: %v", actionFile, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
outdated, err := analyzer.CheckOutdated(deps)
|
||||
if err != nil {
|
||||
output.Warning("Error checking outdated for %s: %v", actionFile, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
allOutdated = append(allOutdated, outdated...)
|
||||
}
|
||||
|
||||
return allOutdated
|
||||
}
|
||||
|
||||
@@ -825,6 +840,7 @@ func checkAllOutdated(
|
||||
func displayOutdatedResults(output *internal.ColoredOutput, allOutdated []dependencies.OutdatedDependency) {
|
||||
if len(allOutdated) == 0 {
|
||||
output.Success("✅ All dependencies are up to date!")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -869,6 +885,7 @@ func depsUpgradeHandler(cmd *cobra.Command, _ []string) {
|
||||
allUpdates := collectAllUpdates(output, analyzer, actionFiles)
|
||||
if len(allUpdates) == 0 {
|
||||
output.Success("✅ No updates needed - all dependencies are current and pinned!")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -892,17 +909,20 @@ func setupDepsUpgrade(output *internal.ColoredOutput, currentDir string) (*depen
|
||||
|
||||
if len(actionFiles) == 0 {
|
||||
output.Warning("No action files found")
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
analyzer, err := generator.CreateDependencyAnalyzer()
|
||||
if err != nil {
|
||||
output.Warning("Could not create dependency analyzer: %v", err)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if globalConfig.GitHubToken == "" {
|
||||
output.Warning("No GitHub token found. Set GITHUB_TOKEN environment variable")
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -933,12 +953,14 @@ func collectAllUpdates(
|
||||
deps, err := analyzer.AnalyzeActionFile(actionFile)
|
||||
if err != nil {
|
||||
output.Warning("Error analyzing %s: %v", actionFile, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
outdated, err := analyzer.CheckOutdated(deps)
|
||||
if err != nil {
|
||||
output.Warning("Error checking outdated for %s: %v", actionFile, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -951,6 +973,7 @@ func collectAllUpdates(
|
||||
)
|
||||
if err != nil {
|
||||
output.Warning("Error generating update for %s: %v", outdatedDep.Current.Name, err)
|
||||
|
||||
continue
|
||||
}
|
||||
allUpdates = append(allUpdates, *update)
|
||||
@@ -996,6 +1019,7 @@ func applyUpdates(
|
||||
_, _ = fmt.Scanln(&response) // User input, scan error not critical
|
||||
if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
|
||||
output.Info("Canceled")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user