Skip to content

Commit

Permalink
Merge pull request #47 from grafana/46-fix-go-git-workdir-permissions
Browse files Browse the repository at this point in the history
fix go-git workdir permissions
  • Loading branch information
szkiba authored Aug 30, 2024
2 parents 7d8463b + d9a2d7b commit 66af04c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ func saveCompliance(ctx context.Context, module string, comp *k6lint.Compliance)
return os.WriteFile(filename, data, permFile)
}

func fixWorkdirPerm(dir string) error {
return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}

var mode fs.FileMode

if info.IsDir() {
mode = permDir
} else {
mode = permFile
}

return os.Chmod(path, mode) //nolint:forbidigo
})
}

//nolint:forbidigo
func updateWorkdir(ctx context.Context, dir string, cloneURL string) error {
_, err := os.Stat(dir)
Expand All @@ -74,7 +92,11 @@ func updateWorkdir(ctx context.Context, dir string, cloneURL string) error {

if notfound {
_, err = git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{URL: cloneURL})
return err
if err != nil {
return err
}

return fixWorkdirPerm(dir)
}

repo, err := git.PlainOpen(dir)
Expand All @@ -92,7 +114,7 @@ func updateWorkdir(ctx context.Context, dir string, cloneURL string) error {
return err
}

return nil
return fixWorkdirPerm(dir)
}

func checkCompliance(ctx context.Context, module string, cloneURL string, tstamp float64) (*k6lint.Compliance, error) {
Expand Down
11 changes: 11 additions & 0 deletions releases/v0.1.16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
k6registry `v0.1.16` is here 🎉!

This is an internal maintenance release.

**Fix file/directory permissions**

The `go-git` library used to checkout the source of extensions creates certain files readable only for the user. This makes it impossible to cache files created in GitHub action mode between workflow runs.

After the git operations, the workdir file permissions now will be fixed.

In the case of files, now the permission set to `0o644`, in the case of a direcotry to `0o755`.

0 comments on commit 66af04c

Please sign in to comment.