summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/CI/GithubActionReporter.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/console/CI/GithubActionReporter.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/CI/GithubActionReporter.php')
-rw-r--r--vendor/symfony/console/CI/GithubActionReporter.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/vendor/symfony/console/CI/GithubActionReporter.php b/vendor/symfony/console/CI/GithubActionReporter.php
new file mode 100644
index 0000000..2cae6fd
--- /dev/null
+++ b/vendor/symfony/console/CI/GithubActionReporter.php
@@ -0,0 +1,99 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Console\CI;
13
14use Symfony\Component\Console\Output\OutputInterface;
15
16/**
17 * Utility class for Github actions.
18 *
19 * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
20 */
21class GithubActionReporter
22{
23 private OutputInterface $output;
24
25 /**
26 * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85
27 */
28 private const ESCAPED_DATA = [
29 '%' => '%25',
30 "\r" => '%0D',
31 "\n" => '%0A',
32 ];
33
34 /**
35 * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L87-L94
36 */
37 private const ESCAPED_PROPERTIES = [
38 '%' => '%25',
39 "\r" => '%0D',
40 "\n" => '%0A',
41 ':' => '%3A',
42 ',' => '%2C',
43 ];
44
45 public function __construct(OutputInterface $output)
46 {
47 $this->output = $output;
48 }
49
50 public static function isGithubActionEnvironment(): bool
51 {
52 return false !== getenv('GITHUB_ACTIONS');
53 }
54
55 /**
56 * Output an error using the Github annotations format.
57 *
58 * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
59 */
60 public function error(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void
61 {
62 $this->log('error', $message, $file, $line, $col);
63 }
64
65 /**
66 * Output a warning using the Github annotations format.
67 *
68 * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message
69 */
70 public function warning(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void
71 {
72 $this->log('warning', $message, $file, $line, $col);
73 }
74
75 /**
76 * Output a debug log using the Github annotations format.
77 *
78 * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message
79 */
80 public function debug(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void
81 {
82 $this->log('debug', $message, $file, $line, $col);
83 }
84
85 private function log(string $type, string $message, ?string $file = null, ?int $line = null, ?int $col = null): void
86 {
87 // Some values must be encoded.
88 $message = strtr($message, self::ESCAPED_DATA);
89
90 if (!$file) {
91 // No file provided, output the message solely:
92 $this->output->writeln(sprintf('::%s::%s', $type, $message));
93
94 return;
95 }
96
97 $this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message));
98 }
99}