Allow both single-workflow and fork-enabled publishing validation (#174)

* Test workflow local

* change owner

* Replace mode

* Add boolean condition

* Use post_summaries

* fix and

* Fix ifs

* make env bool

* fix bool again

* Fix

* Fix

* Another fix

* don't write in internal

* Add documentation
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
index a66a031..e27ead4 100644
--- a/.github/workflows/publish.yaml
+++ b/.github/workflows/publish.yaml
@@ -37,6 +37,15 @@
 #     with:
 #       use-flutter: true
 
+# When using a post_summaries.yaml workflow to post the comments, set
+# the write-comments parameter to false.
+#
+# jobs:
+#   publish:
+#     uses: dart-lang/ecosystem/.github/workflows/publish.yml@main
+#     with:
+#       write-comments: false
+
 on:
   workflow_call:
     inputs:
@@ -62,6 +71,12 @@
         default: false
         required: false
         type: boolean
+      write-comments:
+        description: >-
+          Whether to write a comment in this workflow.
+        default: true
+        required: false
+        type: boolean
 
 jobs:
   # Note that this job does not require the specified environment.
@@ -96,11 +111,36 @@
           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: Get comment id
+        if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments }}
+        run: |
+          touch -a output/commentId
+          COMMENT_ID=$(cat output/commentId)
+          echo "COMMENT_ID=$COMMENT_ID" >> $GITHUB_ENV
+
+      - name: Create comment
+        uses: peter-evans/create-or-update-comment@46da6c0d98504aed6fc429519a258b951f23f474
+        if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments && (env.COMMENT_ID == '') }}
+        with:
+          issue-number: ${{ github.event.number }}
+          body-path: 'output/comment.md'
+          edit-mode: replace
+
+      - name: Update comment
+        uses: peter-evans/create-or-update-comment@46da6c0d98504aed6fc429519a258b951f23f474
+        if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments && (env.COMMENT_ID != '') }}
+        with:
+          comment-id: ${{ env.COMMENT_ID }}
+          body-path: 'output/comment.md'
+          edit-mode: replace
+
       - name: Save PR number
+        if: ${{ !inputs.write-comments }}
         run: |
           mkdir -p output/ && echo ${{ github.event.number }} > output/issueNumber
 
       - name: Upload folder with number and markdown
+        if: ${{ !inputs.write-comments }}
         uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05
         with:
           name: output
diff --git a/.github/workflows/publish_internal.yaml b/.github/workflows/publish_internal.yaml
index 3fb6f6f..341cbf6 100644
--- a/.github/workflows/publish_internal.yaml
+++ b/.github/workflows/publish_internal.yaml
@@ -14,6 +14,7 @@
 
 env:
   use-flutter: false
+  write-comments: false
 
 jobs:
   publish:
@@ -42,11 +43,36 @@
           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: Get comment id
+        if: ${{ (hashFiles('output/comment.md') != '') && fromJSON(env.write-comments ) }}
+        run: |
+          touch -a output/commentId
+          COMMENT_ID=$(cat output/commentId)
+          echo "COMMENT_ID=$COMMENT_ID" >> $GITHUB_ENV
+
+      - name: Create comment
+        uses: peter-evans/create-or-update-comment@46da6c0d98504aed6fc429519a258b951f23f474
+        if: ${{ (hashFiles('output/comment.md') != '') && fromJSON(env.write-comments ) && (env.COMMENT_ID == '') }}
+        with:
+          issue-number: ${{ github.event.number }}
+          body-path: 'output/comment.md'
+          edit-mode: replace
+
+      - name: Update comment
+        uses: peter-evans/create-or-update-comment@46da6c0d98504aed6fc429519a258b951f23f474
+        if: ${{ (hashFiles('output/comment.md') != '') && fromJSON(env.write-comments ) && (env.COMMENT_ID != '') }}
+        with:
+          comment-id: ${{ env.COMMENT_ID }}
+          body-path: 'output/comment.md'
+          edit-mode: replace
+
       - name: Save PR number
+        if: ${{ !fromJSON(env.write-comments ) }}
         run: |
           mkdir -p output/ && echo ${{ github.event.number }} > output/issueNumber
 
       - name: Upload folder with number and markdown
+        if: ${{ !fromJSON(env.write-comments ) }}
         uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05
         with:
           name: output
diff --git a/pkgs/firehose/README.md b/pkgs/firehose/README.md
index 5125396..51e5304 100644
--- a/pkgs/firehose/README.md
+++ b/pkgs/firehose/README.md
@@ -79,6 +79,34 @@
     uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
 ```
 
+#### Enabling comments on forks
+
+- add the following to your `publish.yaml`:
+```yaml
+with:
+       write-comments: false
+``` 
+- copy the yaml below into a `.github/workflows/post_summaries.yaml` file in your repo
+
+```yaml
+# A CI configuration to write comments on PRs.
+
+name: Comment on the pull request
+
+on:
+  workflow_run:
+    workflows: 
+      - Publish
+    types:
+      - completed
+
+jobs:
+  upload:
+    uses: dart-lang/ecosystem/.github/workflows/post_summaries.yaml@main
+    permissions:
+      pull-requests: write
+```
+
 ### Publishing from a specific version of the SDK
 
 Callers may optionally specify the version of the SDK to use when publishing a