-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from grafana/prepare-v0.2.0
build and smoke checkers
- Loading branch information
Showing
13 changed files
with
231 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package k6lint | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"runtime" | ||
|
||
"github.com/grafana/k6foundry" | ||
) | ||
|
||
//nolint:forbidigo | ||
func build(ctx context.Context, module string, dir string) (filename string, result error) { | ||
exe, err := os.CreateTemp("", "k6-*.exe") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if err = os.Chmod(exe.Name(), 0o700); err != nil { //nolint:gosec | ||
return "", err | ||
} | ||
|
||
var out bytes.Buffer | ||
|
||
defer func() { | ||
if result != nil { | ||
_, _ = io.Copy(os.Stderr, &out) | ||
fmt.Fprintln(os.Stderr) | ||
} | ||
}() | ||
|
||
builder, err := k6foundry.NewNativeBuilder( | ||
ctx, | ||
k6foundry.NativeBuilderOpts{ | ||
Logger: slog.New(slog.NewTextHandler(&out, &slog.HandlerOptions{Level: slog.LevelError})), | ||
Stdout: &out, | ||
Stderr: &out, | ||
GoOpts: k6foundry.GoOpts{ | ||
CopyGoEnv: true, | ||
Env: map[string]string{"GOWORK": "off"}, | ||
}, | ||
}, | ||
) | ||
if err != nil { | ||
result = err | ||
return "", result | ||
} | ||
|
||
_, result = builder.Build( | ||
ctx, | ||
k6foundry.NewPlatform(runtime.GOOS, runtime.GOARCH), | ||
"latest", | ||
[]k6foundry.Module{{Path: module, ReplacePath: dir}}, | ||
nil, | ||
exe, | ||
) | ||
|
||
if result != nil { | ||
return "", result | ||
} | ||
|
||
if err = exe.Close(); err != nil { | ||
return "", err | ||
} | ||
|
||
return exe.Name(), nil | ||
} | ||
|
||
//nolint:forbidigo | ||
func findFile(rex *regexp.Regexp, dirs ...string) (string, string, error) { | ||
for idx, dir := range dirs { | ||
entries, err := os.ReadDir(dir) | ||
if err != nil { | ||
if idx == 0 { | ||
return "", "", err | ||
} | ||
|
||
continue | ||
} | ||
|
||
script := "" | ||
|
||
for _, entry := range entries { | ||
if rex.Match([]byte(entry.Name())) { | ||
script = entry.Name() | ||
|
||
break | ||
} | ||
} | ||
|
||
if len(script) > 0 { | ||
return filepath.Join(dir, script), script, nil | ||
} | ||
} | ||
|
||
return "", "", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,9 @@ | |
"examples", | ||
"license", | ||
"git", | ||
"versions" | ||
"versions", | ||
"build", | ||
"smoke" | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,5 @@ $defs: | |
- license | ||
- git | ||
- versions | ||
- build | ||
- smoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
k6lint `v0.2.0` is here 🎉! | ||
|
||
This version adds two new checkers to the linter: | ||
- **build checker** | ||
- **smoke checker** | ||
|
||
## build checker | ||
|
||
The check is successful if the extension can be built with the latest k6 release. | ||
|
||
## smoke checker | ||
|
||
The check is successful if there is a smoke test script and it runs successfully with the k6 built with the extension. | ||
|
||
Obviously, a prerequisite for a successful run is that the build checker runs successfully, otherwise k6 cannot be built with the extension. | ||
|
||
The smoke test script file is searched for in the root of the repository and in the `test`,`tests`,`examples` directories. The name of the smoke test script is one of the following: | ||
- `smoke.js` | ||
- `smoke.ts` | ||
- `smoke.test.js` | ||
- `smoke.test.ts` |