Skip to content
Open
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
2 changes: 1 addition & 1 deletion SECURITY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Installation token
limited to the test repository and to the permissions the bot uses:

- Actions: read and write (reading runs, reruns, dispatching);
- Checks: read (warning annotations);
- Checks: read (warning and error annotations);
- Contents: read and write (test branches and recovery refs);
- Workflows: read and write (patches may change workflow files);
- Metadata: read (always granted).
Expand Down
2 changes: 1 addition & 1 deletion SETUP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Fill in the form:
- **Repository permissions**:

- Actions: read and write (reading runs, reruns, dispatching);
- Checks: read-only (warning annotations, see
- Checks: read-only (warning and error annotations, see
``workflows.warning_annotation`` in ``examples/reference.yaml``);
- Contents: read and write (pushing test branches);
- Workflows: read and write (patches may change workflow files);
Expand Down
4 changes: 4 additions & 0 deletions examples/ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ report:
# Answers from submitters go to ovs-dev.
reply_to: ovs-dev@openvswitch.org
pending: check
# List the failed tests of these workflows in reports.
workflow_logs_format:
ovn-kubernetes: ginkgo
Build and Test: autotest

archive:
reports_url: https://mail.openvswitch.org/pipermail/ovs-build/
Expand Down
124 changes: 119 additions & 5 deletions examples/reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,119 @@ report:
# Email a report for every patch that applied, not only for failures.
apply_success: true

# Reports of failed runs include the last log_lines lines of up to
# max_log_jobs failed jobs.
# Format of the job logs of each workflow, by workflow name (as in
# the Test-Label, ignoring case), used to list the failed tests and
# show their logs in reports of failed runs. The jobs of a workflow
# that is not listed, or whose log has no failed tests in its format
# (for example when the build failed), get the last log_lines lines of
# their log instead. Leave it empty, the default, to always report
# the last log_lines lines of every job. For example:
#
# workflow_logs_format:
# ovn-kubernetes: ginkgo
# Build and Test: autotest
#
# The formats are:
#
# - autotest: Autotest test suites, like "make check" of OVS and OVN,
# when the job prints tests/testsuite.log after the tests fail. The
# failed tests are those of its "Summary of the failures" (failed
# tests and unexpected passes), from every test suite the job ran,
# and the log of each is its part of "Detailed failed tests". The
# error is at the end of those logs, so a long one keeps its last
# max_test_lines lines, after a note on how many lines came before.
#
# - ginkgo: Ginkgo test suites, like the e2e tests of ovn-kubernetes.
# The failed specs are those of the "Summarizing N Failures:" list at
# the end of the suite, and the log of each is the report Ginkgo
# printed when it failed, with its error. Go unit tests that run in
# the same job are not looked at.
workflow_logs_format: {}

# Limits on the logs in reports of failed runs. All of them are
# optional; the values below are the defaults. Each must be at least
# 1. Wherever a limit cuts something, the report says how much was
# left out and to see the workflow run:
#
# ... 12 more failed tests, see the workflow run.
# ... 40 more lines, see the workflow run.
#
# A report starts with the list of all failed jobs, from GitHub, with
# the step each failed at. Then come the logs of the first
# max_log_jobs failed jobs, each in one of three ways:
#
# - When the job has error annotations titled
# workflows.warning_annotation, like the checkpatch workflows:
#
# Errors of "<job>":
# <the messages of those annotations>
#
# - Otherwise, when workflow_logs_format gives the workflow a format
# and failed tests are found in the job's log:
#
# Failed tests in "<job>":
# <test name> <- up to max_listed_tests names
# ...
# ... N more failed tests, see the workflow run.
#
# <test name> <- up to max_tests tests, each with
# <log of the test> up to max_test_lines log lines
# ...
# ... N more failed tests, see the workflow run.
#
# Only whole tests are shown: each test shown gets its log up to
# max_test_lines lines, never less to make room for others. So a job shows at
# most max_tests x max_test_lines log lines, plus the list of names,
# the test names and the notes. With the defaults, that is at most
# 4 x 25 = 100 log lines, and about 160 lines in all with a full list
# of 50 names.
#
# A test's log is shown only once per report: when the same test
# fails in several jobs, the later jobs list its name, say its log
# is skipped, and don't count it toward their max_tests.
#
# - Otherwise (no format, or no failed tests found in the log, as when
# the build fails before the tests run):
#
# Last <log_lines> log lines of "<job>":
# <the last log_lines lines of the job's log>
#
# These lines end with the line that ends the step that failed (the
# "##[error]Process completed with exit code" line), so the cleanup
# steps after it do not hide the error.
#
# The logs of the jobs after the first max_log_jobs are left out, with
# a note saying how many.
#
# max_lines is a ceiling on the whole report. It counts every line:
# the list of failed jobs, blank lines, headings, lists of failed
# tests, test names, log lines and notes. Once the report reaches it,
# no more jobs are added, and the report is cut after max_lines lines,
# even in the middle of a test. The report is also always cut after
# 20000 characters, in case of very long lines. Reports with a few
# failed tests stay well under max_lines; it only cuts reports of runs
# with many failures in several jobs. To get shorter reports, lower
# max_log_jobs, max_tests, max_test_lines and max_listed_tests first.
# The warnings in reports of runs that passed with warnings, and
# reports of patches that fail to apply, with the git am output and the
# diff of the conflicts, are cut the same way.
#
# So not every limit applies to every job:
#
# - max_log_jobs and max_lines apply to every report.
# - The errors of annotations, like those of checkpatch, are only cut
# by max_lines.
# - Reports of patches that fail to apply are only cut by max_lines.
# - max_listed_tests, max_tests and max_test_lines only apply to the
# workflows given a format in workflow_logs_format.
# - log_lines only applies to the jobs reported with the last lines of
# their log.
max_log_jobs: 3
max_listed_tests: 50
max_tests: 4
max_test_lines: 25
log_lines: 25
max_log_jobs: 5
max_lines: 300

# Right-hand side of generated Message-IDs. Empty means the domain
# of the LEADTEST_SMTP_USERNAME address.
Expand Down Expand Up @@ -370,9 +479,14 @@ workflows:
# annotations with this title, e.g. from
# echo "::warning title=leadtest::2 lines are too long"
# Their messages are included in the report. This lets a workflow
# pass with warnings, like checkpatch in fork-workflows/. Reading the
# pass with warnings, like checkpatch in fork-workflows/. The report of
# a failed job carries the messages of its error annotations with this
# title, e.g. from
# echo "::error title=leadtest::ERROR: Line is too long"
# instead of its log. Either way the messages are cut to
# report.max_lines lines and 20000 characters. Reading the
# annotations needs the Checks permission of the GitHub App (see
# SETUP.rst). Empty disables it.
# SETUP.rst). Empty disables both.
warning_annotation: leadtest

rechecks:
Expand Down
17 changes: 16 additions & 1 deletion fork-workflows/leadtest-checkpatch-dpdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,23 @@ jobs:
done
chmod +x linux/checkpatch.pl

# On failure the output goes in an error annotation titled like
# workflows.warning_annotation, which LeadTestKit reports instead of
# the end of the log.
- name: Run checkpatches.sh
run: |
cd dpdk
status=0
DPDK_CHECKPATCH_PATH="$GITHUB_WORKSPACE/linux/checkpatch.pl" \
devtools/checkpatches.sh "$GITHUB_WORKSPACE/patch.mbox"
devtools/checkpatches.sh "$GITHUB_WORKSPACE/patch.mbox" \
> ../checkpatch.log 2>&1 || status=$?
cat ../checkpatch.log
[ "$status" -eq 0 ] && exit 0
python3 - ../checkpatch.log <<'EOF'
import sys
text = open(sys.argv[1]).read().strip()
for c, e in (("%", "%25"), ("\r", "%0D"), ("\n", "%0A")):
text = text.replace(c, e)
print("::error title=leadtest::" + text)
EOF
exit "$status"
24 changes: 14 additions & 10 deletions fork-workflows/leadtest-checkpatch-ovs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ jobs:
cp upstream/utilities/checkpatch.py checkpatch.py
fi

# Errors fail the job. With only warnings the job passes with a
# warning annotation titled like workflows.warning_annotation, and
# LeadTestKit reports a warning with its text.
# The output of checkpatch goes in an annotation titled like
# workflows.warning_annotation, which LeadTestKit reports instead of
# the end of the log. Errors fail the job with an error annotation.
# With only warnings the job passes with a warning annotation, and
# LeadTestKit reports a warning.
- name: Run checkpatch
run: |
status=0
python3 checkpatch.py patch.mbox > checkpatch.log 2>&1 || status=$?
cat checkpatch.log
if [ "$status" -ne 0 ] && ! grep -q '^ERROR' checkpatch.log &&
grep -q '^WARNING' checkpatch.log; then
python3 - checkpatch.log <<'EOF'
[ "$status" -eq 0 ] && exit 0
level=error
if ! grep -q '^ERROR' checkpatch.log && grep -q '^WARNING' checkpatch.log; then
level=warning
fi
python3 - "$level" checkpatch.log <<'EOF'
import sys
text = open(sys.argv[1]).read().strip()
text = open(sys.argv[2]).read().strip()
for c, e in (("%", "%25"), ("\r", "%0D"), ("\n", "%0A")):
text = text.replace(c, e)
print("::warning title=leadtest::" + text)
print("::%s title=leadtest::%s" % (sys.argv[1], text))
EOF
exit 0
fi
[ "$level" = warning ] && exit 0
exit "$status"
56 changes: 43 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -107,6 +108,10 @@ type TestRepo struct {
GitHost string `yaml:"git_host"`
}

// LogFormats are the job log formats that can be given in
// report.workflow_logs_format.
var LogFormats = []string{"ginkgo", "autotest"}

type Report struct {
// Style is "ovs" (patchwork state names) or "dpdk" (upper case).
Style string `yaml:"style"`
Expand All @@ -122,8 +127,16 @@ type Report struct {
// "both" or "off".
Pending string `yaml:"pending"`
ApplySuccess bool `yaml:"apply_success"`
LogLines int `yaml:"log_lines"`
MaxLogJobs int `yaml:"max_log_jobs"`
// WorkflowLogsFormat maps workflow names to the format of their job
// logs, one of LogFormats, to find the failed tests in them.
WorkflowLogsFormat map[string]string `yaml:"workflow_logs_format"`
// Limits on the logs in reports of failed runs.
MaxLogJobs int `yaml:"max_log_jobs"`
MaxListedTests int `yaml:"max_listed_tests"`
MaxTests int `yaml:"max_tests"`
MaxTestLines int `yaml:"max_test_lines"`
LogLines int `yaml:"log_lines"`
MaxLines int `yaml:"max_lines"`
// MessageIDDomain is the right-hand side of generated Message-IDs.
MessageIDDomain string `yaml:"message_id_domain"`
}
Expand Down Expand Up @@ -268,7 +281,8 @@ type Workflows struct {
// RerunJobs is "failed" (GitHub's "Re-run failed jobs") or "all".
RerunJobs string `yaml:"rerun_jobs"`
// WarningAnnotation is the title of the warning annotations that
// make a successful run a warning. Empty disables the check.
// make a successful run a warning, and of the error annotations
// reported instead of the log of a failed job. Empty disables both.
WarningAnnotation string `yaml:"warning_annotation"`
}

Expand Down Expand Up @@ -323,16 +337,21 @@ func defaults() Config {
GitHost: "github.com",
},
Report: Report{
Style: "ovs",
Label: "github-robot",
ApplyLabel: "apply-robot",
FromName: "LeadTestKit Robot",
BuildPrefix: "github build",
Reply: Reply{Mode: "on-failure"},
Pending: "both",
ApplySuccess: true,
LogLines: 25,
MaxLogJobs: 5,
Style: "ovs",
Label: "github-robot",
ApplyLabel: "apply-robot",
FromName: "LeadTestKit Robot",
BuildPrefix: "github build",
Reply: Reply{Mode: "on-failure"},
Pending: "both",
ApplySuccess: true,
WorkflowLogsFormat: map[string]string{},
MaxLogJobs: 3,
MaxListedTests: 50,
MaxLines: 300,
MaxTests: 4,
MaxTestLines: 25,
LogLines: 25,
},
Archive: Archive{
MinDelay: Duration(time.Second),
Expand Down Expand Up @@ -744,6 +763,17 @@ func (c *Config) validate() error {
if l.PerAuthorMaxShare <= 0 || l.PerAuthorMaxShare > 1 {
add("limits.per_author_max_share must be in (0, 1]")
}
rp := c.Report
if rp.MaxLogJobs < 1 || rp.MaxListedTests < 1 || rp.MaxLines < 1 ||
rp.MaxTests < 1 || rp.MaxTestLines < 1 || rp.LogLines < 1 {
add("report: max_log_jobs, max_listed_tests, max_lines, max_tests, " +
"max_test_lines and log_lines must be >= 1")
}
for wf, f := range rp.WorkflowLogsFormat {
if !slices.Contains(LogFormats, f) {
add("report: workflow_logs_format: unknown format %q for %q", f, wf)
}
}
if c.Runner.LoopInterval <= 0 || c.Runner.LoopDuration < 0 {
add("runner: loop_interval must be positive")
}
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func TestValidationErrors(t *testing.T) {
"stale 1s": minimal + "\npages:\n stale_after: 1s\n",
"bad pending": strings.Replace(minimal, "report:\n",
"report:\n pending: yes\n", 1),
"unknown log format": strings.Replace(minimal, "report:\n",
"report:\n workflow_logs_format:\n lorem: ipsum\n", 1),
"no dev archive for rechecks": strings.Replace(minimal,
"archive:\n dev_url: https://lists.example.org/pipermail/lorem-dev/\n",
"", 1),
Expand Down
20 changes: 17 additions & 3 deletions internal/gitrepo/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (w *WorkRepo) ReadFile(ctx context.Context, rev, path string) ([]byte, erro
// Apply applies the emails on top of base one by one. It returns the
// commit of every applied patch, or "" for a patch whose change is
// already there, which git am applies without a commit; on a failure it
// also returns the index of the failing patch and the git am output.
// also returns the index of the failing patch and the git am output,
// followed by the diff of any conflicts.
func (w *WorkRepo) Apply(
ctx context.Context, base string, mboxes [][]byte,
) ([]string, int, string, error) {
Expand Down Expand Up @@ -182,13 +183,24 @@ func (w *WorkRepo) Apply(
if err != nil {
return shas, -1, "", err
}
if _, err := g.Run(ctx, "am", "-q", "-3", "--no-gpg-sign", file); err != nil {
// Without -q, git am names the files with conflicts.
if _, err := g.Run(ctx, "-c", "advice.mergeConflict=false", "-c",
"advice.amWorkDir=false", "am", "-3",
"--no-gpg-sign", file); err != nil {
var gerr *Error
if !errors.As(err, &gerr) {
return shas, -1, "", err
}
out := strings.TrimSpace(gerr.Stdout + "\n" + gerr.Stderr)
diff, err := w.Git.Out(ctx, "diff", "--no-color", "--no-ext-diff")
w.abortAm(ctx)
return shas, i, strings.TrimSpace(gerr.Stdout + "\n" + gerr.Stderr), nil
if err != nil {
return shas, -1, "", err
}
if diff != "" {
out += "\n\n" + diffHeading + "\n" + diff
}
return shas, i, out, nil
}
sha, err := w.Git.Out(ctx, "rev-parse", "HEAD")
if err != nil {
Expand All @@ -204,6 +216,8 @@ func (w *WorkRepo) Apply(
return shas, -1, "", nil
}

const diffHeading = "Diff of the conflicts:"

// SameChange reports whether a commit makes the change of an email,
// comparing stable patch IDs, which ignore whitespace and line numbers.
func (w *WorkRepo) SameChange(ctx context.Context, sha string, mbox []byte) (bool, error) {
Expand Down
Loading