-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
[3.4] fix: enable strict mode for CI #15504
Conversation
3e2d228
to
9d7354f
Compare
.github/workflows/tests.yaml
Outdated
@@ -58,8 +58,12 @@ jobs: | |||
GO_BUILD_FLAGS='-v' GOARCH=s390x ./build | |||
;; | |||
linux-amd64-grpcproxy) | |||
set -o pipefail; set +e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it looks good, I will file a fix pr for main branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
To test I checked out this pr, pushed as a new branch with a bogus edit to a test file.
Opening a PR against 3.4 the workflow now correctly failed, refer: https://github.com/etcd-io/etcd/actions/runs/4454519493/jobs/7823765743?pr=15506
Thanks @fuweid 🙏🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Thank you @fuweid
Usually we fix the main branch firstly, then backport to 3.5 & 3.4. But I won't insist on it for such a small change.
.github/workflows/tests.yaml
Outdated
PASSES='build grpcproxy' CPU='4' RACE='true' ./test 2>&1 | tee test.log | ||
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log | ||
ecode=$? | ||
egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you remove the !
? We may need to keep it. If we find any (--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)
, we may still consider the test failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply.
I was thinking if we can delete the egrep
command in this patch.
I didn't see any comment about egrep introduced in #8655.
It seems that the egrep is used to fix the unexpected exit code, since | tee
won't return expected exit code because of pipefail
.
As the tee
already writes the log in the stdout, we won't lost any details and the command will return expected exit code. Maybe we can go with the following script:
set -o pipefail
PASSES='build grpcproxy' CPU='4' RACE='true' ./test 2>&1 | tee test.log
Does it make senses?
NOTE: In my opinion, if the
test.log
is not in the CI artifacts, we don't need the log file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be OK, because the following case will never happen:
The test script/cases exits with 0, but somehow there are some (--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)
errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. So I believe that egrep is to fix the pipefail
issue. I will update the pr later and send new pr to main branch as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the things that first caught my eye in etcd scripting is fact that it doesn't run in strict mode and it even depends on some parts failing for correctness. By strict mode I mean set -euo pipefail
as defined in http://redsymbol.net/articles/unofficial-bash-strict-mode/.
To my understanding !grep (--- FAIL:|...
was a workaround for not properly written scripts. I think long term it would be better to fix all scripts and switch on strict mode. What do you think? @ahrtr @fuweid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By strict mode I mean
set -euo pipefail
as defined in
Makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It came to me while reviewing #15519.
We cannot just set set -o pipefail; set +e;
in run
as bash doesn't pass the flags we set to scripts it calls. This will only affect run
and not ./test
.
So this change doesn't work if ./test
runs go test
that writes --- FAIL:
to stdout and doesn't exit with non-zero status code.
fixes: etcd-io#15487 Signed-off-by: Wei Fu <fuweid89@gmail.com>
@@ -588,6 +596,8 @@ function receiver_name_pass { | |||
} | |||
|
|||
function commit_title_pass { | |||
# TODO: git rev-parse --abbrev-ref doesn't work in pull-request and it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @serathius @ahrtr @jmhbnz please take a look. Thanks |
Can you prepare similar PR for v3.5? |
yeah. Still working on it. Will file it when it is ready. |
By default, the pipefail is disabled. For instance, the commands shouldreturn 1 as exit code, but we get zero. After pipefail enabled, it's
back to normal.
And the test.log is used to grep the error from a ton of messages. Sothat we shouldset +e
and set it back after egrep.fixes: #15487
Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.
1. If failed to build: https://github.com/etcd-io/etcd/actions/runs/4453530207/jobs/78221054852. If panic in the test: https://github.com/etcd-io/etcd/actions/runs/4453540829/jobs/7822123516@ahrtr @serathius @jmhbnz