Skip to content

Commit ef998b6

Browse files
committed
fix: cache permission fixed in GH action mode
1 parent 66af04c commit ef998b6

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

cmd/cmd.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"encoding/json"
88
"io/fs"
99
"os"
10+
"path/filepath"
1011

12+
"github.com/adrg/xdg"
1113
"github.com/spf13/cobra"
1214
)
1315

@@ -45,6 +47,9 @@ func New() (*cobra.Command, error) {
4547

4648
return run(cmd.Context(), args, opts)
4749
},
50+
PostRunE: func(_ *cobra.Command, _ []string) error {
51+
return ghActionFixPerm(xdg.CacheHome)
52+
},
4853
}
4954

5055
ctx, err := newContext(context.TODO(), root.Root().Name())
@@ -150,6 +155,28 @@ func run(ctx context.Context, args []string, opts *options) (result error) {
150155
return nil
151156
}
152157

158+
func ghActionFixPerm(dir string) error {
159+
if os.Getenv("GITHUB_ACTIONS") != "true" { //nolint:forbidigo
160+
return nil
161+
}
162+
163+
return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
164+
if err != nil {
165+
return err
166+
}
167+
168+
var mode fs.FileMode
169+
170+
if info.IsDir() {
171+
mode = permDir
172+
} else {
173+
mode = permFile
174+
}
175+
176+
return os.Chmod(path, mode) //nolint:forbidigo
177+
})
178+
}
179+
153180
const (
154181
permFile fs.FileMode = 0o644
155182
permDir fs.FileMode = 0o755

cmd/lint.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,6 @@ func saveCompliance(ctx context.Context, module string, comp *k6lint.Compliance)
6363
return os.WriteFile(filename, data, permFile)
6464
}
6565

66-
func fixWorkdirPerm(dir string) error {
67-
return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
68-
if err != nil {
69-
return err
70-
}
71-
72-
var mode fs.FileMode
73-
74-
if info.IsDir() {
75-
mode = permDir
76-
} else {
77-
mode = permFile
78-
}
79-
80-
return os.Chmod(path, mode) //nolint:forbidigo
81-
})
82-
}
83-
8466
//nolint:forbidigo
8567
func updateWorkdir(ctx context.Context, dir string, cloneURL string) error {
8668
_, err := os.Stat(dir)
@@ -92,11 +74,7 @@ func updateWorkdir(ctx context.Context, dir string, cloneURL string) error {
9274

9375
if notfound {
9476
_, err = git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{URL: cloneURL})
95-
if err != nil {
96-
return err
97-
}
98-
99-
return fixWorkdirPerm(dir)
77+
return err
10078
}
10179

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

117-
return fixWorkdirPerm(dir)
95+
return nil
11896
}
11997

12098
func checkCompliance(ctx context.Context, module string, cloneURL string, tstamp float64) (*k6lint.Compliance, error) {

releases/v0.1.17.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
k6registry `v0.1.17` is here 🎉!
2+
3+
This is an internal maintenance release.
4+
5+
**Fix file/directory permissions**
6+
7+
In GitHub Action mode, the permissions of the cache (XDG_CACHE_HOME) files have been corrected.
8+
9+
In the case of files, now the permission set to `0o644`, in the case of a direcotry to `0o755`.

0 commit comments

Comments
 (0)