Skip to content

Commit

Permalink
support an 'publish-ignore-warnings' label (#77)
Browse files Browse the repository at this point in the history
* support an 'publish-ignore-warnings' label

* make the 'use label' message more prominent

* remove warning
  • Loading branch information
devoncarew authored Feb 28, 2023
1 parent 1704fa1 commit b4b1c68
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish_internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]+' ]

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions pkgs/firehose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]+' ]

Expand Down
27 changes: 17 additions & 10 deletions pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 |';
Expand All @@ -303,22 +310,22 @@ 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);

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';
Expand Down
9 changes: 9 additions & 0 deletions pkgs/firehose/lib/src/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Github {
/// The PR (or issue) number.
String? get issueNumber => _env['ISSUE_NUMBER'];

/// Any labels applied to this PR.
List<String> get prLabels =>
_env.containsKey('PR_LABELS') ? _env['PR_LABELS']!.split(',') : [];

/// The commit SHA that triggered the workflow.
String? get sha => _env['GITHUB_SHA'];

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit b4b1c68

Please sign in to comment.