wp-cli / ideas

💡 Ideas and feature requests are collected here
40 stars 1 forks source link

Add built-in support for GitHub Actions annotations #164

Open swissspidy opened 2 years ago

swissspidy commented 2 years ago

Feature Request

Describe your use case and the problem you are facing

GitHub Actions is a very popular choice for CI and used by a lot of WordPress projects.

Actions can communicate with the runner machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks.

They can use a specific format to send messages that result in direct code annotations displayed on GitHub. Annotations can associate the message with a particular file in the repository and even with a specific position within the file.

See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

Example:


echo "::notice file=app.js,line=1,col=5,endColumn=7::Missing semicolon"

echo "::warning file=app.js,line=1,col=5,endColumn=7::Missing semicolon"

echo "::error file=app.js,line=1,col=5,endColumn=7::Missing semicolon"

Having a built-in way in WP-CLI to print such messages/annotations might be useful for WP-CLI commands such as wp i18n or Traduttore, but also others, as it allows one to easily use them in a GitHub Action context without any extra overhead.

Related:

Describe the solution you'd like

The first possible solution that came to mind is extending the Formatter, adding a new github-actions case here:

https://github.com/wp-cli/wp-cli/blob/c3bd5bd76abf024f9d492579539646e0d263a05a/php/WP_CLI/Formatter.php#L133-L181

Similar to the table formatter it could take an array like this and echo the output as expected by GitHub Actions:

$annotations = [
    [
        'type' => 'notice', // or 'warning' or 'error',
        'title' => 'Attention please', // Custom title.
        'file' => 'foo.php', // Filename
        'col' => 1, // Column number, starting at 1
        'endColumn' => 1, // End column number
        'line' => 1, // Line number, starting at 1
        'endLine' => 1, // End line number
    ],

    [
        'type' => 'error', // or 'warning' or 'error',
        'title' => 'Some error', // Custom title.
        'file' => 'bar.js', // Filename
        'col' => 10, // Column number, starting at 1
        'endColumn' => 20, // End column number
        'line' => 10, // Line number, starting at 1
        'endLine' => 10, // End line number
    ],

    [
        'type' => 'warning', // or 'warning' or 'error',
        'title' => 'Some warning', // Custom title.
        'file' => 'bar.js', // Filename
        'col' => 1, // Column number, starting at 1
        'endColumn' => 1, // End column number
        'line' => 10, // Line number, starting at 1
        'endLine' => 20, // End line number
    ],
];

Then commands could support this via a --format argument, e.g. --format=github-actions

danielbachhuber commented 2 years ago

👍 I'm amenable to this. How would you transform the idea to actionable tasks?