|
| 1 | +name: Flutter Package Workflow |
| 2 | +description: Build and test a Flutter package. |
| 3 | + |
| 4 | +inputs: |
| 5 | + concurrency: |
| 6 | + required: false |
| 7 | + default: "4" |
| 8 | + description: The value of the concurrency flag (-j) used when running tests |
| 9 | + coverage_excludes: |
| 10 | + required: false |
| 11 | + default: "" |
| 12 | + description: Globs to exclude from coverage |
| 13 | + working_directory: |
| 14 | + required: false |
| 15 | + default: "." |
| 16 | + description: The working directory for this workflow |
| 17 | + min_coverage: |
| 18 | + required: false |
| 19 | + default: "100" |
| 20 | + description: The minimum coverage percentage value |
| 21 | + analyze_directories: |
| 22 | + required: false |
| 23 | + default: "lib test" |
| 24 | + description: Directories to analyze |
| 25 | + report_on: |
| 26 | + required: false |
| 27 | + default: "lib" |
| 28 | + description: Directories to report on when collecting coverage |
| 29 | + platform: |
| 30 | + required: false |
| 31 | + default: "vm" |
| 32 | + description: Platform to use when running tests |
| 33 | + |
| 34 | +runs: |
| 35 | + using: "composite" |
| 36 | + steps: |
| 37 | + - name: 🐦 Setup Flutter |
| 38 | + uses: subosito/flutter-action@v2 |
| 39 | + |
| 40 | + - name: 📦 Install Dependencies |
| 41 | + working-directory: ${{ inputs.working_directory }} |
| 42 | + shell: ${{ inputs.shell }} |
| 43 | + run: flutter pub get |
| 44 | + |
| 45 | + - name: ✨ Format |
| 46 | + working-directory: ${{ inputs.working_directory }} |
| 47 | + shell: ${{ inputs.shell }} |
| 48 | + run: dart format --set-exit-if-changed . |
| 49 | + |
| 50 | + - name: 🔍 Analyze |
| 51 | + working-directory: ${{ inputs.working_directory }} |
| 52 | + shell: ${{ inputs.shell }} |
| 53 | + run: dart analyze --fatal-warnings ${{inputs.analyze_directories}} |
| 54 | + |
| 55 | + - name: 🧪 Test |
| 56 | + working-directory: ${{ inputs.working_directory }} |
| 57 | + shell: ${{ inputs.shell }} |
| 58 | + run: | |
| 59 | + if [ -d "test" ]; then |
| 60 | + flutter test --no-pub --test-randomize-ordering-seed random --coverage |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: 📊 Verify Coverage |
| 64 | + if: inputs.collect_coverage == 'true' |
| 65 | + uses: VeryGoodOpenSource/very_good_coverage@v3 |
| 66 | + with: |
| 67 | + path: ${{inputs.working_directory}}/coverage/lcov.info |
| 68 | + exclude: ${{inputs.coverage_excludes}} |
| 69 | + min_coverage: ${{inputs.min_coverage}} |
| 70 | + |
| 71 | + - name: 💯 Verify Pub Score |
| 72 | + if: inputs.collect_score == 'true' |
| 73 | + working-directory: ${{ inputs.working_directory }} |
| 74 | + shell: ${{ inputs.shell }} |
| 75 | + run: | |
| 76 | + dart pub global activate pana 0.21.45 |
| 77 | + sudo apt-get install webp |
| 78 | + PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p") |
| 79 | + echo "score: $PANA_SCORE" |
| 80 | + IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1] |
| 81 | + if [ -z "$1" ]; then MINIMUM_SCORE=TOTAL; else MINIMUM_SCORE=$1; fi |
| 82 | + if (( $SCORE < $MINIMUM_SCORE )); then echo "minimum score $MINIMUM_SCORE was not met!"; exit 1; fi |
0 commit comments