diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index e6bd7c24d1..5e7deceb3f 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -24,6 +24,7 @@ jobs: access_token: ${{ github.token }} analyze: + name: Format, fix & analyze Code if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} runs-on: ubuntu-latest timeout-minutes: 20 @@ -36,8 +37,17 @@ jobs: if: ${{ inputs.sdk == 'dart' }} - uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # pin@v2.10.0 if: ${{ inputs.sdk == 'flutter' }} + - run: ${{ inputs.sdk }} pub get - - run: ${{ inputs.sdk }} format --set-exit-if-changed ./ + + - run: dart format . + + - run: dart fix --apply + + # 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. + - run: ../scripts/commit-formatted-code.sh $GITHUB_HEAD_REF - name: dart analyze uses: invertase/github-action-dart-analyzer@cdd8652b05bf7ed08ffce30f425436780f869f13 # pin@v1 diff --git a/flutter/lib/src/binding_wrapper.dart b/flutter/lib/src/binding_wrapper.dart index 4a0b5d5a87..4d6856861a 100644 --- a/flutter/lib/src/binding_wrapper.dart +++ b/flutter/lib/src/binding_wrapper.dart @@ -1,10 +1,9 @@ // ignore_for_file: invalid_use_of_internal_member +import '../sentry_flutter.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import '../sentry_flutter.dart'; - /// The methods and properties are modelled after the the real binding class. @experimental class BindingWrapper { diff --git a/scripts/commit-formatted-code.sh b/scripts/commit-formatted-code.sh new file mode 100755 index 0000000000..8f77921ceb --- /dev/null +++ b/scripts/commit-formatted-code.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -euo pipefail + +GITHUB_BRANCH="${1}" + +if [[ $(git status) == *"nothing to commit"* ]]; then + echo "Nothing to commit. All code formatted correctly." +else + echo "Formatted some code. Going to push the changes." + git config --global user.name 'Sentry Github Bot' + git config --global user.email 'bot+github-bot@sentry.io' + git fetch + git checkout ${GITHUB_BRANCH} + git commit -am "Format & fix code" + git push --set-upstream origin ${GITHUB_BRANCH} +fi