Skip to content

Commit

Permalink
Add ignore flag for publish.yaml (#237)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mosuem authored Feb 8, 2024
1 parent 7d8ec47 commit 3e4f286
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/post_summaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_call:
workflow_run:
workflows:
- Publish
- Publish:Internal
- Health:Internal
types:
- completed
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 }}
Expand Down
76 changes: 6 additions & 70 deletions .github/workflows/publish_internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 10 additions & 1 deletion pkgs/firehose/bin/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,6 +27,10 @@ void main(List<String> 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<String>)
.where((pattern) => pattern.isNotEmpty)
.map((pattern) => Glob(pattern, recursive: true))
.toList();

if (!validate && !publish) {
_usage(argParser,
Expand All @@ -41,7 +46,7 @@ void main(List<String> arguments) async {
exit(1);
}

final firehose = Firehose(Directory.current, useFlutter);
final firehose = Firehose(Directory.current, useFlutter, ignoredPackages);

if (validate) {
await firehose.validate();
Expand Down Expand Up @@ -88,5 +93,9 @@ ArgParser _createArgs() {
useFlutterFlag,
negatable: true,
help: 'Whether this is a Flutter project.',
)
..addMultiOption(
'ignore-packages',
help: 'Which packages to ignore.',
);
}
8 changes: 3 additions & 5 deletions pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const String _ignoreWarningsLabel = 'publish-ignore-warnings';
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.
///
Expand Down Expand Up @@ -92,10 +93,7 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
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);

Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/lib/src/health/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Health {
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 |
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.6.1
version: 0.7.0
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down

0 comments on commit 3e4f286

Please sign in to comment.