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
on: | |
workflow_dispatch: | |
push: | |
jobs: | |
cancel-previous-workflow: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cancel Previous Runs | |
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # [email protected] | |
with: | |
access_token: ${{ github.token }} | |
format-and-fix: | |
name: Format & fix code | |
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
strategy: | |
matrix: | |
package: [ | |
{name: dart, sdk: dart}, | |
{name: dio, sdk: dart}, | |
{name: file, sdk: dart}, | |
{name: flutter, sdk: flutter}, | |
{name: logging, sdk: dart}, | |
{name: sqflite, sdk: flutter}, | |
] | |
defaults: | |
run: | |
working-directory: ${{ matrix.package.name }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 # pin@v1 | |
if: ${{ matrix.package.sdk == 'dart' }} | |
- uses: subosito/flutter-action@62f096cacda5168a3bd7b95793373be14fa4fbaf # [email protected] | |
if: ${{ matrix.package.sdk == 'flutter' }} | |
- run: ${{ matrix.package.sdk }} pub get | |
- run: dart format . | |
- run: dart fix --apply | |
# Source: https://stackoverflow.com/a/58035262 | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore | |
# we need to pass the current branch, otherwise we can't commit the changes. | |
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. | |
- name: Commit & push | |
run: ./scripts/commit-code.sh ${{ steps.extract_branch.outputs.branch }} "Format & fix code" |