diff --git a/.github/workflows/health.yaml b/.github/workflows/health.yaml index fdddf060..0f719ee4 100644 --- a/.github/workflows/health.yaml +++ b/.github/workflows/health.yaml @@ -62,6 +62,11 @@ on: default: false type: boolean required: false + save_comment: + description: Whether to save summary as markdown file + default: false + type: boolean + required: false jobs: health: @@ -112,3 +117,22 @@ jobs: base-path: current_repo/ compare-sha: ${{ github.event.pull_request.base.ref }} allow-empty: true + + - name: Archive code coverage results + if: ${{ inputs.save_comment }} + uses: actions/upload-artifact@v3 + with: + name: code-coverage-report + path: output/${{ github.event.number }}/comment.md + + - name: Save PR number + if: ${{ inputs.save_comment }} + run: | + echo ${{ github.event.number }} > ./output/issueNumber + + - name: Upload folder with number and markdown + if: ${{ inputs.save_comment }} + uses: actions/upload-artifact@v2 + with: + name: output + path: output/ \ No newline at end of file diff --git a/.github/workflows/post_summaries.yaml b/.github/workflows/post_summaries.yaml new file mode 100644 index 00000000..08430307 --- /dev/null +++ b/.github/workflows/post_summaries.yaml @@ -0,0 +1,72 @@ +name: Comment on the pull request + +on: + # Trigger this workflow after the Health workflow completes. This workflow will have permissions to + # do things like create comments on the PR, even if the original workflow couldn't. + workflow_run: + workflows: [Health] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + + # Download the output of the health workflow, consisting of the comment markdown and either + # the issue number or an existing comment ID. + - name: 'Download artifact' + uses: actions/github-script@6f00a0b667f9463337970371ccda9072ee86fb27 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "output" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/comment.zip', Buffer.from(download.data)); + - run: unzip comment.zip + + + # Create the comment, or update the existing one, with the markdown + # generated in the Health workflow. + - name: 'Comment on PR' + uses: actions/github-script@6f00a0b667f9463337970371ccda9072ee86fb27 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + var fs = require('fs'); + var markdown = fs.readFileSync('./comment.md'); + if (fs.existsSync('./commentId')) { + var comment_number = Number(fs.readFileSync('./commentId')); + + await github.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment_number, + body: markdown + }); + } + else{ + var issue_number = Number(fs.readFileSync('./issueNumber')); + + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: markdown + }); + } \ No newline at end of file diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 5ef54877..b44c21f1 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.3.24 +- Start fixing [#137](https://github.com/dart-lang/ecosystem/issues/137). + ## 0.3.23 - Tweak PR health workflow. - Shorten some text in the markdown summary table. diff --git a/pkgs/firehose/lib/src/health/health.dart b/pkgs/firehose/lib/src/health/health.dart index 973a6d81..8b1f8e26 100644 --- a/pkgs/firehose/lib/src/health/health.dart +++ b/pkgs/firehose/lib/src/health/health.dart @@ -216,18 +216,16 @@ ${isWorseThanInfo ? 'This check can be disabled by tagging the PR with `skip-${r logError: print, ); - if (existingCommentId == null) { - await allowFailure( - github.createComment(repoSlug, issueNumber, summary), - logError: print, - ); - } else { - await allowFailure( - github.updateComment(repoSlug, existingCommentId, summary), - logError: print, - ); + if (existingCommentId != null) { + var idFile = File('./output/commentId'); + await idFile.create(recursive: true); + await idFile.writeAsString(existingCommentId.toString()); } + var commentFile = File('./output/comment.md'); + await commentFile.create(recursive: true); + await commentFile.writeAsString(summary); + if (results.any((result) => result.severity == Severity.error) && exitCode == 0) { exitCode = 1; diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index 3f061184..6ee23445 100644 --- a/pkgs/firehose/pubspec.yaml +++ b/pkgs/firehose/pubspec.yaml @@ -1,6 +1,6 @@ name: firehose description: A tool to automate publishing of Pub packages from GitHub actions. -version: 0.3.23 +version: 0.3.24 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose environment: