diff --git a/.github/workflows/issue-bot.yml b/.github/workflows/issue-bot.yml index 2366222087..c62816c8b6 100644 --- a/.github/workflows/issue-bot.yml +++ b/.github/workflows/issue-bot.yml @@ -160,7 +160,17 @@ jobs: if: github.event_name == 'pull_request' env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - run: ./console.php evaluate >> $GITHUB_STEP_SUMMARY + run: | + set +e + ./console.php evaluate >> $GITHUB_STEP_SUMMARY + exit_code="$?" + + if [[ "$exit_code" == "2" ]]; then + echo "::notice file=.github/workflows/issue-bot.yml,line=3 ::Issue bot detected open issues which are affected by this pull request - see https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + exit 0 + fi + + exit $exit_code - name: "Evaluate results - push" working-directory: "issue-bot" @@ -169,4 +179,14 @@ jobs: GITHUB_PAT: ${{ secrets.PHPSTAN_BOT_TOKEN }} PHPSTAN_SRC_COMMIT_BEFORE: ${{ github.event.before }} PHPSTAN_SRC_COMMIT_AFTER: ${{ github.event.after }} - run: ./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY + run: | + set +e + ./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY + exit_code="$?" + + # its fine when issue-bot found affected issues + if [[ "$exit_code" == "2" ]]; then + exit 0 + fi + + exit $exit_code diff --git a/issue-bot/src/Console/EvaluateCommand.php b/issue-bot/src/Console/EvaluateCommand.php index 9836d85bb0..cc417f6b34 100644 --- a/issue-bot/src/Console/EvaluateCommand.php +++ b/issue-bot/src/Console/EvaluateCommand.php @@ -33,6 +33,10 @@ class EvaluateCommand extends Command { + private const EXIT_ERROR = 1; + private const EXIT_AFFECTS_ISSUES = 2; + private const EXIT_NO_AFFECTED_ISSUES = 0; + public function __construct( private TabCreator $tabCreator, private PostGenerator $postGenerator, @@ -133,7 +137,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } + $exitCode = self::EXIT_AFFECTS_ISSUES; if (count($toPost) === 0) { + $exitCode = self::EXIT_NO_AFFECTED_ISSUES; $output->writeln(sprintf('No changes in results in %d code snippets from %d GitHub issues. :tada:', $totalCodeSnippets, count($issueCache->getIssues()))); } @@ -163,7 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($postComments) { if (count($toPost) > 20) { $output->writeln('Too many comments to post, something is probably wrong.'); - return 1; + return self::EXIT_ERROR; } foreach ($toPost as ['issue' => $issue, 'hash' => $hash, 'users' => $users, 'diff' => $diff, 'details' => $details]) { $text = sprintf( @@ -191,7 +197,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - return 0; + return $exitCode; } /**