Skip to content

Commit cb427da

Browse files
authored
Merge pull request #7 from PlugFox/feature/handlers-context
Feature/handlers context
2 parents 3611123 + 5238615 commit cb427da

24 files changed

+725
-215
lines changed

.github/actions/setup/action.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Setup
2+
description: Sets up the Flutter environment
3+
4+
inputs:
5+
flutter-version:
6+
description: 'The version of Flutter to use'
7+
required: false
8+
default: '3.24.3'
9+
pub-cache:
10+
description: 'The name of the pub cache variable'
11+
required: false
12+
default: control
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: 📦 Checkout the repo
18+
uses: actions/checkout@v4
19+
20+
- name: 🔢 Set up version from tags
21+
id: set-version
22+
if: startsWith(github.ref, 'refs/tags')
23+
shell: bash
24+
run: |
25+
BASE_VERSION="${GITHUB_REF#refs/tags/v}"
26+
UNIXTIME=$(date +%s)
27+
VERSION="${BASE_VERSION}+${UNIXTIME}"
28+
echo "VERSION=$VERSION" >> $GITHUB_ENV
29+
sed -i "s/^version: .*/version: ${VERSION}/" pubspec.yaml
30+
echo "Version set to $VERSION"
31+
32+
- name: 🚂 Setup Flutter
33+
uses: subosito/flutter-action@v2
34+
with:
35+
flutter-version: '${{ inputs.flutter-version }}'
36+
channel: "stable"
37+
38+
- name: 📤 Restore Pub modules
39+
id: cache-pub-restore
40+
uses: actions/cache/restore@v4
41+
with:
42+
path: |
43+
/home/runner/.pub-cache
44+
key: ${{ runner.os }}-pub-${{ inputs.pub-cache }}-${{ hashFiles('pubspec.lock') }}
45+
46+
- name: 👷 Install Dependencies
47+
shell: bash
48+
run: |
49+
echo /home/runner/.pub-cache/bin >> $GITHUB_PATH
50+
flutter config --no-cli-animations --no-analytics
51+
flutter pub get
52+
53+
#- name: ⏲️ Run build runner
54+
# shell: bash
55+
# run: |
56+
# dart run build_runner build --delete-conflicting-outputs --release
57+
58+
- name: 📥 Save Pub modules
59+
id: cache-pub-save
60+
if: steps.cache-pub-restore.outputs.cache-hit != 'true'
61+
uses: actions/cache/save@v4
62+
with:
63+
path: |
64+
/home/runner/.pub-cache
65+
key: ${{ steps.cache-pub-restore.outputs.cache-primary-key }}

.github/workflows/checkout.yml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ on:
55
push:
66
branches:
77
- "master"
8-
- "develop"
9-
- "feature/**"
10-
- "bugfix/**"
11-
- "hotfix/**"
12-
- "support/**"
13-
paths:
14-
- "lib/**.dart"
15-
- "test/**.dart"
16-
- "example/**.dart"
17-
- "pubspec.yaml"
188
pull_request:
199
branches:
2010
- "master"
@@ -24,58 +14,69 @@ on:
2414
- "hotfix/**"
2515
- "support/**"
2616
paths:
17+
- "pubspec.yaml"
18+
- "pubspec.lock"
2719
- "lib/**.dart"
2820
- "test/**.dart"
2921
- "example/**.dart"
30-
- "pubspec.yaml"
22+
23+
permissions:
24+
contents: read
25+
actions: read
26+
checks: write
3127

3228
jobs:
3329
checkout:
34-
name: "Checkout"
30+
name: "🧪 Check code with analysis, format, and tests"
3531
runs-on: ubuntu-latest
32+
timeout-minutes: 10
3633
defaults:
3734
run:
3835
working-directory: ./
39-
container:
40-
image: plugfox/flutter:stable
41-
timeout-minutes: 10
4236
steps:
43-
- name: 🚂 Get latest code
44-
uses: actions/checkout@v3
45-
46-
- name: 🚃 Cache pub modules
47-
uses: actions/cache@v2
48-
env:
49-
cache-name: cache-octopus-package
37+
- name: 📦 Get the .github actions
38+
uses: actions/checkout@v4
5039
with:
51-
path: |
52-
$PWD/.pub_cache/
53-
key: ${{ runner.os }}-pub-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }}
40+
sparse-checkout: |
41+
.github
5442
55-
- name: 🗄️ Export pub cache directory
56-
run: export PUB_CACHE=$PWD/.pub_cache/
43+
- name: 🚂 Setup Flutter and dependencies
44+
uses: ./.github/actions/setup
45+
with:
46+
flutter-version: 3.24.3
5747

