-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6394ef6
commit d1b7ceb
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,58 @@ jobs: | |
code-quality: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
permissions: write-all | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.head_ref }} | ||
repository: ${{github.event.pull_request.head.repo.full_name}} | ||
- name: Get branch name | ||
id: branch-name | ||
uses: tj-actions/[email protected] | ||
- 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 | ||
run: flutter analyze | ||
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 | ||
fi | ||
- name: Run tests | ||
run: cd example && flutter test | ||
id: test | ||
run: | | ||
cd example | ||
# Allows code to run after an error. | ||
set -e | ||
# Runs flutter test; saves output and if it fails. | ||
out=$(flutter test) || failed='true' | ||
echo "$out" | ||
# Saves output to either success or failure variables. | ||
if [ "$failed" == "true" ]; then | ||
echo "FAILURE=true" >> $GITHUB_OUTPUT | ||
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 | ||
|
@@ -36,3 +69,35 @@ jobs: | |
git add -A | ||
git commit -m '[automated commit] lint format and import sort' | ||
git push | ||
- name: Print outputs | ||
env: | ||
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_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 |
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
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
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