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
68 changes: 68 additions & 0 deletions .github/workflows/summary-code-generation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Summary code generation

on:
push:
branches:
- master
pull_request:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing it on each pull request, should we do only on the ones directly applying changes to lib/summary/... package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can. Although it's super cheap and fast, so not sure if it really worth it.


defaults:
run:
shell: bash

permissions:
contents: read

jobs:
check-generated-code:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
persist-credentials: false

- name: Install cog
run: |
COG_VERSION="v0.0.46"
curl -sSL "https://github.com/grafana/cog/releases/download/${COG_VERSION}/cog_Linux_x86_64.tar.gz" \
| sudo tar -xz -C /usr/local/bin
cog --version

- name: Checkout schemas
run: |
./internal/lib/summary/machinereadable/checkout.sh

- name: Generate code
run: |
./internal/lib/summary/machinereadable/generate.sh

- name: Check for uncommitted changes
run: |
# Check if there are any changes in the Git working directory
if ! git diff --exit-code; then
echo "❌ Generated code is not up-to-date!"
echo ""
echo "The following files have uncommitted changes:"
git diff --name-only
echo ""
echo "Please run the following commands to update the generated code:"
echo " ./internal/lib/summary/machinereadable/checkout.sh"
echo " ./internal/lib/summary/machinereadable/generate.sh"
echo ""
echo "Then commit the changes."
exit 1
fi

# Also check for untracked files
if [ -n "$(git ls-files --others --exclude-standard internal/lib/summary/machinereadable/ | grep -v k6-summary/)" ]; then
echo "❌ There are untracked generated files!"
echo ""
echo "Untracked files:"
git ls-files --others --exclude-standard internal/lib/summary/machinereadable/ | grep -v k6-summary/
echo ""
echo "Please run the generation scripts and commit all generated files."
exit 1
fi

echo "✅ Generated code is up-to-date!"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/k6.exe
/dist
/pkg-build
/internal/lib/summary/machinereadable/k6-summary
/internal/js/tc39/TestTC39
/internal/js/modules/k6/experimental/streams/tests/wpt
/internal/js/modules/k6/webcrypto/tests/wpt/
Expand Down
16 changes: 14 additions & 2 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"os"
"slices"
"strings"
"sync"
"syscall"
Expand All @@ -26,6 +27,7 @@ import (
"go.k6.io/k6/internal/lib/summary"
"go.k6.io/k6/internal/lib/trace"
"go.k6.io/k6/internal/metrics/engine"
"go.k6.io/k6/internal/output/cloud"
summaryoutput "go.k6.io/k6/internal/output/summary"
"go.k6.io/k6/internal/ui/pb"
"go.k6.io/k6/js/common"
Expand Down Expand Up @@ -220,6 +222,14 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
}
}

summaryMeta := summary.Meta{
Script: string(test.source.Data),
IsCloud: slices.ContainsFunc(outputs, func(o output.Output) bool {
_, isCloud := o.(*cloud.Output)
return isCloud
}),
}

switch summaryMode {
// TODO(@joanlopez): remove by k6 v2.0, once we completely drop the support for --summary-mode=legacy.
case summary.ModeLegacy:
Expand All @@ -229,7 +239,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
defer func() {
logger.Debug("Generating the end-of-test summary...")

summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, legacySummary(), nil)
summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, legacySummary(), nil, summaryMeta)
if hsErr == nil {
hsErr = handleSummaryResult(c.gs.FS, c.gs.Stdout, c.gs.Stderr, summaryResult)
}
Expand Down Expand Up @@ -262,8 +272,10 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
// likely as an additional argument like options.
summary.NoColor = c.gs.Flags.NoColor
summary.EnableColors = !summary.NoColor && c.gs.Stdout.IsTTY
summary.NewMachineReadableSummary = testRunState.RuntimeOptions.NewMachineReadableSummary.Valid &&
testRunState.RuntimeOptions.NewMachineReadableSummary.Bool

summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, legacySummary(), summary)
summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, legacySummary(), summary, summaryMeta)
if hsErr == nil {
hsErr = handleSummaryResult(c.gs.FS, c.gs.Stdout, c.gs.Stderr, summaryResult)
}
Expand Down
28 changes: 19 additions & 9 deletions internal/cmd/runtime_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ extended: base + sets "global" as alias for "globalThis"
"",
"output the end-of-test summary report to JSON file",
)
// TODO(@joanlopez): remove by k6 v2.0, once the new summary model is the default and the only one.
flags.Bool("new-machine-readable-summary", false, "enables the new machine-readable summary, "+
"which is used for summary exports and as handleSummary() argument")
flags.String("traces-output", "none",
"set the output for k6 traces, possible values are none,otel[=host:port]")
return flags
Expand Down Expand Up @@ -78,15 +81,16 @@ func getRuntimeOptions(

func runtimeOptionsFromFlags(flags *pflag.FlagSet) lib.RuntimeOptions {
opts := lib.RuntimeOptions{
TestType: getNullString(flags, "type"),
IncludeSystemEnvVars: getNullBool(flags, "include-system-env-vars"),
CompatibilityMode: getNullString(flags, "compatibility-mode"),
NoThresholds: getNullBool(flags, "no-thresholds"),
NoSummary: getNullBool(flags, "no-summary"),
SummaryMode: getNullString(flags, "summary-mode"),
SummaryExport: getNullString(flags, "summary-export"),
TracesOutput: getNullString(flags, "traces-output"),
Env: make(map[string]string),
TestType: getNullString(flags, "type"),
IncludeSystemEnvVars: getNullBool(flags, "include-system-env-vars"),
CompatibilityMode: getNullString(flags, "compatibility-mode"),
NoThresholds: getNullBool(flags, "no-thresholds"),
NoSummary: getNullBool(flags, "no-summary"),
SummaryMode: getNullString(flags, "summary-mode"),
SummaryExport: getNullString(flags, "summary-export"),
NewMachineReadableSummary: getNullBool(flags, "new-machine-readable-summary"),
TracesOutput: getNullString(flags, "traces-output"),
Env: make(map[string]string),
}
return opts
}
Expand Down Expand Up @@ -133,6 +137,12 @@ func populateRuntimeOptionsFromEnv(opts lib.RuntimeOptions, environment map[stri
opts.SummaryExport = null.StringFrom(envVar)
}

if err := saveBoolFromEnv(
environment, "K6_NEW_MACHINE_READABLE_SUMMARY", &opts.NewMachineReadableSummary,
); err != nil {
return opts, err
}

if envVar, ok := environment["SSLKEYLOGFILE"]; !opts.KeyWriter.Valid && ok {
opts.KeyWriter = null.StringFrom(envVar)
}
Expand Down
Loading
Loading