feat: go 1.25.5, dependency updates, renamed internal/errors (#129)

* feat: rename internal/errors to internal/apperrors

* fix(tests): clear env values before using in tests

* feat: rename internal/errors to internal/apperrors

* chore(deps): update go and all dependencies

* chore: remove renovate from pre-commit, formatting

* chore: sonarcloud fixes

* feat: consolidate constants to appconstants/constants.go

* chore: sonarcloud fixes

* feat: simplification, deduplication, test utils

* chore: sonarcloud fixes

* chore: sonarcloud fixes

* chore: sonarcloud fixes

* chore: sonarcloud fixes

* chore: clean up

* fix: config discovery, const deduplication

* chore: fixes
This commit is contained in:
2026-01-01 23:17:29 +02:00
committed by GitHub
parent 85a439d804
commit 7f80105ff5
65 changed files with 2321 additions and 1710 deletions

View File

@@ -10,6 +10,8 @@ import (
"time"
"github.com/adrg/xdg"
"github.com/ivuorinen/gh-action-readme/appconstants"
)
// Entry represents a cached item with TTL support.
@@ -53,13 +55,15 @@ func NewCache(config *Config) (*Cache, error) {
}
// Get XDG cache directory
cacheDir, err := xdg.CacheFile("gh-action-readme")
cacheDir, err := xdg.CacheFile(appconstants.AppName)
if err != nil {
return nil, fmt.Errorf("failed to get XDG cache directory: %w", err)
}
// Ensure cache directory exists
if err := os.MkdirAll(filepath.Dir(cacheDir), 0750); err != nil { // #nosec G301 -- cache directory permissions
cacheDirParent := filepath.Dir(cacheDir)
// #nosec G301 -- cache directory permissions
if err := os.MkdirAll(cacheDirParent, appconstants.FilePermDir); err != nil {
return nil, fmt.Errorf("failed to create cache directory: %w", err)
}
@@ -145,7 +149,7 @@ func (c *Cache) Clear() error {
c.data = make(map[string]Entry)
// Remove cache file
cacheFile := filepath.Join(c.path, "cache.json")
cacheFile := filepath.Join(c.path, appconstants.CacheJSON)
if err := os.Remove(cacheFile); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove cache file: %w", err)
}
@@ -245,7 +249,7 @@ func (c *Cache) cleanup() {
// loadFromDisk loads cache data from disk.
func (c *Cache) loadFromDisk() error {
cacheFile := filepath.Join(c.path, "cache.json")
cacheFile := filepath.Join(c.path, appconstants.CacheJSON)
data, err := os.ReadFile(cacheFile) // #nosec G304 -- cache file path constructed internally
if err != nil {
@@ -280,8 +284,9 @@ func (c *Cache) saveToDisk() error {
return fmt.Errorf("failed to marshal cache data: %w", err)
}
cacheFile := filepath.Join(c.path, "cache.json")
if err := os.WriteFile(cacheFile, jsonData, 0600); err != nil { // #nosec G306 -- cache file permissions
cacheFile := filepath.Join(c.path, appconstants.CacheJSON)
// #nosec G306 -- cache file permissions
if err := os.WriteFile(cacheFile, jsonData, appconstants.FilePermDefault); err != nil {
return fmt.Errorf("failed to write cache file: %w", err)
}

View File

@@ -74,7 +74,7 @@ func TestCache_SetAndGet(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
tests := []struct {
name string
@@ -126,7 +126,7 @@ func TestCache_TTL(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Set value with short TTL
shortTTL := 100 * time.Millisecond
@@ -155,7 +155,7 @@ func TestCache_GetOrSet(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Use unique key to avoid interference from other tests
testKey := fmt.Sprintf("test-key-%d", time.Now().UnixNano())
@@ -185,7 +185,7 @@ func TestCache_GetOrSetError(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Getter that returns error
getter := func() (any, error) {
@@ -212,7 +212,7 @@ func TestCache_ConcurrentAccess(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
const numGoroutines = 10
const numOperations = 100
@@ -272,7 +272,7 @@ func TestCache_Persistence(t *testing.T) {
// Create new cache instance (should load from disk)
cache2 := createTestCache(t, tmpDir)
defer func() { _ = cache2.Close() }()
defer testutil.CleanupCache(t, cache2)()
// Value should still exist
value, exists := cache2.Get("persistent-key")
@@ -287,7 +287,7 @@ func TestCache_Clear(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Add some data
_ = cache.Set("key1", "value1")
@@ -317,7 +317,7 @@ func TestCache_Delete(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Add some data
_ = cache.Set("key1", "value1")
@@ -354,7 +354,7 @@ func TestCache_Stats(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Ensure cache starts clean
_ = cache.Clear()
@@ -412,7 +412,7 @@ func TestCache_CleanupExpiredEntries(t *testing.T) {
cache, err := NewCache(config)
testutil.AssertNoError(t, err)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// Add entry that will expire
err = cache.Set("expiring-key", "expiring-value")
@@ -465,7 +465,7 @@ func TestCache_ErrorHandling(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cache := tt.setupFunc(t)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
tt.testFunc(t, cache)
})
@@ -477,7 +477,7 @@ func TestCache_AsyncSaveErrorHandling(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
// This tests our new saveToDiskAsync error handling
// Set a value to trigger async save
@@ -502,7 +502,7 @@ func TestCache_EstimateSize(t *testing.T) {
defer cleanup()
cache := createTestCache(t, tmpDir)
defer func() { _ = cache.Close() }()
defer testutil.CleanupCache(t, cache)()
tests := []struct {
name string