Skip to content

Commit

Permalink
ci: Update to use reusable flutter code quality action (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 26, 2024
1 parent d9bfe19 commit b8b4827
Show file tree
Hide file tree
Showing 9 changed files with 6,354 additions and 122 deletions.
107 changes: 13 additions & 94 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,16 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7.0.7
- uses: subosito/flutter-action@v2
- name: Setup flutter
run: flutter pub get
- name: Format code
id: format
run: dart format . -l 120
- name: Apply linter auto-fixes
id: lint
run: dart fix --apply
- name: Check for un-fixable issues
id: fix
run: |
# Allows code to run after an error.
set -e
# Runs flutter analyze; saves output and if it fails.
out="$(flutter analyze)" || failed='true'
echo "$out"
# Saves output to either success or failure variables.
if [ "$failed" == "true" ]; then
echo "FAILURE=true" >> $GITHUB_OUTPUT
exit 1
fi
- name: Run tests
id: test
run: |
# Allows code to run after an error.
set -e
# Runs flutter test; saves output and if it fails.
out=$(flutter test --coverage) || failed='true'
echo "$out"
# Saves output to either success or failure variables.
if [ "$failed" == "true" ]; then
echo "FAILURE=true" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
- name: Update changes in GitHub repository
if: env.modified == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
- name: Print outputs
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
template='<h2>PR Checks complete</h2>✅ - Linting</br>'
if [ -n "${{steps.fix.outputs.FAILURE}}" ]; then
template="$template ⛔️ - Problems found in code. To replicate, run <code>dart fix</code></br>"
else
template="$template ✅ - No errors found in code</br>"
fi
if [ -n "${{steps.test.outputs.FAILURE}}" ]; then
template="$template ⛔️ - Tests failed. To replicate, run <code>flutter test</code></br>"
else
template="$template ✅ - All tests passed</br>"
fi
# Add / amend comment on PR.
gh pr comment ${{github.event.pull_request.number}} --body="${template}" --edit-last -R ${{github.repository}} || gh pr comment ${{github.event.pull_request.number}} --body="${template}" -R ${{github.repository}} || echo 'Token not working'
# Concatenates failure outputs.
fail="${{steps.fix.outputs.FAILURE}}${{steps.test.outputs.FAILURE}}"
# Checks if there is any content in the failure variable.
if [[ -z "$fail" ]];
then
exit 0
else
exit 1
fi
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{ github.head_ref }}
- uses: subosito/flutter-action@v2
with:
cache: true
- uses: ZebraDevs/flutter-code-quality@latest
with:
token: ${{secrets.GITHUB_TOKEN}}
4 changes: 4 additions & 0 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ jobs:
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

code-quality:
uses: ./.github/workflows/code-quality.yml

deploy-qa-demo:
name: Deploy preview version of the storybook on firebase
needs: code-quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
cache: true
- name: Setup flutter
run: flutter pub get
- name: Build example app
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
- uses: dart-lang/setup-dart@v1
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
cache: true
- name: Install dependencies
run: flutter pub get
- name: Format code
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ on:
pull_request_target:

jobs:
up-to-date:
uses: ./.github/workflows/up-to-date.yml

code-quality:
uses: ./.github/workflows/code-quality.yml

Expand All @@ -24,7 +21,7 @@ jobs:
deploy-preview:
name: Deploy preview version of the storybook on firebase
needs: [up-to-date, code-quality, check-secret]
needs: [code-quality, check-secret]
if: needs.check-secret.outputs.secret-exists == 'true'
runs-on: ubuntu-latest
steps:
Expand All @@ -33,6 +30,8 @@ jobs:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{ github.head_ref }}
- uses: subosito/flutter-action@v2
with:
cache: true
- name: Setup flutter
run: flutter pub get
- name: Build example app
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/up-to-date.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ doc/api/
.fvm/flutter_sdk
.pub-cache/
.pub/
coverage/
/coverage/**/
lib/generated_plugin_registrant.dart
**/android/**/gradle-wrapper.jar
**/android/.gradle
Expand Down Expand Up @@ -97,7 +97,6 @@ lib/generated_plugin_registrant.dart
*.csr
*.css
*.htm
*.js
*.jsp
*.php
*.rss
Expand Down Expand Up @@ -146,3 +145,5 @@ $RECYCLE.BIN/
*.lnk
**/Generated.xcconfig
.fvmrc
**/node_modules/
package-lock.json
Loading

0 comments on commit b8b4827

Please sign in to comment.