feat: add README standardization tool #133
This file contains hidden or 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: Dart | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| env: | |
| FLUTTER_VERSION: "3.35.0" | |
| jobs: | |
| discover: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| packages: ${{ steps.packages.outputs.packages }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: ${{ env.FLUTTER_VERSION }} | |
| cache: true | |
| - name: Install melos | |
| run: dart pub global activate melos | |
| - name: Bootstrap packages | |
| run: melos bootstrap | |
| - name: Get packages | |
| id: packages | |
| run: | | |
| # Determine the base ref for comparison | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| BASE_REF="origin/${{ github.base_ref }}" | |
| else | |
| BASE_REF="HEAD~1" | |
| fi | |
| # Get packages that have changes using melos diff | |
| packages=$(melos list --diff="$BASE_REF" --json | jq -c "[.[] | select(.name != \"biomedict_workspace\") | .name]" 2>/dev/null || echo '[]') | |
| if [ "$packages" = "" ] || [ "$packages" = "null" ]; then | |
| packages="[]" | |
| fi | |
| echo "packages=$packages" >> $GITHUB_OUTPUT | |
| echo "Changed packages: $packages" | |
| build: | |
| needs: discover | |
| runs-on: ubuntu-latest | |
| if: needs.discover.outputs.packages != '[]' | |
| strategy: | |
| matrix: | |
| package: ${{ fromJson(needs.discover.outputs.packages) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: ${{ env.FLUTTER_VERSION }} | |
| cache: true | |
| - name: Install dependencies | |
| run: | | |
| dart pub global activate melos | |
| melos bootstrap --scope="${{ matrix.package }}" | |
| - name: Format package | |
| run: melos exec --scope="${{ matrix.package }}" -- dart format . --set-exit-if-changed | |
| - name: Analyze package | |
| run: melos exec --scope="${{ matrix.package }}" -- dart analyze --fatal-infos | |
| test: | |
| needs: [ discover, build ] | |
| runs-on: ubuntu-latest | |
| if: needs.discover.outputs.packages != '[]' | |
| strategy: | |
| matrix: | |
| package: ${{ fromJson(needs.discover.outputs.packages) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: ${{ env.FLUTTER_VERSION }} | |
| cache: true | |
| - name: Install dependencies | |
| run: | | |
| dart pub global activate melos | |
| melos bootstrap --scope="${{ matrix.package }}" | |
| - name: Run tests | |
| id: test-step | |
| run: | | |
| # Try Flutter test first (will only run if package has test dir and is Flutter package) | |
| if melos exec --scope="${{ matrix.package }}" --dir-exists=test --flutter -- flutter test --coverage 2>/dev/null; then | |
| echo "has_tests=true" >> $GITHUB_OUTPUT | |
| # Try Dart test (will only run if package has test dir and is not Flutter package) | |
| elif melos exec --scope="${{ matrix.package }}" --dir-exists=test --no-flutter -- dart test --coverage 2>/dev/null; then | |
| echo "has_tests=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No tests to run for ${{ matrix.package }}" | |
| echo "has_tests=false" >> $GITHUB_OUTPUT | |
| fi | |
| # Get package path for coverage upload | |
| package_path=$(melos list --scope="${{ matrix.package }}" --json | jq -r ".[0].path") | |
| echo "package_path=$package_path" >> $GITHUB_OUTPUT | |
| - name: Upload coverage reports to Codecov | |
| if: steps.test-step.outputs.has_tests == 'true' | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| flags: ${{ matrix.package }} | |
| files: ${{ steps.test-step.outputs.package_path }}/coverage/lcov.info |