Add ignore flag for `publish.yaml` (#237)

* Add ignore flag for `publish.yaml`

* Add local debug of publish

* Fix path

* Add multiline

* Add ignore-packages option

* Comment on workflows

* Rev version

* Add documentation
diff --git a/.github/workflows/post_summaries.yaml b/.github/workflows/post_summaries.yaml
index a0f3c67..4928c89 100644
--- a/.github/workflows/post_summaries.yaml
+++ b/.github/workflows/post_summaries.yaml
@@ -6,7 +6,7 @@
   workflow_call:
   workflow_run:
     workflows:
-      - Publish
+      - Publish:Internal
       - Health:Internal
     types:
       - completed
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
index 106d24c..aedae9d 100644
--- a/.github/workflows/publish.yaml
+++ b/.github/workflows/publish.yaml
@@ -46,6 +46,15 @@
 #     with:
 #       write-comments: false
 
+# It is also possible to ignore certain packages in the repository 
+# via a glob.
+#
+# jobs:
+#   publish:
+#     uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
+#     with:
+#       ignore-packages: pkgs/non-published-package
+
 on:
   workflow_call:
     inputs:
@@ -83,6 +92,16 @@
         default: false
         required: false
         type: boolean
+      ignore-packages:
+        description: Which packages to ignore.
+        default: "\"\""
+        required: false
+        type: string
+      local_debug:
+        description: Whether to use a local copy of package:firehose - only for debug
+        default: false
+        type: boolean
+        required: false
 
 jobs:
   # Note that this job does not require the specified environment.
@@ -113,13 +132,22 @@
 
       - name: Install firehose
         run: dart pub global activate firehose
+        if:  ${{ !inputs.local_debug }}
 
+      - name: Install local firehose
+        run: dart pub global activate --source path pkgs/firehose/
+        if:  ${{ inputs.local_debug }} 
+        
       - name: Validate packages
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           ISSUE_NUMBER: ${{ github.event.number }}
           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] }}
+        run: |
+             dart pub global run firehose \
+               --validate \
+               ${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[inputs.use-flutter] }} \
+               --ignore-packages ${{ inputs.ignore-packages }}
 
       - name: Get comment id
         if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments }}
diff --git a/.github/workflows/publish_internal.yaml b/.github/workflows/publish_internal.yaml
index 991ce71..514977a 100644
--- a/.github/workflows/publish_internal.yaml
+++ b/.github/workflows/publish_internal.yaml
@@ -3,81 +3,17 @@
 # We don't use the regular publish.yaml script here in order to dogfood the
 # publishing code at head.
 
-name: Publish
-
+name: Publish:Internal
 on:
   pull_request:
     branches: [ main ]
     types: [opened, synchronize, reopened, labeled, unlabeled]
   push:
     tags: [ '[A-z]+-v[0-9]+.[0-9]+.[0-9]+*' ]
-
-env:
-  use-flutter: false
-  write-comments: false
-
 jobs:
   publish:
-    if: github.repository_owner == 'dart-lang'
-
-    # These permissions are required for authentication using OIDC and to enable
-    # us to create comments on PRs.
-    permissions:
-      id-token: write
-      pull-requests: write
-
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
-      - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
-
-      - name: Pub get
-        working-directory: pkgs/firehose
-        run: dart pub get
-
-      - name: Validate packages
-        if: ${{ github.event_name == 'pull_request' }}
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-          ISSUE_NUMBER: ${{ github.event.number }}
-          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@3509deb8e3e0d7847ba5297bcac581b636533971
-        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@3509deb8e3e0d7847ba5297bcac581b636533971
-        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@c7d193f32edcb7bfad88892161225aeda64e9392
-        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] }}
+    uses: ./.github/workflows/publish.yaml
+    with:
+      local_debug: true
+      use-flutter: false
+      write-comments: false
diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md
index ca3a401..d8da3b0 100644
--- a/pkgs/firehose/CHANGELOG.md
+++ b/pkgs/firehose/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.7.0
+
+- Add `ignore-packages` flag to the publish workflow.
+
 ## 0.6.1
 
 - Add `ignore` flags to the health workflow.
diff --git a/pkgs/firehose/bin/firehose.dart b/pkgs/firehose/bin/firehose.dart
index d496bc1..65d0000 100644
--- a/pkgs/firehose/bin/firehose.dart
+++ b/pkgs/firehose/bin/firehose.dart
@@ -7,6 +7,7 @@
 import 'package:args/args.dart';
 import 'package:firehose/firehose.dart';
 import 'package:firehose/src/github.dart';
+import 'package:glob/glob.dart';
 
 const helpFlag = 'help';
 const validateFlag = 'validate';
@@ -26,6 +27,10 @@
     final validate = argResults[validateFlag] as bool;
     final publish = argResults[publishFlag] as bool;
     final useFlutter = argResults[useFlutterFlag] as bool;
+    final ignoredPackages = (argResults['ignore-packages'] as List<String>)
+        .where((pattern) => pattern.isNotEmpty)
+        .map((pattern) => Glob(pattern, recursive: true))
+        .toList();
 
     if (!validate && !publish) {
       _usage(argParser,
@@ -41,7 +46,7 @@
       exit(1);
     }
 
-    final firehose = Firehose(Directory.current, useFlutter);
+    final firehose = Firehose(Directory.current, useFlutter, ignoredPackages);
 
     if (validate) {
       await firehose.validate();
@@ -88,5 +93,9 @@
       useFlutterFlag,
       negatable: true,
       help: 'Whether this is a Flutter project.',
+    )
+    ..addMultiOption(
+      'ignore-packages',
+      help: 'Which packages to ignore.',
     );
 }
diff --git a/pkgs/firehose/lib/firehose.dart b/pkgs/firehose/lib/firehose.dart
index 3f4ce73..5c702f6 100644
--- a/pkgs/firehose/lib/firehose.dart
+++ b/pkgs/firehose/lib/firehose.dart
@@ -25,8 +25,9 @@
 class Firehose {
   final Directory directory;
   final bool useFlutter;
+  final List<Glob> ignoredPackages;
 
-  Firehose(this.directory, this.useFlutter);
+  Firehose(this.directory, this.useFlutter, this.ignoredPackages);
 
   /// Validate the packages in the repository.
   ///
@@ -92,10 +93,7 @@
     github.close();
   }
 
-  Future<VerificationResults> verify(
-    GithubApi github, [
-    List<Glob> ignoredPackages = const [],
-  ]) async {
+  Future<VerificationResults> verify(GithubApi github) async {
     var repo = Repository(directory);
     var packages = repo.locatePackages(ignoredPackages);
 
diff --git a/pkgs/firehose/lib/src/health/health.dart b/pkgs/firehose/lib/src/health/health.dart
index 47baf97..264f358 100644
--- a/pkgs/firehose/lib/src/health/health.dart
+++ b/pkgs/firehose/lib/src/health/health.dart
@@ -146,7 +146,7 @@
   Future<HealthCheckResult> validateCheck() async {
     //TODO: Add Flutter support for PR health checks
     var results =
-        await Firehose(directory, false).verify(github, ignoredPackages);
+        await Firehose(directory, false, ignoredPackages).verify(github);
 
     var markdownTable = '''
 | Package | Version | Status |
diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml
index 8c06421..baacac6 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.6.1
+version: 0.7.0
 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose
 
 environment: