From 3e4f2866d49c2448e44f51112956a689a2e50cd6 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 8 Feb 2024 09:31:42 +0100 Subject: [PATCH] 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 --- .github/workflows/post_summaries.yaml | 2 +- .github/workflows/publish.yaml | 30 +++++++++- .github/workflows/publish_internal.yaml | 76 ++---------------------- pkgs/firehose/CHANGELOG.md | 4 ++ pkgs/firehose/bin/firehose.dart | 11 +++- pkgs/firehose/lib/firehose.dart | 8 +-- pkgs/firehose/lib/src/health/health.dart | 2 +- pkgs/firehose/pubspec.yaml | 2 +- 8 files changed, 55 insertions(+), 80 deletions(-) diff --git a/.github/workflows/post_summaries.yaml b/.github/workflows/post_summaries.yaml index a0f3c673..4928c891 100644 --- a/.github/workflows/post_summaries.yaml +++ b/.github/workflows/post_summaries.yaml @@ -6,7 +6,7 @@ on: 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 106d24c0..aedae9d3 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -46,6 +46,15 @@ name: Publish # 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 @@ on: 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 @@ jobs: - 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 991ce717..514977ad 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 ca3a4010..d8da3b02 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 d496bc1b..65d00005 100644 --- a/pkgs/firehose/bin/firehose.dart +++ b/pkgs/firehose/bin/firehose.dart @@ -7,6 +7,7 @@ import 'dart:io'; 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 @@ void main(List arguments) async { 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) + .where((pattern) => pattern.isNotEmpty) + .map((pattern) => Glob(pattern, recursive: true)) + .toList(); if (!validate && !publish) { _usage(argParser, @@ -41,7 +46,7 @@ void main(List arguments) async { exit(1); } - final firehose = Firehose(Directory.current, useFlutter); + final firehose = Firehose(Directory.current, useFlutter, ignoredPackages); if (validate) { await firehose.validate(); @@ -88,5 +93,9 @@ ArgParser _createArgs() { 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 3f4ce73e..5c702f6c 100644 --- a/pkgs/firehose/lib/firehose.dart +++ b/pkgs/firehose/lib/firehose.dart @@ -25,8 +25,9 @@ const String _ignoreWarningsLabel = 'publish-ignore-warnings'; class Firehose { final Directory directory; final bool useFlutter; + final List ignoredPackages; - Firehose(this.directory, this.useFlutter); + Firehose(this.directory, this.useFlutter, this.ignoredPackages); /// Validate the packages in the repository. /// @@ -92,10 +93,7 @@ Saving existing comment id $existingCommentId to file ${idFile.path}'''); github.close(); } - Future verify( - GithubApi github, [ - List ignoredPackages = const [], - ]) async { + Future 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 47baf974..264f3589 100644 --- a/pkgs/firehose/lib/src/health/health.dart +++ b/pkgs/firehose/lib/src/health/health.dart @@ -146,7 +146,7 @@ class Health { Future 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 8c064218..baacac6c 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: