Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.x'
go-version: '1.26.x'
cache: true

- name: Download dependencies
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.24.x']
go-version: ['1.26.x']

steps:
- name: Checkout code
Expand Down Expand Up @@ -44,11 +44,11 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.x'
go-version: '1.26.x'
cache: true

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v9
with:
version: latest
version: 'v2.10.1'
args: --timeout=5m
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
.conjure

# Test binary, built with `go test -c`
*.test
Expand Down
4 changes: 2 additions & 2 deletions cmd/bundle/bundle_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func createTempFile(pattern, content string) (string, error) {
if err != nil {
return "", err
}
defer tmpFile.Close()
defer func() { _ = tmpFile.Close() }()

_, err = tmpFile.WriteString(content)
if err != nil {
Expand All @@ -284,5 +284,5 @@ func createTempFile(pattern, content string) (string, error) {
}

func cleanupTempFile(path string) {
os.Remove(path)
_ = os.Remove(path)
}
1 change: 1 addition & 0 deletions cmd/list/list.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Example: conjure list templates,
conjure list bundles,
conjure list templates -t yaml,
conjure list bundles -t kubernetes`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("=== Templates ===")
listTemplates("", false)
Expand Down
1 change: 1 addition & 0 deletions cmd/list/list_bundles.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Examples:
conjure list bundles
conjure list bundles --versions
conjure list bundles --type kubernetes`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
bundleType, _ := cmd.Flags().GetString("type")
showAllVersions, _ := cmd.Flags().GetBool("versions")
Expand Down
1 change: 1 addition & 0 deletions cmd/list/list_templates.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Examples:
conjure list templates
conjure list templates --versions
conjure list templates --type yaml`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
templateType, _ := cmd.Flags().GetString("type")
showAllVersions, _ := cmd.Flags().GetBool("versions")
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Examples:
fmt.Printf("built: %s\n", dateInfo)
return
}
cmd.Help()
_ = cmd.Help()
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if showVersion {
Expand Down
12 changes: 10 additions & 2 deletions cmd/root_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestResolveConfigPathRelative(t *testing.T) {
if err != nil {
t.Fatalf("failed to get original working directory: %v", err)
}
defer os.Chdir(originalWd)
defer func() { _ = os.Chdir(originalWd) }()

if err := os.Chdir(subDir); err != nil {
t.Fatalf("failed to change to subdirectory: %v", err)
Expand All @@ -123,6 +123,14 @@ func TestResolveConfigPathRelative(t *testing.T) {
expectedPath := filepath.Clean(configFile)
resolvedPath = filepath.Clean(resolvedPath)

// Resolve symlinks on both sides to handle macOS where /var -> /private/var
if evaled, err := filepath.EvalSymlinks(expectedPath); err == nil {
expectedPath = evaled
}
if evaled, err := filepath.EvalSymlinks(resolvedPath); err == nil {
resolvedPath = evaled
}

if resolvedPath != expectedPath {
t.Errorf("expected path %q, got %q", expectedPath, resolvedPath)
}
Expand Down Expand Up @@ -161,7 +169,7 @@ func TestResolveConfigPathHomeDirExpansion(t *testing.T) {
t.Skipf("failed to create test file in home directory: %v", err)
return
}
defer os.Remove(testFile)
defer func() { _ = os.Remove(testFile) }()

resolvedPath, err := resolveConfigPath(tt.inputPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/template/template_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func createTempFile(pattern, content string) (string, error) {
if err != nil {
return "", err
}
defer tmpFile.Close()
defer func() { _ = tmpFile.Close() }()

_, err = tmpFile.WriteString(content)
if err != nil {
Expand All @@ -246,5 +246,5 @@ func createTempFile(pattern, content string) (string, error) {
}

func cleanupTempFile(path string) {
os.Remove(path)
_ = os.Remove(path)
}
4 changes: 1 addition & 3 deletions go.mod
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/wizardopstech/conjure

go 1.24.0

toolchain go1.24.7
go 1.26.0

require (
github.com/charmbracelet/bubbletea v1.3.10
Expand Down
12 changes: 6 additions & 6 deletions internal/indexer/indexer_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestIndexer_ValidateStructure(t *testing.T) {
setupFunc: func(testDir string) string {
templatesDir := filepath.Join(testDir, "templates")
templateDir := filepath.Join(templatesDir, "test-template", "1.0.0")
os.MkdirAll(templateDir, 0755)
_ = os.MkdirAll(templateDir, 0755)
metadata := `{
"schema_version": "v1",
"template_name": "test-template",
Expand All @@ -261,8 +261,8 @@ func TestIndexer_ValidateStructure(t *testing.T) {
"version": "1.0.0",
"variables": []
}`
os.WriteFile(filepath.Join(templateDir, "conjure.json"), []byte(metadata), 0600)
os.WriteFile(filepath.Join(templateDir, "template.tmpl"), []byte("test"), 0600)
_ = os.WriteFile(filepath.Join(templateDir, "conjure.json"), []byte(metadata), 0600)
_ = os.WriteFile(filepath.Join(templateDir, "template.tmpl"), []byte("test"), 0600)
return templatesDir
},
resourceType: "templates",
Expand All @@ -273,8 +273,8 @@ func TestIndexer_ValidateStructure(t *testing.T) {
setupFunc: func(testDir string) string {
templatesDir := filepath.Join(testDir, "templates")
templateDir := filepath.Join(templatesDir, "test-template", "1.0.0")
os.MkdirAll(templateDir, 0755)
os.WriteFile(filepath.Join(templateDir, "template.tmpl"), []byte("test"), 0600)
_ = os.MkdirAll(templateDir, 0755)
_ = os.WriteFile(filepath.Join(templateDir, "template.tmpl"), []byte("test"), 0600)
return templatesDir
},
resourceType: "templates",
Expand All @@ -284,7 +284,7 @@ func TestIndexer_ValidateStructure(t *testing.T) {
name: "no versions",
setupFunc: func(testDir string) string {
templatesDir := filepath.Join(testDir, "templates")
os.MkdirAll(filepath.Join(templatesDir, "test-template"), 0755)
_ = os.MkdirAll(filepath.Join(templatesDir, "test-template"), 0755)
return templatesDir
},
resourceType: "templates",
Expand Down
19 changes: 10 additions & 9 deletions internal/source/remote.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *RemoteSource) fetchIndex(skipCache bool) error {
if err != nil {
return fmt.Errorf("failed to fetch index: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to fetch index: HTTP %d", resp.StatusCode)
Expand Down Expand Up @@ -219,7 +219,7 @@ func (r *RemoteSource) GetTemplate(name, requestedVersion string) (*TemplateCont
if err != nil {
return nil, fmt.Errorf("failed to download file '%s': %w", file.Name, err)
}
defer os.Remove(tempFile)
defer func(f string) { _ = os.Remove(f) }(tempFile)

content, err := os.ReadFile(tempFile)
if err != nil {
Expand Down Expand Up @@ -264,6 +264,7 @@ func (r *RemoteSource) GetBundle(name, requestedVersion string) (*BundleContent,
}

if err := r.fetchIndex(false); err != nil {
return nil, fmt.Errorf("failed to fetch bundle index: %w", err)
}

var bundleEntry *BundleIndexEntry
Expand Down Expand Up @@ -327,7 +328,7 @@ func (r *RemoteSource) GetBundle(name, requestedVersion string) (*BundleContent,
if err != nil {
return nil, fmt.Errorf("failed to download file '%s': %w", file.Name, err)
}
defer os.Remove(tempFile)
defer func(f string) { _ = os.Remove(f) }(tempFile)

content, err := os.ReadFile(tempFile)
if err != nil {
Expand Down Expand Up @@ -415,7 +416,7 @@ func (r *RemoteSource) downloadFile(url string, expectedSize int64, expectedHash
if err != nil {
return "", fmt.Errorf("failed to download: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to download: HTTP %d", resp.StatusCode)
Expand All @@ -428,27 +429,27 @@ func (r *RemoteSource) downloadFile(url string, expectedSize int64, expectedHash
tempPath := tempFile.Name()

written, err := io.Copy(tempFile, resp.Body)
tempFile.Close()
_ = tempFile.Close()

if err != nil {
os.Remove(tempPath)
_ = os.Remove(tempPath)
return "", fmt.Errorf("failed to write file: %w", err)
}

if written != expectedSize {
os.Remove(tempPath)
_ = os.Remove(tempPath)
return "", fmt.Errorf("file size mismatch: expected %d bytes, got %d bytes. This likely means index.json was generated with different line endings (Windows CRLF vs Linux LF) than the files on the remote repository", expectedSize, written)
}

if expectedHash != "" {
if err := r.verifier.VerifySHA256(tempPath, expectedHash); err != nil {
os.Remove(tempPath)
_ = os.Remove(tempPath)
return "", fmt.Errorf("%w. This means the file content on the remote repository doesn't match what was used to generate index.json", err)
}
}

if err := os.Chmod(tempPath, cacheFilePerm); err != nil {
os.Remove(tempPath)
_ = os.Remove(tempPath)
return "", fmt.Errorf("failed to set file permissions: %w", err)
}

Expand Down
14 changes: 7 additions & 7 deletions internal/source/remote_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func createMockServer() *httptest.Server {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(index)
_ = json.NewEncoder(w).Encode(index)
})

mux.HandleFunc("/templates/test-template/1.0.0/conjure.json", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -82,11 +82,11 @@ func createMockServer() *httptest.Server {
"template_type": "yaml",
"variables": []interface{}{},
}
json.NewEncoder(w).Encode(metadata)
_ = json.NewEncoder(w).Encode(metadata)
})

mux.HandleFunc("/templates/test-template/1.0.0/template.tmpl", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("template content"))
_, _ = w.Write([]byte("template content"))
})

mux.HandleFunc("/bundles/test-bundle/1.0.0/conjure.json", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -99,11 +99,11 @@ func createMockServer() *httptest.Server {
"shared_variables": []interface{}{},
"template_variables": map[string]interface{}{},
}
json.NewEncoder(w).Encode(metadata)
_ = json.NewEncoder(w).Encode(metadata)
})

mux.HandleFunc("/bundles/test-bundle/1.0.0/app.yaml.tmpl", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("app template content"))
_, _ = w.Write([]byte("app template content"))
})

return httptest.NewServer(mux)
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestRemoteSource_InvalidIndex(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/index.json" {
w.Write([]byte("invalid json"))
_, _ = w.Write([]byte("invalid json"))
}
}))
defer server.Close()
Expand All @@ -367,7 +367,7 @@ func TestRemoteSource_UnsupportedSchemaVersion(t *testing.T) {
SchemaVersion: "v99",
Templates: []TemplateIndexEntry{},
}
json.NewEncoder(w).Encode(index)
_ = json.NewEncoder(w).Encode(index)
}
}))
defer server.Close()
Expand Down
2 changes: 1 addition & 1 deletion internal/source/verifier.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (v *Verifier) ComputeSHA256(filePath string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to open file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()

hash := sha256.New()
if _, err := io.Copy(hash, file); err != nil {
Expand Down
Loading