Skip to content
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

Add built-in support for GitHub Actions annotations #164

Open
1 task done
swissspidy opened this issue Apr 26, 2022 · 1 comment
Open
1 task done

Add built-in support for GitHub Actions annotations #164

swissspidy opened this issue Apr 26, 2022 · 1 comment

Comments

@swissspidy
Copy link
Member

swissspidy commented Apr 26, 2022

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants