Skip to content
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

Add golden test and update CI pipelines #1

Merged
merged 2 commits into from
Apr 19, 2024
Merged
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
59 changes: 38 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
FLUTTER_VERSION: "3.19.5"

jobs:
ci:
full_CI:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
Expand All @@ -28,12 +28,15 @@ jobs:
uses: bluefireteam/melos-action@v3

- name: Run analyzer
run: melos analyze
run: melos run analyze

- name: Check formatting of Dart files
run: melos format_check
run: melos run format_check

ci_on_diff:
- name: Run golden tests
run: melos run test_golden

selective_CI:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
Expand All @@ -51,13 +54,33 @@ jobs:
- name: Set up Melos
uses: bluefireteam/melos-action@v3

- name: Run analyzer with Git Diff
run: melos analyze_diff
- name: Set MELOS_PACKAGES filter with packages names that are affected by the Git Diff
run: |
changeAffectedPackages=$(melos list --diff=origin/main...HEAD --include-dependents)
if [[ $changeAffectedPackages == *"No package"* ]]; then
echo "MELOS_PACKAGES=dummy_value_to_filter_out_all_packages" >> $GITHUB_ENV
else
echo "MELOS_PACKAGES=$(echo "$changeAffectedPackages" | paste -sd ',' -)" >> $GITHUB_ENV
fi

- name: Check formatting of Dart files with Git Diff
run: melos format_check_diff
- name: Print MELOS_PACKAGES global scope
run: |
echo "The Melos global scope is: $MELOS_PACKAGES"
echo "It'll be used as a global filter for the remaining Melos scripts in the pipeline!"

- name: Run analyzer with Git Diff using MELOS_PACKAGES
run: melos run analyze

- name: Check formatting of Dart files with Git Diff using MELOS_PACKAGES
run: melos run format_check

ci_on_diff_alternative:
- name: Run golden tests with Git Diff using MELOS_PACKAGES
run: melos run test_golden

# This Melos filtering approach will not work as intended until the following
# feature is implemented https://github.com/invertase/melos/pull/702.
selective_CI_alternative:
if: false
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
Expand All @@ -75,17 +98,11 @@ jobs:
- name: Set up Melos
uses: bluefireteam/melos-action@v3

- name: Set MELOS_PACKAGES filter with packages names that are affected by the Git Diff
run: |
changeAffectedPackages=$(melos list --diff=origin/main...HEAD --include-dependents)
if [[ $changeAffectedPackages == *"No package"* ]]; then
echo "MELOS_PACKAGES=dummy_value_to_filter_out_all_packages" >> $GITHUB_ENV
else
echo "MELOS_PACKAGES=$(echo "$changeAffectedPackages" | paste -sd ',' -)" >> $GITHUB_ENV
fi
- name: Run analyzer with Git Diff
run: melos run analyze_diff

- name: Run analyzer
run: melos analyze
- name: Check formatting of Dart files with Git Diff
run: melos run format_check_diff

- name: Check formatting of Dart files
run: melos format_check
- name: Run golden tests with Git Diff
run: melos run test_golden_diff
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ app.*.map.json

# Melos related
pubspec_overrides.yaml

# Ignore non-CI golden files and failures
**/test/**/goldens/**/*.*
**/test/**/failures/**/*.*
!**/test/**/goldens/ci/*.*
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@
"type": "dart",
"flutterMode": "release"
},
{
"name": "update goldens",
"type": "dart",
"request": "launch",
"args": [
"--update-goldens"
],
"templateFor": "test",
"codeLens": {
"for": [
"run-test",
"run-test-file"
],
"title": "Update goldens"
}
}
]
}
35 changes: 33 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,39 @@ command:
scripts:
analyze: melos exec dart analyze .

analyze_diff: melos exec --diff=origin/main...HEAD --include-dependents dart analyze .
analyze_diff:
run: melos exec --diff=origin/main...HEAD --include-dependents \
dart analyze .

format_check_diff: melos exec --diff=origin/main...HEAD --include-dependents dart format . --set-exit-if-changed
format_check_diff:
run: melos exec --diff=origin/main...HEAD --include-dependents \
dart format . --set-exit-if-changed

format_check: melos exec dart format . --set-exit-if-changed

test_golden_package:
run: melos exec flutter test --tags golden --dart-define=CI=true
packageFilters:
dirExists:
- test
dependsOn:
- alchemist

test_golden_package_diff:
run: melos exec --diff=origin/main...HEAD --include-dependents \
flutter test --tags golden --dart-define=CI=true
packageFilters:
dirExists:
- test
dependsOn:
- alchemist

test_golden: melos run test_golden_package --no-select

test_golden_diff: melos run test_golden_package_diff --no-select

update_goldens:
run: melos exec flutter test --update-goldens
packageFilters:
dependsOn:
- alchemist
Loading