Skip to content

Commit

Permalink
Add code validation and unit test workflows for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
takenagain committed Sep 23, 2024
1 parent e296b1b commit 526e17d
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/actions/generate-assets/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Generates assets"
description: "Runs the flutter build command to transform and generate assets for the deployment build"

inputs:
GITHUB_TOKEN:
description: "The GitHub API public readonly token"
required: false
runs:
using: "composite"
steps:
- name: Fetch packages and generate assets
shell: bash
env:
GITHUB_API_PUBLIC_READONLY_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: |
echo "Running \`flutter build\` to generate assets for the deployment build"
if [ -n "$GITHUB_API_PUBLIC_READONLY_TOKEN" ]; then
echo "GITHUB_TOKEN provided, running flutter build with token"
else
echo "GITHUB_TOKEN not provided or empty, running flutter build without token"
unset GITHUB_API_PUBLIC_READONLY_TOKEN
fi
flutter pub get > /dev/null 2>&1
flutter build web --release > /dev/null 2>&1 || true
rm -rf build/*
# Run flutter build and capture its output and exit status
flutter pub get > /dev/null 2>&1
output=$(flutter build web --release)
exit_status=$?
# Check if the exit status is non-zero (indicating an error)
if [ $exit_status -ne 0 ]; then
echo "Flutter build exited with status $exit_status. Output:"
echo "$output"
exit $exit_status
fi
echo "Done fetching packages and generating assets"
51 changes: 51 additions & 0 deletions .github/workflows/unit-tests-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Runs unit tests on PRs to ensure the app is working as expected
name: Run unit tests for packages on PR
run-name: ${{ github.actor }} is running unit tests on PR 🚀

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- "packages/**"

jobs:
unit_tests_:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Setup GH Actions
uses: actions/checkout@v4

- name: Get stable flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Fetch packages and generate assets
uses: ./.github/actions/generate-assets
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test unit_test (unix)
id: unit_tests
continue-on-error: false
timeout-minutes: 15
run: |
cd packages
for package in */; do
echo "Running tests for $package"
cd "$package"
if [ -d "test" ]; then
flutter clean
rm -rf build/*
rm -rf web/src/mm2/*
rm -rf web/src/kdfi/*
rm -rf web/dist/*
flutter test
else
echo "No test directory found in $package"
fi
cd ..
done
39 changes: 39 additions & 0 deletions .github/workflows/validate-code-guidelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Rule for running static analysis and code formatting checks on all PRs
# Runs static analysis and code formatting checks on all PRs to ensure the codebase is clean and consistent
name: Validate Packages Code Guidelines
run-name: ${{ github.actor }} is validating code guidelines 🚀

on:
pull_request:
branches:
- "*"
paths:
- "packages/**"

jobs:
validate_packages_code_guidelines:
runs-on: macos-latest

steps:
- name: Setup GH Actions
uses: actions/checkout@v4

- name: Get stable flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Fetch packages and generate assets
uses: ./.github/actions/generate-assets
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Validate dart code
run: |
cd packages
for package in */; do
echo "Analyzing package: $package"
cd "$package"
flutter analyze
cd ..
done

0 comments on commit 526e17d

Please sign in to comment.