Skip to content

Commit f124efc

Browse files
authored
Introduce workflow dispatch action forformat & fix --apply (#1575)
1 parent 9d43f71 commit f124efc

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

.github/workflows/analyze.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
access_token: ${{ github.token }}
2525

2626
analyze:
27-
name: Format, fix & analyze Code
2827
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
2928
runs-on: ubuntu-latest
3029
timeout-minutes: 20
@@ -39,17 +38,8 @@ jobs:
3938
if: ${{ inputs.sdk == 'flutter' }}
4039

4140
- run: ${{ inputs.sdk }} pub get
42-
43-
- run: dart format .
44-
45-
- run: dart fix --apply
46-
47-
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore
48-
# we need to pass the current branch, otherwise we can't commit the changes.
49-
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs.
50-
- run: ../scripts/commit-formatted-code.sh $GITHUB_HEAD_REF
51-
if: env.GITHUB_HEAD_REF != null
52-
41+
- run: dart format --set-exit-if-changed ./
42+
5343
- name: dart analyze
5444
uses: invertase/github-action-dart-analyzer@1cda5922c6369263b1c7e2fbe281f69704f4d63e # [email protected]
5545
with:

.github/workflows/format-and-fix.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)