Calls to `opoo` and `onoe` produce duplicate `Warning:` and `Error:`
messages in CI logs because we print something to stdout and print an
annotation. Annotations also produce `Error:` and `Warning:` lines in
the log.
Let's fix this by skipping printing the message if we've already printed
an annotation.
- only use annotations for `opoo` and `onoe` if
`HOMEBREW_GITHUB_ACTIONS` is set. This will make using `brew` less
noisy in GitHub Actions for third parties. See
Homebrew/discussions#5602.
- if we've already called `puts_annotation_if_env_set`, then we no
longer need to print the message to `$stderr`. The message from the
annotation already show up in the GitHub Actions log, so printing to
`$stderr` just leads to duplicate messages in the log.
While we're here, let's make sure to forward the `file:` and `line:`
kwargs of `puts_annotation_if_env_set` to the `Annotation` constructor.
We currently generate invalid workflow commands when we create
annotations with a `title` but no `file`. Let's fix that.
While we're here, let's improve handling of `title`s with `:`s. We
cannot use `title`s with `::` since GitHub Actions uses this as a
separator for different fields between a workflow command.
Let's also make sure `metadata` never ends in a `:` to avoid confusing
the GitHub Actions command parser about where the `::` separator is
meant to be.
Per feedback to https://github.com/Homebrew/brew/pull/17806, this
moves some `require` statements in `dev-cmd/contributions.rb` and
`Utils::GitHub` into the methods that need them.
This will mean e.g. `opoo` etc. will output to stdout and not end up
being in the stdout of `brew deps` etc.
While we're here, remove a duplicate annotation output I noticed in
`extend/kernel.rb`.
Inspired by conversation in:
https://github.com/Homebrew/homebrew-test-bot/issues/1082
We already do this for deprecations but these may make warnings
and errors from Homebrew easier to spot in GitHub Actions logs.
While we're here, cleanup other cases that should have used
`GitHub::Actions::Annotation` but didn't and provide some helpers and
tweaks there necessary for our use case here.