5848
- name: 👷 Install Dependencies
5949
timeout-minutes: 1
6050
run: |
6151
flutter pub get
6252
63-
- name: 🔎 Check format
53+
- name: 🚦 Check code format
54+
id: check-format
6455
timeout-minutes: 1
65-
run: dart format --set-exit-if-changed -l 80 -o none lib/
56+
run: |
57+
find lib test -name "*.dart" ! -name "*.*.dart" -print0 | xargs -0 dart format --set-exit-if-changed --line-length 80 -o none
6658
67-
- name: 📈 Check analyzer
59+
- name: 📈 Check for Warnings
60+
id: check-analyzer
6861
timeout-minutes: 1
69-
run: flutter analyze --fatal-infos --fatal-warnings lib/
62+
run: |
63+
flutter analyze --fatal-infos --fatal-warnings lib/ test/
7064
71-
- name: 🧪 Run tests
65+
- name: 🧪 Unit & Widget tests
7266
timeout-minutes: 2
7367
run: |
74-
flutter test -r github -j 6 --coverage test/control_test.dart
68+
flutter test -r github --concurrency=6 --coverage test/control_test.dart
7569
7670
- name: 📥 Upload coverage to Codecov
7771
timeout-minutes: 1
7872
uses: codecov/codecov-action@v3
7973
with:
8074
files: ./coverage/lcov.info
8175
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
76+
77+
- name: 📥 Upload test report
78+
uses: actions/upload-artifact@v4
79+
if: (success() || failure()) && ${{ github.actor != 'dependabot[bot]' }}
80+
with:
81+
name: test-results
82+
path: reports/tests.json

.github/workflows/test-report.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Test Report"
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Checkout"] # runs after "Checkout" workflow
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: read
11+
actions: read
12+
checks: write
13+
14+
jobs:
15+
report:
16+
name: "🚛 Test report"
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
steps:
20+
- name: Test report
21+
uses: dorny/test-reporter@v1
22+
with:
23+
artifact: test-results
24+
name: Test Report
25+
path: "**/tests.json"
26+
reporter: flutter-json
27+
fail-on-error: false

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ coverage/
4747
/temp
4848

4949
# FVM
50-
.fvm/flutter_sdk
50+
.fvm/flutter_sdk
51+
52+
# Generated files
53+
*.*.dart

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.2.0
2+
3+
- **ADDED**: `HandlerContext` to handlers, available at zone and observer.
4+
- **ADDED**: `name` getter for `Controller`
5+
- **ADDED**: `void onHandler(HandlerContext context)` to `IControllerObserver`
6+
- **REMOVED**: `done` getter from `Controller`
7+
18
## 0.1.0
29

310
- **BREAKING CHANGE**: Replace FutureOr with Future in handler

Makefile

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,95 @@
1+
SHELL :=/bin/bash -e -o pipefail
2+
PWD := $(shell pwd)
3+
4+
.DEFAULT_GOAL := all
5+
.PHONY: all
6+
all: ## build pipeline
7+
all: format check test
8+
9+
.PHONY: ci
10+
ci: ## CI build pipeline
11+
ci: all
12+
13+
.PHONY: precommit
14+
precommit: ## validate the branch before commit
15+
precommit: all
16+
117
.PHONY: help
2-
help: ## help dialog
3-
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
4-
@echo ''
5-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
18+
help:
19+
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
20+
@echo ''
21+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
22+
23+
.PHONY: version
24+
version: ## Check flutter version
25+
@flutter --version
26+
27+
.PHONY: doctor
28+
doctor: ## Check flutter doctor
29+
@flutter doctor
30+
31+
.PHONY: format
32+
format: ## Format the code
33+
@dart format -l 80 --fix lib/ test/
34+
35+
.PHONY: fmt
36+
fmt: format
37+
38+
.PHONY: fix
39+
fix: format ## Fix the code
40+
@dart fix --apply lib
41+
@dart fix --apply test
42+
43+
.PHONY: get
44+
get: ## Get the dependencies
45+
@flutter pub get
46+
47+
.PHONY: upgrade
48+
upgrade: get ## Upgrade dependencies
49+
@flutter pub upgrade
50+
51+
.PHONY: upgrade-major
52+
upgrade-major: get ## Upgrade to major versions
53+
@flutter pub upgrade --major-versions
54+
55+
.PHONY: outdated
56+
outdated: get ## Check for outdated dependencies
57+
@flutter pub outdated --show-all --dev-dependencies --dependency-overrides --transitive --no-prereleases
58+
59+
.PHONY: dependencies
60+
dependencies: get ## Check outdated dependencies
61+
@flutter pub outdated --dependency-overrides \
62+
--dev-dependencies --prereleases --show-all --transitive
63+
64+
.PHONY: test
65+
test: get ## Run the tests
66+
@flutter test --coverage --concurrency=6 test/control_test.dart
67+
68+
.PHONY: publish-check
69+
publish-check: ## Check the package before publishing
70+
@dart pub publish --dry-run
71+
72+
.PHONY: publish
73+
publish: ## Publish the package
74+
@yes | dart pub publish
75+
76+
.PHONY: analyze
77+
analyze: get ## Analyze the code
78+
@dart format --set-exit-if-changed -l 80 -o none lib/ test/
79+
@flutter analyze --fatal-infos --fatal-warnings lib/ test/
80+
81+
.PHONY: check
82+
check: analyze publish-check ## Check the code
83+
# @flutter pub global activate pana
84+
# @pana --json --no-warning --line-length 80 > log.pana.json
85+
86+
.PHONY: clean
87+
clean: ## Clean the project and remove all generated files
88+
@rm -rf dist bin out build
89+
@rm -rf coverage.* coverage .dart_tool .packages pubspec.lock
690

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

0 commit comments

Comments
 (0)