From b4b1c68400eeaddf2ff2a7f9c884987fd58342d3 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 27 Feb 2023 18:45:34 -0800 Subject: [PATCH] support an 'publish-ignore-warnings' label (#77) * support an 'publish-ignore-warnings' label * make the 'use label' message more prominent * remove warning --- .github/workflows/publish.yaml | 2 ++ .github/workflows/publish_internal.yaml | 2 ++ pkgs/firehose/CHANGELOG.md | 6 +++++- pkgs/firehose/README.md | 1 + pkgs/firehose/lib/firehose.dart | 27 ++++++++++++++++--------- pkgs/firehose/lib/src/github.dart | 9 +++++++++ pkgs/firehose/pubspec.yaml | 2 +- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index d7a35cba..c2a5445c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -8,6 +8,7 @@ name: Publish # on: # pull_request: # branches: [ main ] +# types: [opened, synchronize, reopened, labeled, unlabeled] # push: # tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] # jobs: @@ -61,6 +62,7 @@ jobs: 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 - name: Publish packages diff --git a/.github/workflows/publish_internal.yaml b/.github/workflows/publish_internal.yaml index 20f959dc..051b2b62 100644 --- a/.github/workflows/publish_internal.yaml +++ b/.github/workflows/publish_internal.yaml @@ -8,6 +8,7 @@ name: Publish on: pull_request: branches: [ main ] + types: [opened, synchronize, reopened, labeled, unlabeled] push: tags: [ '[A-z]+-v[0-9]+.[0-9]+.[0-9]+' ] @@ -35,6 +36,7 @@ jobs: 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 - name: Publish tagged package diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index cc36d56d..c160ad39 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,8 +1,12 @@ -## 0.3.14-dev +## 0.3.14 - Require Dart `2.19.0`. - Adjust docs for the recommended tag format to use to trigger publishing (support semver release versions, not pre-release versions). +- Support using a `publish-ignore-warnings` label to ignore `dart pub publish` + dry-run validation failures. +- Update the recommended publish.yaml file to listen for label changes on PRs + (`types: ...`). ## 0.3.13 diff --git a/pkgs/firehose/README.md b/pkgs/firehose/README.md index 7ba5587d..e923f9f6 100644 --- a/pkgs/firehose/README.md +++ b/pkgs/firehose/README.md @@ -69,6 +69,7 @@ name: Publish on: pull_request: branches: [ main ] + types: [opened, synchronize, reopened, labeled, unlabeled] push: tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] diff --git a/pkgs/firehose/lib/firehose.dart b/pkgs/firehose/lib/firehose.dart index 278aeea7..7bf82c36 100644 --- a/pkgs/firehose/lib/firehose.dart +++ b/pkgs/firehose/lib/firehose.dart @@ -16,6 +16,8 @@ const String _githubActionsUser = 'github-actions[bot]'; const String _publishBotTag = '## Package publishing'; +const String _ignoreWarningsLabel = 'publish-ignore-warnings'; + class Firehose { final Directory directory; @@ -153,12 +155,17 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati } else { var code = await runCommand('dart', args: ['pub', 'publish', '--dry-run'], cwd: package.directory); - if (code != 0) { + + final ignoreWarnings = github.prLabels.contains(_ignoreWarningsLabel); + + if (code != 0 && !ignoreWarnings) { exitCode = code; - results.addResult(Result.fail(package, 'pub publish dry-run failed')); + var message = + 'pub publish dry-run failed; add the `$_ignoreWarningsLabel` ' + 'label to ignore'; + github.notice(message: message); + results.addResult(Result.fail(package, message)); } else { - print('No issues found.'); - var result = Result.success(package, '**ready to publish** (merge and tag to publish)', repoTag); print(result); @@ -291,7 +298,7 @@ class VerificationResults { return results.map((r) { var sev = r.severity == Severity.error ? '(error) ' : ''; - var tag = r.other == null ? '' : '`${r.other}`'; + var tag = r.gitTag == null ? '' : '`${r.gitTag}`'; return '| package:${r.package.name} | ${r.package.version} | ' '$sev${r.message} | $tag |'; @@ -303,9 +310,9 @@ class Result { final Severity severity; final Package package; final String message; - final String? other; + final String? gitTag; - Result(this.severity, this.package, this.message, [this.other]); + Result(this.severity, this.package, this.message, [this.gitTag]); factory Result.fail(Package package, String message) => Result(Severity.error, package, message); @@ -313,12 +320,12 @@ class Result { factory Result.info(Package package, String message) => Result(Severity.info, package, message); - factory Result.success(Package package, String message, [String? other]) => - Result(Severity.success, package, message, other); + factory Result.success(Package package, String message, [String? gitTag]) => + Result(Severity.success, package, message, gitTag); @override String toString() { - final details = other == null ? '' : ' ($other)'; + final details = gitTag == null ? '' : ' ($gitTag)'; return severity == Severity.error ? 'error: $message$details' : '$message$details'; diff --git a/pkgs/firehose/lib/src/github.dart b/pkgs/firehose/lib/src/github.dart index bae622f1..822d5e20 100644 --- a/pkgs/firehose/lib/src/github.dart +++ b/pkgs/firehose/lib/src/github.dart @@ -27,6 +27,10 @@ class Github { /// The PR (or issue) number. String? get issueNumber => _env['ISSUE_NUMBER']; + /// Any labels applied to this PR. + List get prLabels => + _env.containsKey('PR_LABELS') ? _env['PR_LABELS']!.split(',') : []; + /// The commit SHA that triggered the workflow. String? get sha => _env['GITHUB_SHA']; @@ -191,6 +195,11 @@ class Github { void close() { _httpClient?.close(); } + + /// Write a notice message to the github log. + void notice({required String message}) { + print('::notice ::$message'); + } } class RpcException implements Exception { diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index fecaa058..7a5ad635 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.14-dev +version: 0.3.14 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose environment: