|
| 1 | +on: |
| 2 | + workflow_dispatch: |
| 3 | + |
| 4 | +jobs: |
| 5 | + cancel-previous-workflow: |
| 6 | + runs-on: ubuntu-latest |
| 7 | + steps: |
| 8 | + - name: Cancel Previous Runs |
| 9 | + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # [email protected] |
| 10 | + with: |
| 11 | + access_token: ${{ github.token }} |
| 12 | + |
| 13 | + format-and-fix: |
| 14 | + name: Format & fix code |
| 15 | + if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 20 |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + package: [ |
| 21 | + {name: dart, sdk: dart}, |
| 22 | + {name: dio, sdk: dart}, |
| 23 | + {name: file, sdk: dart}, |
| 24 | + {name: flutter, sdk: flutter}, |
| 25 | + {name: logging, sdk: dart}, |
| 26 | + {name: sqflite, sdk: flutter}, |
| 27 | + ] |
| 28 | + defaults: |
| 29 | + run: |
| 30 | + working-directory: ${{ matrix.package.name }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v3 |
| 33 | + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1 |
| 34 | + if: ${{ matrix.package.sdk == 'dart' }} |
| 35 | + - uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # [email protected] |
| 36 | + if: ${{ matrix.package.sdk == 'flutter' }} |
| 37 | + |
| 38 | + - run: ${{ matrix.package.sdk }} pub get |
| 39 | + |
| 40 | + - run: dart format . |
| 41 | + |
| 42 | + - run: dart fix --apply |
| 43 | + |
| 44 | + # Source: https://stackoverflow.com/a/58035262 |
| 45 | + - name: Extract branch name |
| 46 | + shell: bash |
| 47 | + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT |
| 48 | + id: extract_branch |
| 49 | + |
| 50 | + # actions/checkout fetches only a single commit in a detached HEAD state. Therefore |
| 51 | + # we need to pass the current branch, otherwise we can't commit the changes. |
| 52 | + # GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. |
| 53 | + - name: Commit & push |
| 54 | + run: ./scripts/commit-formatted-code.sh ${{ steps.extract_branch.outputs.branch }} |
0 commit comments