mirror of
https://github.com/go-task/task.git
synced 2025-12-16 11:47:44 +01:00
feat: emit error annotations in GitHub Actions (#2568)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
@@ -28,19 +29,34 @@ func main() {
|
|||||||
Color: flags.Color,
|
Color: flags.Color,
|
||||||
}
|
}
|
||||||
if err, ok := err.(*errors.TaskRunError); ok && flags.ExitCode {
|
if err, ok := err.(*errors.TaskRunError); ok && flags.ExitCode {
|
||||||
|
emitCIErrorAnnotation(err)
|
||||||
l.Errf(logger.Red, "%v\n", err)
|
l.Errf(logger.Red, "%v\n", err)
|
||||||
os.Exit(err.TaskExitCode())
|
os.Exit(err.TaskExitCode())
|
||||||
}
|
}
|
||||||
if err, ok := err.(errors.TaskError); ok {
|
if err, ok := err.(errors.TaskError); ok {
|
||||||
|
emitCIErrorAnnotation(err)
|
||||||
l.Errf(logger.Red, "%v\n", err)
|
l.Errf(logger.Red, "%v\n", err)
|
||||||
os.Exit(err.Code())
|
os.Exit(err.Code())
|
||||||
}
|
}
|
||||||
|
emitCIErrorAnnotation(err)
|
||||||
l.Errf(logger.Red, "%v\n", err)
|
l.Errf(logger.Red, "%v\n", err)
|
||||||
os.Exit(errors.CodeUnknown)
|
os.Exit(errors.CodeUnknown)
|
||||||
}
|
}
|
||||||
os.Exit(errors.CodeOk)
|
os.Exit(errors.CodeOk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// emitCIErrorAnnotation emits an error annotation for supported CI providers.
|
||||||
|
func emitCIErrorAnnotation(err error) {
|
||||||
|
if isGA, _ := strconv.ParseBool(os.Getenv("GITHUB_ACTIONS")); !isGA {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e, ok := err.(*errors.TaskRunError); ok {
|
||||||
|
fmt.Fprintf(os.Stdout, "::error title=Task '%s' failed::%v\n", e.TaskName, e.Err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stdout, "::error title=Task failed::%v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
log := &logger.Logger{
|
log := &logger.Logger{
|
||||||
Stdout: os.Stdout,
|
Stdout: os.Stdout,
|
||||||
|
|||||||
@@ -2290,6 +2290,28 @@ The `output` option can also be specified by the `--output` or `-o` flags.
|
|||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
## CI Integration
|
||||||
|
|
||||||
|
### Colored output
|
||||||
|
|
||||||
|
Task automatically enables colored output when running in CI environments
|
||||||
|
(`CI=true`). Most CI providers set this variable automatically.
|
||||||
|
|
||||||
|
You can also force colored output with `FORCE_COLOR=1` or disable it with
|
||||||
|
`NO_COLOR=1`.
|
||||||
|
|
||||||
|
### Error annotations
|
||||||
|
|
||||||
|
When running in GitHub Actions (`GITHUB_ACTIONS=true`), Task automatically emits
|
||||||
|
error annotations when a task fails. These annotations appear in the workflow
|
||||||
|
summary, making it easier to spot failures without scrolling through logs.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
::error title=Task 'build' failed::exit status 1
|
||||||
|
```
|
||||||
|
|
||||||
|
This feature requires no configuration and works automatically.
|
||||||
|
|
||||||
## Interactive CLI application
|
## Interactive CLI application
|
||||||
|
|
||||||
When running interactive CLI applications inside Task they can sometimes behave
|
When running interactive CLI applications inside Task they can sometimes behave
|
||||||
|
|||||||
Reference in New Issue
Block a user