Skip to content

Commit

Permalink
Split commenting into new workflow (#141)
Browse files Browse the repository at this point in the history
* Add workflow

* Fixes

* Recursive file creation

* Change name

* Remove commented out code

* Add changelog

* Changes as per review

* To be safe, rev version
  • Loading branch information
mosuem authored Jul 18, 2023
1 parent a52ac63 commit 02703ce
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/
72 changes: 72 additions & 0 deletions .github/workflows/post_summaries.yaml
Original file line number Diff line number Diff line change
@@ -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
});
}
3 changes: 3 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 8 additions & 10 deletions pkgs/firehose/lib/src/health/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 02703ce

Please sign in to comment.