Skip to content

Commit

Permalink
Introduce workflow dispatch action forformat & fix --apply (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Sep 11, 2023
1 parent 9d43f71 commit f124efc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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
Expand All @@ -39,17 +38,8 @@ jobs:
if: ${{ inputs.sdk == 'flutter' }}

- run: ${{ inputs.sdk }} pub get

- 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
if: env.GITHUB_HEAD_REF != null

- run: dart format --set-exit-if-changed ./

- name: dart analyze
uses: invertase/github-action-dart-analyzer@1cda5922c6369263b1c7e2fbe281f69704f4d63e # [email protected]
with:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/format-and-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
workflow_dispatch:

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # [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@v3
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1
if: ${{ matrix.package.sdk == 'dart' }}
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # [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-formatted-code.sh ${{ steps.extract_branch.outputs.branch }}

0 comments on commit f124efc

Please sign in to comment.