|
| 1 | +name: "[base] Dart" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + path: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: '.' |
| 10 | + |
| 11 | +jobs: |
| 12 | + is-flutter: |
| 13 | + uses: ./.github/workflows/_base-has_flutter.yaml |
| 14 | + with: |
| 15 | + path: ${{ inputs.path }} |
| 16 | + |
| 17 | + check-tests: |
| 18 | + name: "check tests" |
| 19 | + runs-on: ubuntu-latest |
| 20 | + needs: is-flutter |
| 21 | + if: needs.is-flutter.outputs.is_flutter == '0' |
| 22 | + outputs: |
| 23 | + do_tests: ${{ steps.check-tests.outputs.do_tests }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v5 |
| 26 | + # Skip if no test directory |
| 27 | + - id: check-tests |
| 28 | + run: | |
| 29 | + if [ ! -d "${{ inputs.path }}/test" ]; then |
| 30 | + echo "No test directory found, skipping tests."; |
| 31 | + do_tests=0 |
| 32 | + else |
| 33 | + echo "Test directory found, will run tests."; |
| 34 | + do_tests=1 |
| 35 | + fi |
| 36 | + echo "do_tests=$do_tests" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + install: |
| 39 | + name: "install" |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: [ is-flutter ] |
| 42 | + if: needs.is-flutter.outputs.is_flutter == '0' |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v5 |
| 45 | + - uses: dart-lang/setup-dart@v1 |
| 46 | + with: |
| 47 | + sdk: stable |
| 48 | + |
| 49 | + format: |
| 50 | + name: "format" |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: install |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v5 |
| 56 | + - uses: dart-lang/setup-dart@v1 |
| 57 | + with: |
| 58 | + sdk: stable |
| 59 | + |
| 60 | + - name: "Get dependencies" |
| 61 | + run: dart pub get |
| 62 | + working-directory: ${{ inputs.path }} |
| 63 | + |
| 64 | + - name: "dart format" |
| 65 | + run: | |
| 66 | + echo "Checking Dart formatting...\nFiles displayed below:" |
| 67 | + dart format -o none --set-exit-if-changed ./lib/ |
| 68 | + if [ -d "${{ inputs.path }}/test" ]; then dart format -o none --set-exit-if-changed ./test/; fi |
| 69 | + echo "No formatting issues found." |
| 70 | + working-directory: ${{ inputs.path }} |
| 71 | + |
| 72 | + analyze: |
| 73 | + name: "analyze" |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: install |
| 76 | + |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v5 |
| 79 | + - uses: dart-lang/setup-dart@v1 |
| 80 | + with: |
| 81 | + sdk: stable |
| 82 | + |
| 83 | + - name: "Get dependencies" |
| 84 | + run: dart pub get |
| 85 | + working-directory: ${{ inputs.path }} |
| 86 | + |
| 87 | + - name: Run analysis |
| 88 | + run: | |
| 89 | + dart analyze --fatal-warnings ./lib/ |
| 90 | + if [ -d "${{ inputs.path }}/test" ]; then dart analyze --fatal-warnings ./test/; fi |
| 91 | + working-directory: ${{ inputs.path }} |
| 92 | + |
| 93 | + test: |
| 94 | + runs-on: ubuntu-latest |
| 95 | + needs: [install, check-tests] |
| 96 | + if: needs.check-tests.outputs.do_tests == 1 |
| 97 | + |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v5 |
| 100 | + - uses: dart-lang/setup-dart@v1 |
| 101 | + with: |
| 102 | + sdk: stable |
| 103 | + |
| 104 | + - name: "Get dependencies" |
| 105 | + run: dart pub get |
| 106 | + working-directory: ${{ inputs.path }} |
| 107 | + |
| 108 | + - name: Run tests |
| 109 | + run: dart test --reporter=expanded test/*.dart |
| 110 | + working-directory: ${{ inputs.path }} |
0 commit comments