Update dependency lints to v5 #114
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run automated tests | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
concurrency: | |
group: test-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
find-tests: | |
runs-on: ubuntu-latest | |
outputs: | |
tests: ${{ steps.find-tests.outputs.tests }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Find tests | |
id: find-tests | |
run: | | |
testable_pkg=$( | |
find . -type f -name pubspec.yaml -not -path '**/example/*' -exec dirname {} \; \ | |
| sed -e 's,^\./,,' \ | |
| sort -u \ | |
| awk '{print}' ORS='", "') | |
echo "tests=[\"${testable_pkg::-4}\"]" >> $GITHUB_OUTPUT | |
run-tests: | |
needs: find-tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
tests: ${{ fromJson(needs.find-tests.outputs.tests) }} | |
defaults: | |
run: | |
working-directory: ${{ matrix.tests }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cache pub packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.pub-cache | |
key: ${{ runner.os }}-pub-cache-${{ hashFiles('**/pubspec.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pub-cache- | |
- name: Check if has Flutter SDK on pubspec.yaml | |
id: has-flutter-sdk | |
run: | | |
if grep -q 'sdk: *flutter' pubspec.yaml; then | |
echo "has-flutter-sdk=true" >> $GITHUB_OUTPUT | |
else | |
echo "has-flutter-sdk=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
if: steps.has-flutter-sdk.outputs.has-flutter-sdk == 'true' | |
- name: Setup Dart | |
uses: dart-lang/setup-dart@v1 | |
if: steps.has-flutter-sdk.outputs.has-flutter-sdk == 'false' | |
- name: Install Coverage | |
run: | | |
dart pub global activate coverage | |
if: steps.has-flutter-sdk.outputs.has-flutter-sdk == 'false' | |
- name: Get package name | |
id: package-name | |
run: | | |
echo "package=$(grep -E '^name:' pubspec.yaml | awk '{print $2}')" >> $GITHUB_OUTPUT | |
- name: Install dependencies | |
run: | | |
if command -v flutter &> /dev/null; then | |
flutter pub get | |
else | |
dart pub get | |
fi | |
- name: Ensure test directory exists | |
run: | | |
[ -d test ] || mkdir test | |
- uses: stelynx/[email protected] | |
with: | |
use_git_root: false | |
main_dir: ${{ matrix.tests }} | |
package: ${{ steps.package-name.outputs.package }} | |
test_file: test/coverage_helper_test.dart | |
- name: Add fake test to help coverage | |
run: | | |
sed -i '/^void main/d' test/coverage_helper_test.dart | |
echo -e "import 'package:test/test.dart';\nvoid main(){ test('dart-full-coverage', () {}); }" >> test/coverage_helper_test.dart | |
dart pub add test --dev | |
- name: Run tests | |
run: | | |
if command -v test_with_coverage &> /dev/null; then | |
test_with_coverage | |
else | |
flutter test --coverage | |
fi | |
- name: Normalize Codecov fag name | |
id: codecov-flag | |
run: | | |
echo "name=$(echo ${{ matrix.tests }} | sed -e 's/\//./g')" >> $GITHUB_OUTPUT | |
- name: Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: ${{ steps.codecov-flag.outputs.name }} | |
file: ${{ matrix.tests }}/coverage/lcov.info |