From d3699aa6093e01ecf2dadbc3c42174aa8aafd268 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Mon, 11 May 2026 06:49:35 -0700 Subject: [PATCH] chore(shorebird_ci): make package cleanly publishable (#3753) --- packages/shorebird_ci/analysis_options.yaml | 12 +++- packages/shorebird_ci/example/README.md | 36 ++++++++++ .../shorebird_ci/example/shorebird_ci.yaml | 65 +++++++++++++++++++ packages/shorebird_ci/lib/src/codecov.dart | 2 +- packages/shorebird_ci/lib/src/cspell.dart | 2 +- packages/shorebird_ci/pubspec.yaml | 4 ++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 packages/shorebird_ci/example/README.md create mode 100644 packages/shorebird_ci/example/shorebird_ci.yaml diff --git a/packages/shorebird_ci/analysis_options.yaml b/packages/shorebird_ci/analysis_options.yaml index f04c6cf0..da3e8510 100644 --- a/packages/shorebird_ci/analysis_options.yaml +++ b/packages/shorebird_ci/analysis_options.yaml @@ -1 +1,11 @@ -include: ../../analysis_options.yaml +# Self-contained (does NOT `include: ../../analysis_options.yaml`). +# Reason: pub publish uploads only this package, and pana scores it +# in an isolated copy. A relative include of the workspace-root file +# is unresolvable in those environments, which causes dart_style to +# silently drop the `formatter:` block and reformat against defaults. +# Keeping the formatter config local to the package guarantees the +# same formatting behavior here, in CI, in pana, and on pub.dev. +include: package:very_good_analysis/analysis_options.10.0.0.yaml +formatter: + page_width: 80 + trailing_commas: preserve diff --git a/packages/shorebird_ci/example/README.md b/packages/shorebird_ci/example/README.md new file mode 100644 index 00000000..7aaca627 --- /dev/null +++ b/packages/shorebird_ci/example/README.md @@ -0,0 +1,36 @@ +# Example + +`shorebird_ci.yaml` is the workflow `shorebird_ci generate` produces for +a minimal Dart workspace with two packages — `app` (depends on `core`) +and `core`: + +``` +my_repo/ + pubspec.yaml # workspace root + packages/ + app/pubspec.yaml # depends on core + core/pubspec.yaml +``` + +Reproduce it with: + +```sh +dart pub global activate shorebird_ci +shorebird_ci generate --repo-root . --dry-run +``` + +The workflow has two jobs. `setup` activates `shorebird_ci` on the +runner, calls `verify` to fail fast if CI coverage has drifted from the +dep graph, then calls `affected_packages` to emit the JSON matrix. +`dart_ci` fans out across that matrix, running format / analyze / test +for each affected package — including transitive dependents (a change +to `core` runs `app` too). + +For Flutter packages a parallel `flutter_ci` job is added, with +`flutter_version` resolved from the pubspec when pinned. With codecov +configured, coverage upload steps are added. With a cspell config +present, a `cspell` job is added. None of those apply to this minimal +example. + +See the package README for the static (`--style static`) variant and +other options. diff --git a/packages/shorebird_ci/example/shorebird_ci.yaml b/packages/shorebird_ci/example/shorebird_ci.yaml new file mode 100644 index 00000000..82fbc512 --- /dev/null +++ b/packages/shorebird_ci/example/shorebird_ci.yaml @@ -0,0 +1,65 @@ +# Generated by shorebird_ci. Safe to edit. +# Run `shorebird_ci verify` to check for dep graph drift. +# shorebird_ci-managed: dynamic +name: Shorebird CI + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + setup: + runs-on: ubuntu-latest + outputs: + dart_packages: ${{ steps.affected.outputs.dart_packages }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: dart-lang/setup-dart@v1 + - run: dart pub global activate shorebird_ci + # Verify first so we fail fast if CI coverage is broken and + # don't waste time computing affected packages. + - name: Verify CI coverage + run: shorebird_ci verify + - id: affected + run: | + DART=$(shorebird_ci affected_packages --sdk dart) + echo "dart_packages=$DART" >> $GITHUB_OUTPUT + + dart_ci: + needs: setup + if: needs.setup.outputs.dart_packages != '[]' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{ fromJSON(needs.setup.outputs.dart_packages) }} + name: ${{ matrix.name }} + defaults: + run: + working-directory: ${{ matrix.path }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: dart-lang/setup-dart@v1 + - name: Setup Bloc Tools + if: matrix.has_bloc_lint == true + uses: felangel/setup-bloc-tools@v0 + - name: Install Dependencies + run: | + dart pub get --no-example + for sub in ${{ matrix.subpackages }}; do + dart pub get --no-example -C $sub + done + - run: dart format --set-exit-if-changed . + - run: dart analyze . + - name: Bloc Lint + if: matrix.has_bloc_lint == true + run: bloc lint . + - run: dart test diff --git a/packages/shorebird_ci/lib/src/codecov.dart b/packages/shorebird_ci/lib/src/codecov.dart index 2e1383d1..e01ee906 100644 --- a/packages/shorebird_ci/lib/src/codecov.dart +++ b/packages/shorebird_ci/lib/src/codecov.dart @@ -3,7 +3,7 @@ import 'package:path/path.dart' as p; /// Candidate paths for codecov config files. /// /// See https://docs.codecov.com/docs/codecov-yaml#can-i-name-the-file-codecovyml -final codecovFileNames = { +final codecovFileNames = { 'codecov.yml', '.codecov.yml', p.join('.github', 'codecov.yml'), diff --git a/packages/shorebird_ci/lib/src/cspell.dart b/packages/shorebird_ci/lib/src/cspell.dart index f52eed51..72587585 100644 --- a/packages/shorebird_ci/lib/src/cspell.dart +++ b/packages/shorebird_ci/lib/src/cspell.dart @@ -3,7 +3,7 @@ import 'package:path/path.dart' as p; /// Candidate paths for cSpell config files. /// /// See https://cspell.org/docs/getting-started#1-create-a-configuration-file -final cSpellConfigFileNames = { +final cSpellConfigFileNames = { '.cspell.json', 'cspell.json', '.cSpell.json', diff --git a/packages/shorebird_ci/pubspec.yaml b/packages/shorebird_ci/pubspec.yaml index 42e46692..7da73550 100644 --- a/packages/shorebird_ci/pubspec.yaml +++ b/packages/shorebird_ci/pubspec.yaml @@ -9,6 +9,9 @@ repository: https://github.com/shorebirdtech/shorebird/tree/main/packages/shoreb topics: [ci, github-actions, monorepo, shorebird] resolution: workspace +executables: + shorebird_ci: + environment: sdk: ^3.9.0 @@ -21,3 +24,4 @@ dependencies: dev_dependencies: test: ^1.31.1 + very_good_analysis: ^10.2.0