-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve reporting of errors & efficiency of pr-size-labeler #7288
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
Conversation
ee9985b
to
7f4a83b
Compare
b465134
to
c699fc9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7288 +/- ##
=======================================
Coverage 98.66% 98.66%
=======================================
Files 1106 1106
Lines 96186 96186
=======================================
Hits 94906 94906
Misses 1280 1280 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Errors in the invocation of `curl` were not being reported. Added `-f` flag to `curl`, return status checking, and printing the response body in case of errors.
- `cat` should have been `echo` - remove debugging setting - refactor a few lines in api_call()
78e70dd
to
5a71671
Compare
I never seem to need it.
This approach is a simple way to debug all shell scripts and commands.
And make sure it still returns the jq status code.
Write error response to stderr as stdout may be captured by the caller. Use `cat` for outputting response as `echo` may translate escape sequences. Make sure api_call returns the curl status code.
Avoid using `cmd <<<"$(api_call args)"` expressions which ignore `api_call` failure.
This is where it sends diagnostics if any.
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.
I think it is better if we use --fail-with-body
so we get to see the error response from the server. There were quite a few places in the original script which masked failure status from api_call
so I rewrote them in a way which should hopefully cause early exit.
Also, any error messages from api_call
need to go to stderr, because stdout is captured by callers.
PTAL at my take on this, it can be reviewed commit-by-commit.
@@ -55,15 +55,19 @@ jobs: | |||
pull-requests: write | |||
env: | |||
PR_NUMBER: ${{inputs.pr-number || github.event.pull_request.number}} | |||
SHELLOPTS: ${{inputs.trace && 'xtrace' || '' }} |
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.
is this used anywhere? If not please delete.
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, it is. The environment variable is recognized by Bash: https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-SHELLOPTS
Here what's happening is that when the Boolean trace
is set by using workflow_dispatch
, it causes SHELLOPTS to get the value xtrace
. That's the same as using set -x
: https://www.gnu.org/software/bash/manual/bash.html#index-set. Since the environment variable is set at the job level, all invocations get the SHELLOPTS value. The result is that all the Bash scripts and commands in the workflow get the equivalent of set -x
, and thus output a trace of their steps. This is useful for debugging.
The beauty of this approach is that it doesn't require modifying any of the run:
commands to add set -x
, and it can be turned on and off at run time.
Looks like we get some diagnostics - yay! |
.github/workflows/pr-labeler.yaml
Outdated
|
||
- name: Label the PR with a size label | ||
id: label | ||
continue-on-error: true | ||
env: | ||
GITHUB_TOKEN: ${{inputs.token || github.token}} | ||
GITHUB_TOKEN: ${{github.token}} | ||
run: ./dev_tools/ci/size-labeler.sh |& tee action.out |
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.
The pipe here masks the exit status from size-labeler.sh.
Please either add set -o pipefail
before or just take out the |& tee action.out
and
change line 79 to something like "see the output above".
PS: Or consider deleting the Detect and report errors...
step altogether.
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.
Please either add set -o pipefail before
I don't believe that's necessary; according to https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defaultsrunshell the default Bash invocation used by GitHub runners is
bash --noprofile --norc -eo pipefail {0}
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.
I don't believe that's necessary; ...
I can't see any other reason why would labeler workflow report success at https://github.com/quantumlib/Cirq/actions/runs/14654500719/job/41127085113. The script terminated at the api_call
line below and per job output it did not get to the next info "Added label..."
line.
Cirq/dev_tools/ci/size-labeler.sh
Lines 217 to 220 in 747fd6a
if [[ "${correctly_labeled}" != true ]]; then | |
api_call "issues/$PR_NUMBER/labels" -X POST -d "{\"labels\":[\"${size_label}\"]}" >/dev/null | |
info "Added label '${size_label}'" | |
fi |
On a second look, the shell command is actually listed as /usr/bin/bash -e {0}, which is one of the possibilities in your link. Regardless of that, the final step just repeats the size-labeler.sh output and is not really necessary. The output of this workflow is not important to contributors and is not worth the extra complexity and space for bugs like we get here.
Please consider taking it out and just have a simple execution of size-labeler.sh.
PS: if size-labeler remains flaky, we should intentionally let it report success, e.g.,
run: ./dev_tools/ci/size-labeler.sh || true
so that contributors are not confused by CI failure that has nothing to do with their work.
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.
/usr/bin/bash -e {0}
You're right! And now reading the GitHub docs, I think I understand what's happening: it seems that if there is no shell:
property, it defaults to this, whereas shell: bash
evidently makes it use the arguments that I thought it was using. (Why is it that way? I don't understand what the point of that is.)
Anyway, I'll change it as you propose.
Oh, argh. It looks like it needs a PAT after all. I'll change the token it uses in the next commmit. |
Once again, got bitten by the fact that adding labels to an issue doesn't work with `GITHUB_TOKEN` C.f. https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#add-labels-to-an-issue
This is for future readers.
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.
Please take out the last step that is obscuring exit status from labeler script. Otherwise LGTM.
Also, w/r to workflow permissions, we should change event type to
Also the workflow will then run with the |
Per [review comments by @Pavol](quantumlib#7288 (comment)), it is not doing what I thought it was doing. Plus, we don't really need the final output step.
Using a |
Errors in the invocation of
curl
were not being reported. Changes:size-labeler.sh
: Added-f
flag tocurl
, added return status checking, and added printing the response body in case of errors.pr-labeler.yaml
: Removed token option in workflow_dispatch and added a trace option. The token turns out to be never (or rarely) needed, and the shell tracing is useful for debugging.In addition, since the only file needed from the repository is the
size-labeler.sh
script, this also makes the git checkout inpr-labeler.yaml
be sparse.