Write comments on forks for `firehose` (#165)
* Write comments on forks for `firehose`
* Allow failure in writing a comment
* Remove deleteComment
* Global `continue-on-error: true`
* Add to internal
* Rev version
* Do not continue on error
* All artifacts
* if empty
* Add logging
* Log artifact
* add name
* Reset
* trigger on publish only
* Publish for both
* Small fixes
* Delete comment on empty body
* Remove arg
diff --git a/.github/workflows/post_summaries.yaml b/.github/workflows/post_summaries.yaml
index e86914f..bfb1032 100644
--- a/.github/workflows/post_summaries.yaml
+++ b/.github/workflows/post_summaries.yaml
@@ -5,7 +5,9 @@
# do things like create comments on the PR, even if the original workflow couldn't.
workflow_call:
workflow_run:
- workflows: [Health]
+ workflows:
+ - Publish
+ - Health
types:
- completed
@@ -17,6 +19,7 @@
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
+ continue-on-error: true
steps:
# Download the output of the health workflow, consisting of the comment markdown and either
@@ -26,18 +29,18 @@
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
- owner: context.repo.owner,
- repo: context.repo.repo,
- run_id: ${{ github.event.workflow_run.id }},
+ 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.rest.actions.downloadArtifact({
- owner: context.repo.owner,
- repo: context.repo.repo,
- artifact_id: matchArtifact.id,
- archive_format: 'zip',
+ 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));
@@ -52,24 +55,33 @@
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
- var markdown = fs.readFileSync('./comment.md', 'utf8');
- if (fs.existsSync('./commentId')) {
+ if (fs.existsSync('./comment.md')) {
+ var markdown = fs.readFileSync('./comment.md', 'utf8');
+ if (fs.existsSync('./commentId')) {
+ var comment_number = Number(fs.readFileSync('./commentId', 'utf8'));
+
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: comment_number,
+ body: markdown
+ });
+ } else {
+ var issue_number = Number(fs.readFileSync('./issueNumber', 'utf8'));
+
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issue_number,
+ body: markdown
+ });
+ }
+ } else if (fs.existsSync('./commentId')) {
var comment_number = Number(fs.readFileSync('./commentId', 'utf8'));
-
- await github.rest.issues.updateComment({
+
+ await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_number,
- body: markdown
});
}
- else{
- var issue_number = Number(fs.readFileSync('./issueNumber', 'utf8'));
-
- await github.rest.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/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
index 8ddc2cb..a66a031 100644
--- a/.github/workflows/publish.yaml
+++ b/.github/workflows/publish.yaml
@@ -96,6 +96,17 @@
PR_LABELS: "${{ join(github.event.pull_request.labels.*.name) }}"
run: dart pub global run firehose --validate ${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[inputs.use-flutter] }}
+ - name: Save PR number
+ run: |
+ mkdir -p output/ && echo ${{ github.event.number }} > output/issueNumber
+
+ - name: Upload folder with number and markdown
+ uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05
+ with:
+ name: output
+ path: output/
+
+
publish:
if: ${{ github.event_name == 'push' }}
diff --git a/.github/workflows/publish_internal.yaml b/.github/workflows/publish_internal.yaml
index c34d8bc..3fb6f6f 100644
--- a/.github/workflows/publish_internal.yaml
+++ b/.github/workflows/publish_internal.yaml
@@ -42,6 +42,16 @@
PR_LABELS: "${{ join(github.event.pull_request.labels.*.name) }}"
run: dart pkgs/firehose/bin/firehose.dart --validate ${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[env.use-flutter] }}
+ - name: Save PR number
+ run: |
+ mkdir -p output/ && echo ${{ github.event.number }} > output/issueNumber
+
+ - name: Upload folder with number and markdown
+ uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05
+ with:
+ name: output
+ path: output/
+
- name: Publish tagged package
if: ${{ github.event_name == 'push' }}
run: dart pkgs/firehose/bin/firehose.dart --publish ${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[env.use-flutter] }}
diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md
index 6ebed0d..71004e3 100644
--- a/pkgs/firehose/CHANGELOG.md
+++ b/pkgs/firehose/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.3.28
+
+- Fix [#156](https://github.com/dart-lang/ecosystem/issues/156).
+
## 0.3.27
- Fix Flutter support.
diff --git a/pkgs/firehose/lib/firehose.dart b/pkgs/firehose/lib/firehose.dart
index 05c09f3..8011dcc 100644
--- a/pkgs/firehose/lib/firehose.dart
+++ b/pkgs/firehose/lib/firehose.dart
@@ -72,30 +72,22 @@
if (results.hasSuccess) {
var commentText = '$_publishBotTag\n\n$markdownTable';
- if (existingCommentId == null) {
- await allowFailure(
- github.createComment(
- github.repoSlug!, github.issueNumber!, commentText),
- logError: print,
- );
- } else {
- await allowFailure(
- github.updateComment(
- github.repoSlug!, existingCommentId, commentText),
- logError: print,
- );
+ if (existingCommentId != null) {
+ var idFile = File('./output/commentId');
+ print('''
+Saving existing comment id $existingCommentId to file ${idFile.path}''');
+ await idFile.create(recursive: true);
+ await idFile.writeAsString(existingCommentId.toString());
}
+
+ var commentFile = File('./output/comment.md');
+ print('Saving comment markdown to file ${commentFile.path}');
+ await commentFile.create(recursive: true);
+ await commentFile.writeAsString(commentText);
} else {
if (results.hasError && exitCode == 0) {
exitCode = 1;
}
-
- if (existingCommentId != null) {
- await allowFailure(
- github.deleteComment(github.repoSlug!, existingCommentId),
- logError: print,
- );
- }
}
github.close();
diff --git a/pkgs/firehose/lib/src/github.dart b/pkgs/firehose/lib/src/github.dart
index 3f6be35..c0400d9 100644
--- a/pkgs/firehose/lib/src/github.dart
+++ b/pkgs/firehose/lib/src/github.dart
@@ -139,18 +139,6 @@
});
}
- /// Create a new comment on the given PR.
- Future<String> createComment(
- String repoSlug, String issueNumber, String commentText) async {
- var result = await callRestApiPost(
- Uri.parse(
- 'https://api.github.com/repos/$repoSlug/issues/$issueNumber/comments'),
- jsonEncode({'body': commentText}),
- );
- var json = jsonDecode(result) as Map;
- return json['url'] as String;
- }
-
/// Find a comment on the PR matching the given criteria ([user],
/// [searchTerm]). Return the issue ID if a matching comment is found or null
/// if there's no match.
@@ -181,23 +169,6 @@
return null;
}
- /// Update the given PR comment with new text.
- Future<String> updateComment(
- String repoSlug, int commentId, String commentText) async {
- var result = await callRestApiPatch(
- Uri.parse(
- 'https://api.github.com/repos/$repoSlug/issues/comments/$commentId'),
- jsonEncode({'body': commentText}),
- );
- var json = jsonDecode(result) as Map;
- return json['url'] as String;
- }
-
- Future<void> deleteComment(String repoSlug, int commentId) async {
- await callRestApiDelete(Uri.parse(
- 'https://api.github.com/repos/$repoSlug/issues/comments/$commentId'));
- }
-
Future<List<GitFile>> listFilesForPR() async {
var result = await callRestApiGet(
Uri.parse(
diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml
index 2577743..18097bf 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.27
+version: 0.3.28
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose
environment: