Skip to content

refactor(repo): use diff to only run commands for changes #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions .github/workflows/legacy_version_analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ on:
push:
branches:
- master
paths:
- 'packages/**'
- '.github/workflows/legacy_version_analyze.yml'
pull_request:
branches:
- master
paths:
- 'packages/**'
- '.github/workflows/legacy_version_analyze.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -34,38 +28,26 @@ jobs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: "Git Checkout"
- name: 📚 Git Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Install Flutter"
- name: 🎯 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter_version }}
channel: stable
cache: true
channel: stable
flutter-version: ${{ env.flutter_version }}
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}

- name: "Install Tools"
- name: 📦 Install Tools
run: flutter pub global activate melos

- name: "Bootstrap Workspace"
run: melos bootstrap --verbose

# Only analyze lib/; non-client code doesn't need to work on
# all supported legacy version.
- name: "Stream Chat Analyze"
run: cd packages/stream_chat/lib && dart analyze --fatal-infos .

- name: "Stream Chat Flutter Core Analyze"
run: cd packages/stream_chat_flutter_core/lib && dart analyze --fatal-infos .

- name: "Stream Chat Flutter Analyze"
run: cd packages/stream_chat_flutter/lib && dart analyze --fatal-infos .

- name: "Stream Chat Persistence Analyze"
run: cd packages/stream_chat_persistence/lib && dart analyze --fatal-infos .
- name: ⚙️ Bootstrap Workspace
run: melos bootstrap

- name: "Stream Chat Localizations Analyze"
run: cd packages/stream_chat_localizations/lib && dart analyze --fatal-infos .
- name: 🕵️ Analyze
# Only analyze lib/; non-client code doesn't need to work on
# all supported legacy version.
run: melos exec -c 1 --diff=origin/master...HEAD --include-dependents -- "dart analyze lib --fatal-infos"
1 change: 1 addition & 0 deletions .github/workflows/pr_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
doc
repo
localization
sample_app
requireScope: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
131 changes: 52 additions & 79 deletions .github/workflows/stream_flutter_workflow.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: stream_flutter_workflow

env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
# Note: The versions below should be manually updated after a new major
# version comes out.
flutter_version: "3.x"

on:
pull_request:
paths:
- 'packages/**'
- '.github/workflows/stream_flutter_workflow.yml'
types:
- opened
- reopened
Expand All @@ -23,127 +21,102 @@ concurrency:
cancel-in-progress: true

jobs:
analyze:
timeout-minutes: 15
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: "Git Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Install Flutter"
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter_version }}
channel: stable
cache: true
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
- name: "Install Tools"
run: |
flutter pub global activate melos
- name: "Bootstrap Workspace"
run: melos bootstrap --verbose
- name: "Dart Analyze"
run: |
melos run analyze
- name: "Pub Check"
if: github.base_ref == 'master'
run: |
melos run lint:pub

format:
lint:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
timeout-minutes: 15
steps:
- name: "Git Checkout"
- name: 📚 Git Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Install Flutter"

- name: 🎯 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter_version }}
channel: stable
cache: true
channel: stable
flutter-version: ${{ env.flutter_version }}
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
- name: "Install Tools"
run: |
flutter pub global activate melos
- name: "Bootstrap Workspace"

- name: 📦 Install Tools
run: flutter pub global activate melos

- name: ⚙️ Bootstrap Workspace
run: melos bootstrap
- name: "Melos Format"
run: melos run format
- name: "Validate Formatting"
run: |
./.github/workflows/scripts/validate-formatting.sh

- name: ✨ Check Formatting
run: melos run format:changes

- name: 🕵️ Analyze
run: melos run analyze:changes

- if: github.base_ref == 'master'
name: 🚀 Pub Check
run: melos run publish:dry-run:changes

test:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
timeout-minutes: 30
steps:
- name: "Git Checkout"
- name: 📚 Git Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Install Flutter"

- name: 🎯 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter_version }}
channel: stable
cache: true
channel: stable
flutter-version: ${{ env.flutter_version }}
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
# This step is needed due to https://github.com/actions/runner-images/issues/11279
- name: Install SQLite3
run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev
- name: "Install Tools"

- name: 📦 Install Tools
run: |
flutter pub global activate melos
flutter pub global activate remove_from_coverage
- name: "Bootstrap Workspace"

- name: ⚙️ Bootstrap Workspace
run: melos bootstrap
- name: "Flutter Test"
run: melos run test:all
- name: "Collect Coverage"

- name: 🧪 Run Tests
run: melos run test:changes

- name: 📊 Collect Coverage
run: melos run coverage:ignore-file --no-select
- name: "Upload Coverage"
uses: codecov/codecov-action@v5
with:
token: ${{secrets.CODECOV_TOKEN}}
files: packages/*/coverage/lcov.info
- name: "Stream Chat Coverage Check"

- name: ✅ Stream Chat Coverage Check
uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat/coverage/lcov.info
min_coverage: 70
- name: "Stream Chat Localizations Coverage Check"

- name: ✅ Stream Chat Localizations Coverage Check
uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_localizations/coverage/lcov.info
min_coverage: 100
- name: "Stream Chat Persistence Coverage Check"

- name: ✅ Stream Chat Persistence Coverage Check
uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_persistence/coverage/lcov.info
min_coverage: 95
- name: "Stream Chat Flutter Core Coverage Check"

- name: ✅ Stream Chat Flutter Core Coverage Check
uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_flutter_core/coverage/lcov.info
min_coverage: 30
- name: "Stream Chat Flutter Coverage Check"

- name: ✅ Stream Chat Flutter Coverage Check
uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_flutter/coverage/lcov.info
min_coverage: 44

draft-build:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == true
timeout-minutes: 1

steps:
- name: Run a one-line script
run: echo Draft PR, you are good.
- name: 📁 Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{secrets.CODECOV_TOKEN}}
files: packages/*/coverage/lcov.info
50 changes: 23 additions & 27 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,31 @@ scripts:
run: melos run analyze && melos run format
description: Run all static analysis checks

analyze:all:
run: melos run analyze && melos run metrics
description: Run all

analyze:
run: |
melos exec -c 5 --ignore="*example*" -- \
dart analyze --fatal-infos .
description: |
Run `dart analyze` in all packages.
- Note: you can also rely on your IDEs Dart Analysis / Issues window.
run: melos exec -c 5 --ignore="*example*" -- "dart analyze --fatal-infos ."
description: Run `dart analyze` in all packages.

analyze:changes:
run: melos exec -c 1 --diff=origin/master...HEAD --include-dependents -- "dart analyze --fatal-infos ."
description: Run `dart analyze` in all changed packages.

format:
run: dart format --set-exit-if-changed .
description: |
Run `dart format --set-exit-if-changed .` in all packages.
description: Run `dart format --set-exit-if-changed .` in all packages.

metrics:
run: |
melos exec -c 1 --ignore="*example*" -- \
flutter pub run dart_code_metrics:metrics analyze lib
description: |
Run `dart_code_metrics` in all packages.
- Note: you can also rely on your IDEs Dart Analysis / Issues window.
format:changes:
run: melos exec -c 1 --diff=origin/master...HEAD --include-dependents -- "dart format --set-exit-if-changed ."
description: Run `dart format` in all changed packages.

lint:pub:
run: |
melos exec -c 5 --no-private --ignore="*example*" -- \
flutter pub publish --dry-run
description: |
Run `pub publish --dry-run` in all packages.
- Note: you can also rely on your IDEs Dart Analysis / Issues window.
run: melos exec -c 5 --no-private --ignore="*example*" -- "flutter pub publish --dry-run"
description: Run `pub publish --dry-run` in all packages.

publish:dry-run:changes:
run: >-
melos exec -c 1 --diff=origin/master...HEAD --no-private --include-dependents --
"[ -f pubspec.yaml ] && ! grep -q 'publish_to: none' pubspec.yaml && flutter pub publish --dry-run || echo 'Package not publishable, skipping'"
description: Run `flutter pub publish --dry-run` in all changed packages.

generate:all:
run: melos run generate:dart && melos run generate:flutter
Expand Down Expand Up @@ -182,6 +175,10 @@ scripts:
flutter: true
dirExists: test

test:changes:
run: melos exec -c 1 --diff=origin/master...HEAD --include-dependents -- "[ -d test ] && flutter test --no-pub --coverage || echo 'No tests found, skipping'"
description: Run `flutter test` in all changed packages.

update:goldens:
run: melos exec -c 1 --depends-on="alchemist" -- "flutter test --tags golden --update-goldens"
description: Update golden files for all packages in this project.
Expand All @@ -193,8 +190,7 @@ scripts:
flutter: true

coverage:ignore-file:
run: |
melos exec -c 5 --fail-fast -- "\$MELOS_ROOT_PATH/.github/workflows/scripts/remove-from-coverage.sh"
run: melos exec -c 1 --fail-fast -- "\$MELOS_ROOT_PATH/.github/workflows/scripts/remove-from-coverage.sh"
description: Removes all the ignored files from the coverage report.
packageFilters:
dirExists: coverage
2 changes: 1 addition & 1 deletion packages/stream_chat/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: stream_chat_example
description: A new Flutter project.

publish_to: "none"
publish_to: none
version: 1.0.0+1

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: stream_chat_flutter_example
description: A new Flutter project.
publish_to: 'none'
publish_to: none
version: 1.0.0+1

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_flutter_core/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: stream_chat_flutter_core_example
description: Example app for testing stream_chat_flutter_core
publish_to: 'none'
publish_to: none
version: 1.0.0+1

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_localizations/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: stream_chat_localizations_example
description: A new Flutter project.

publish_to: 'none'
publish_to: none
version: 1.0.0+1

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_persistence/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: stream_chat_persistence_example
description: A new Flutter project.
publish_to: 'none'
publish_to: none
version: 1.0.0+1

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down
2 changes: 1 addition & 1 deletion sample_app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sample_app
description: A new Flutter project.
publish_to: "none"
publish_to: none
version: 2.2.0

# Note: The environment configuration and dependency versions are managed by Melos.
Expand Down