Skip to content

Binary provisioning/use loadsource #4811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pablochacin
Copy link
Contributor

@pablochacin pablochacin commented May 23, 2025

What?

Use the loadsource function for dependency analysis

Why?

Presently, binary provisioning uses its own logic for loading the input for dependency analysis. This logic has some shortcomings like not handling input for stdin or limiting the processing of scripts with specific extensions.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Depens on #4801

Closes #4727
Closes #4696

@pablochacin pablochacin changed the base branch from master to binary-provisioning/integrate-root-cmd May 23, 2025 07:47
@pablochacin pablochacin force-pushed the binary-provisioning/use-loadsource branch from e6edf2e to 9066d48 Compare May 23, 2025 07:52
@pablochacin pablochacin marked this pull request as ready for review May 23, 2025 11:04
@pablochacin pablochacin requested a review from a team as a code owner May 23, 2025 11:04
@pablochacin pablochacin requested review from oleiade and codebien and removed request for a team May 23, 2025 11:04
@@ -277,37 +276,37 @@ func extractToken(gs *state.GlobalState) (string, error) {
// Presently, only the k6 input script or archive (if any) is passed to k6deps for scanning.
// TODO: if k6 receives the input from stdin, it is not used for scanning because we don't know
// if it is a script or an archive
func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error) {
func analyze(gs *state.GlobalState, _ *cobra.Command, args []string) (k6deps.Dependencies, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func analyze(gs *state.GlobalState, _ *cobra.Command, args []string) (k6deps.Dependencies, error) {
func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error) {

I don't like the fact we are passing Cobra primitives around. Is it really required to have this dependency? Can we break it in Go/k6 primitives and more scoped for the function?

Copy link
Contributor Author

@pablochacin pablochacin Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the problem is with using Cobra types, as we are within the execution of a Cobra command. Can you elaborate on what problems you see?

And, I'm not sure what you mean by "break it in Go/k6 primitives". Create abstractions around Cobra?

@oleiade
Copy link
Contributor

oleiade commented Jun 17, 2025

👀

Comment on lines 124 to 125
// is we are here, it is possible that the analyze function read the stdin to analyse it
// and restored the content into gs.Stdin, so we pass it to the command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs a re-arrangement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you refer to, but the initial "is" should be "if".

}

if strings.HasSuffix(scriptname, ".tar") {
dopts.Archive.Name = scriptname
if strings.HasSuffix(sourceRootPath, ".tar") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To facilitate maintenance, I suggest creating a constant for the tar file extension. This could be done in a separate PR though 🙇🏻

codebien
codebien previously approved these changes Jul 22, 2025
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

oleiade
oleiade previously approved these changes Jul 23, 2025
Base automatically changed from binary-provisioning/integrate-root-cmd to master July 25, 2025 12:28
@mstoykov mstoykov dismissed stale reviews from oleiade and codebien July 25, 2025 12:28

The base branch was changed.

@pablochacin pablochacin changed the base branch from master to binary-provisioning/integrate-root-cmd July 25, 2025 14:02
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin force-pushed the binary-provisioning/use-loadsource branch from e6e0018 to 0758402 Compare July 25, 2025 14:16
@pablochacin pablochacin changed the base branch from binary-provisioning/integrate-root-cmd to master July 25, 2025 14:16
@pablochacin pablochacin requested review from oleiade and codebien July 25, 2025 14:22
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin added this to the v1.2.0 milestone Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle input scripts with extensions other than .tar .js and .ts Handle script input from stdin
3 participants