Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/handlers context #7

Merged
merged 12 commits into from
Oct 16, 2024
Merged
65 changes: 65 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Setup
description: Sets up the Flutter environment

inputs:
flutter-version:
description: 'The version of Flutter to use'
required: false
default: '3.24.3'
pub-cache:
description: 'The name of the pub cache variable'
required: false
default: control

runs:
using: composite
steps:
- name: 📦 Checkout the repo
uses: actions/checkout@v4

- name: 🔢 Set up version from tags
id: set-version
if: startsWith(github.ref, 'refs/tags')
shell: bash
run: |
BASE_VERSION="${GITHUB_REF#refs/tags/v}"
UNIXTIME=$(date +%s)
VERSION="${BASE_VERSION}+${UNIXTIME}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
sed -i "s/^version: .*/version: ${VERSION}/" pubspec.yaml
echo "Version set to $VERSION"

- name: 🚂 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '${{ inputs.flutter-version }}'
channel: "stable"

- name: 📤 Restore Pub modules
id: cache-pub-restore
uses: actions/cache/restore@v4
with:
path: |
/home/runner/.pub-cache
key: ${{ runner.os }}-pub-${{ inputs.pub-cache }}-${{ hashFiles('pubspec.lock') }}

- name: 👷 Install Dependencies
shell: bash
run: |
echo /home/runner/.pub-cache/bin >> $GITHUB_PATH
flutter config --no-cli-animations --no-analytics
flutter pub get

#- name: ⏲️ Run build runner
# shell: bash
# run: |
# dart run build_runner build --delete-conflicting-outputs --release

- name: 📥 Save Pub modules
id: cache-pub-save
if: steps.cache-pub-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
/home/runner/.pub-cache
key: ${{ steps.cache-pub-restore.outputs.cache-primary-key }}
67 changes: 34 additions & 33 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ on:
push:
branches:
- "master"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"
pull_request:
branches:
- "master"
Expand All @@ -24,58 +14,69 @@ on:
- "hotfix/**"
- "support/**"
paths:
- "pubspec.yaml"
- "pubspec.lock"
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"

permissions:
contents: read
actions: read
checks: write

jobs:
checkout:
name: "Checkout"
name: "🧪 Check code with analysis, format, and tests"
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: ./
container:
image: plugfox/flutter:stable
timeout-minutes: 10
steps:
- name: 🚂 Get latest code
uses: actions/checkout@v3

- name: 🚃 Cache pub modules
uses: actions/cache@v2
env:
cache-name: cache-octopus-package
- name: 📦 Get the .github actions
uses: actions/checkout@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-pub-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }}
sparse-checkout: |
.github

- name: 🗄️ Export pub cache directory
run: export PUB_CACHE=$PWD/.pub_cache/
- name: 🚂 Setup Flutter and dependencies
uses: ./.github/actions/setup
with:
flutter-version: 3.24.3

- name: 👷 Install Dependencies
timeout-minutes: 1
run: |
flutter pub get

- name: 🔎 Check format
- name: 🚦 Check code format
id: check-format
timeout-minutes: 1
run: dart format --set-exit-if-changed -l 80 -o none lib/
run: |
find lib test -name "*.dart" ! -name "*.*.dart" -print0 | xargs -0 dart format --set-exit-if-changed --line-length 80 -o none

- name: 📈 Check analyzer
- name: 📈 Check for Warnings
id: check-analyzer
timeout-minutes: 1
run: flutter analyze --fatal-infos --fatal-warnings lib/
run: |
flutter analyze --fatal-infos --fatal-warnings lib/ test/

- name: 🧪 Run tests
- name: 🧪 Unit & Widget tests
timeout-minutes: 2
run: |
flutter test -r github -j 6 --coverage test/control_test.dart
flutter test -r github --concurrency=6 --coverage test/control_test.dart

- name: 📥 Upload coverage to Codecov
timeout-minutes: 1
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos

- name: 📥 Upload test report
uses: actions/upload-artifact@v4
if: (success() || failure()) && ${{ github.actor != 'dependabot[bot]' }}
with:
name: test-results
path: reports/tests.json
27 changes: 27 additions & 0 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Test Report"

on:
workflow_run:
workflows: ["Checkout"] # runs after "Checkout" workflow
types:
- completed

permissions:
contents: read
actions: read
checks: write

jobs:
report:
name: "🚛 Test report"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Test report
uses: dorny/test-reporter@v1
with:
artifact: test-results
name: Test Report
path: "**/tests.json"
reporter: flutter-json
fail-on-error: false
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ coverage/
/temp

# FVM
.fvm/flutter_sdk
.fvm/flutter_sdk

# Generated files
*.*.dart
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.2.0

- **ADDED**: `HandlerContext` to handlers, available at zone and observer.
- **ADDED**: `name` getter for `Controller`
- **ADDED**: `void onHandler(HandlerContext context)` to `IControllerObserver`
- **REMOVED**: `done` getter from `Controller`

## 0.1.0

- **BREAKING CHANGE**: Replace FutureOr with Future in handler
Expand Down
98 changes: 93 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,95 @@
SHELL :=/bin/bash -e -o pipefail
PWD := $(shell pwd)

.DEFAULT_GOAL := all
.PHONY: all
all: ## build pipeline
all: format check test

.PHONY: ci
ci: ## CI build pipeline
ci: all

.PHONY: precommit
precommit: ## validate the branch before commit
precommit: all

.PHONY: help
help: ## help dialog
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
help:
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: version
version: ## Check flutter version
@flutter --version

.PHONY: doctor
doctor: ## Check flutter doctor
@flutter doctor

.PHONY: format
format: ## Format the code
@dart format -l 80 --fix lib/ test/

.PHONY: fmt
fmt: format

.PHONY: fix
fix: format ## Fix the code
@dart fix --apply lib
@dart fix --apply test

.PHONY: get
get: ## Get the dependencies
@flutter pub get

.PHONY: upgrade
upgrade: get ## Upgrade dependencies
@flutter pub upgrade

.PHONY: upgrade-major
upgrade-major: get ## Upgrade to major versions
@flutter pub upgrade --major-versions

.PHONY: outdated
outdated: get ## Check for outdated dependencies
@flutter pub outdated --show-all --dev-dependencies --dependency-overrides --transitive --no-prereleases

.PHONY: dependencies
dependencies: get ## Check outdated dependencies
@flutter pub outdated --dependency-overrides \
--dev-dependencies --prereleases --show-all --transitive

.PHONY: test
test: get ## Run the tests
@flutter test --coverage --concurrency=6 test/control_test.dart

.PHONY: publish-check
publish-check: ## Check the package before publishing
@dart pub publish --dry-run

.PHONY: publish
publish: ## Publish the package
@yes | dart pub publish

.PHONY: analyze
analyze: get ## Analyze the code
@dart format --set-exit-if-changed -l 80 -o none lib/ test/
@flutter analyze --fatal-infos --fatal-warnings lib/ test/

.PHONY: check
check: analyze publish-check ## Check the code
# @flutter pub global activate pana
# @pana --json --no-warning --line-length 80 > log.pana.json

.PHONY: clean
clean: ## Clean the project and remove all generated files
@rm -rf dist bin out build
@rm -rf coverage.* coverage .dart_tool .packages pubspec.lock

-include tool/makefile/pub.mk tool/makefile/test.mk
.PHONY: diff
diff: ## git diff
$(call print-target)
@git diff --exit-code
@RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi
Loading
Loading