Skip to content

Commit

Permalink
Feature/5.0.0 (#19)
Browse files Browse the repository at this point in the history
* chore: Update dependencies and upgrade Flutter to Dart 2.12.0

* chore: Update platform import for JS interop compatibility

* chore: Update platform import for JS interop compatibility

* chore: Update platform import for JS interop compatibility

* chore: Update platform import for JS interop compatibility

* Rename test file

* chore: Update platform import for JS interop compatibility

* Update example.png

* Update example
  • Loading branch information
PlugFox authored Aug 13, 2024
1 parent 32dadab commit 4c6fb44
Show file tree
Hide file tree
Showing 18 changed files with 1,041 additions and 426 deletions.
142 changes: 100 additions & 42 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name: Checkout
name: CHECKOUT

on:
workflow_dispatch:
push:
branches:
- "master"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"
#push:
# branches:
# - "master"
# - "develop"
# - "feature/**"
# - "bugfix/**"
# - "hotfix/**"
# - "support/**"
# paths:
# - ".github/workflows/*.yml"
# - "lib/pubspec.yaml"
# - "lib/**.dart"
# - "test/**.dart"
# - "example/**.dart"
pull_request:
branches:
- "master"
Expand All @@ -24,68 +25,125 @@ on:
- "hotfix/**"
- "support/**"
paths:
- ".github/workflows/*.yml"
- "lib/pubspec.yaml"
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"

jobs:
checkout:
name: "Checkout"
runs-on: ubuntu-latest
container:
image: dart:beta
defaults:
run:
working-directory: ./
container:
image: dart:stable
env:
pub-cache-name: pub
threshold: 95
timeout-minutes: 10
steps:
- name: 🚂 Get latest code
uses: actions/checkout@v3
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
sparse-checkout: |
.github
pubspec.yaml
lib
test
analysis_options.yaml
CHANGELOG.md
- name: 🚃 Cache pub modules
uses: actions/cache@v2
env:
cache-name: cache-pub-package
- name: 📤 Restore Pub modules
id: cache-pub-restore
uses: actions/cache/restore@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-pub-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }}
$HOME/.pub-cache
key: ${{ runner.os }}-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 🗄️ Export pub cache directory
run: export PUB_CACHE=$PWD/.pub_cache/
- name: 🗄️ Export Pub cache directory
id: export-pub-cache
timeout-minutes: 1
run: |
export PUB_CACHE=$PWD/.pub_cache/
export PATH="$PATH":"$HOME/.pub-cache/bin"
echo "${HOME}/.pub-cache/bin" >> $GITHUB_PATH
- name: 👷 Install Dependencies
id: install-dependencies
timeout-minutes: 1
run: |
dart pub get
apt-get update && apt-get install -y lcov
dart pub global activate coverage
dart pub get --no-example
- name: 📥 Save Pub modules
id: cache-pub-save
uses: actions/cache/save@v4
with:
path: |
$HOME/.pub-cache
key: ${{ runner.os }}-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 🔎 Check format
id: check-format
timeout-minutes: 1
run: dart format --set-exit-if-changed -l 80 -o none .
run: dart format --set-exit-if-changed -l 80 -o none lib/

- name: 📈 Check analyzer
id: check-analyzer
timeout-minutes: 1
run: dart analyze --fatal-infos --fatal-warnings lib
run: dart analyze --fatal-infos --fatal-warnings lib/

- name: 👀 Verify versions
id: verify-versions
timeout-minutes: 1
run: |
test -f pubspec.yaml && test -f CHANGELOG.md
version_pubspec=$(grep '^version:' pubspec.yaml | awk '{print $2}' | sed 's/[^[:print:]]//g')
test -n "$version_pubspec"
echo "Version from pubspec.yaml: '$version_pubspec'"
grep -q "# $version_pubspec" CHANGELOG.md || (echo "Version not found in CHANGELOG.md" >&2; exit 1)
#- name: Check with pana
# run: dart pub global activate pana && pana --json --no-warning --line-length 80

- name: 🧪 Run tests
id: run-tests
timeout-minutes: 2
run: |
dart test --coverage=coverage \
&& dart run coverage:format_coverage --lcov --in=coverage \
--out=coverage/lcov.info --report-on=lib
dart pub global run coverage:test_with_coverage -fb -o coverage -- \
--platform vm --compiler=kernel --coverage=coverage \
--reporter=github --file-reporter=json:coverage/tests.json \
--timeout=10m --concurrency=12 --color \
test/test.dart
- name: 📥 Upload coverage to Codecov
uses: codecov/codecov-action@v2.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: 🔍 Check coverage
id: check-coverage
timeout-minutes: 2
run: |
mv coverage/lcov.info coverage/lcov.base.info
lcov --remove coverage/lcov.base.info '*.g.dart' -o coverage/lcov.info
lcov --list coverage/lcov.info
THRESHOLD=${{ env.threshold }}
COVERAGE=$(lcov --summary coverage/lcov.info | grep -i 'lines\|Total:' | tail -n 1 | awk '{print $2}' | sed 's/%//')
echo "Coverage is $COVERAGE%"
echo $COVERAGE | awk '{if ($1 < 50) exit 1}'
- name: 🧹 Cleanup artifacts
id: cleanup-artifacts
if: always()
timeout-minutes: 2
run: |
rm -rf ~/build
- name: 🧮 Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1.2.1
- name: ✨ Upload coverage to Codecov
id: upload-coverage
timeout-minutes: 2
uses: codecov/codecov-action@v4
with:
path: coverage/lcov.info
min_coverage: 90
#exclude: '**.g.dart **.freezed.dart'
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
9 changes: 8 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"request": "launch",
"type": "dart",
"program": "example/main.dart",
"args": []
},
// https://pub.dev/packages/test
// dart test test/ws_test.dart --color --platform=vm
{
Expand Down Expand Up @@ -54,4 +61,4 @@
"args": []
}
]
}
}
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 5.0.0 - 2024-08-13

- Update dependencies
- dart:html replaced with package:web
- Enums replaced with sealed classes
- Renamed getters

## 4.0.2 - 2023-06-30

- Fix topics
Expand Down Expand Up @@ -54,15 +61,15 @@

### Changed

- Fix `kListOSWithCupertinoDesign` constant and `isCupertino` flag
- Fix `kListOSWithCupertinoDesign` constant and `cupertino` flag

## 2.0.1 - 2020-09-06

### Added

- Add getters:
- `isWeb` - Is a web-based applications
- `isIO` - Is a I/O supporting for non-web applications
- `isJS` - Is a web-based applications
- `isVM` - Is a I/O supporting for non-web applications

## 2.0.0 - 2020-08-28

Expand Down Expand Up @@ -114,9 +121,9 @@
### Added

- Add new flags:
- isDesktop
- isMaterial
- isCupertino
- desktop
- material
- cupertino

## 1.0.1 - 2020-04-22

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ get:

upgrade: get
@echo "Upgrading dependencies"
@flutter pub upgrade
@dart pub upgrade

outdated:
@echo "Outdated check"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Provides platform information such as:

- Host platform type

- io (vm, desktops, mobile, console)
- web (html, js, browser)
- vm (io, desktops, mobile, console, server)
- js (web, html, browser)

- Operating system

Expand All @@ -49,7 +49,7 @@ Provides platform information such as:
- Android
- Unknown

- Version (`<unknown>` if not available)
- Version (`unknown` if not available)

- Locale string (`en` if not available)

Expand All @@ -59,7 +59,7 @@ Provides platform information such as:

- Is a Web-based applications

- Is a I/O supporting for non-web applications
- Is a VM supporting for non-web applications

- Is a mobile device (Android, iOS)

Expand Down Expand Up @@ -108,10 +108,10 @@ You can use nested methods to compose more complex queries.
[mobile] - is mobile device (Android, iOS)
[desktop] - is desktop device (Windows, MacOS, Fuchsia)

##### IO or Web
##### VM (IO) or JS (Web)

[web] - is web-based applications
[io] - is I/O supporting for non-web applications
[js] - is web-based applications
[vm] - is I/O supporting for non-web applications

##### Build mode

Expand All @@ -125,7 +125,7 @@ You can use nested methods to compose more complex queries.
1. Operating System
2. Design
3. Mobile/Desktop
4. IO/Web
4. VM/JS
5. Build mode
6. Call [orElse] if any callback was not called

Expand Down
6 changes: 0 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ analyzer:
- 'web/**'
# Build
- 'build/**'
# Generated code
- 'lib/**/*.g.dart'
- 'lib/generated_plugin_registrant.dart'
# Assets
- 'assets/**'
# Mocks for test
Expand Down Expand Up @@ -61,12 +58,10 @@ linter:
avoid_as: false
avoid_redundant_argument_values: false
comment_references: false # Unused because https://github.com/dart-lang/sdk/issues/36974
flutter_style_todos: false
prefer_double_quotes: false
sort_constructors_first: false
sort_unnamed_constructors_first: false
use_key_in_widget_constructors: false
avoid_web_libraries_in_flutter: false
always_put_control_body_on_new_line: false
#diagnostic_describe_all_properties: false # ???

Expand Down Expand Up @@ -140,7 +135,6 @@ linter:
unnecessary_string_escapes: true
unnecessary_string_interpolations: true
unsafe_html: true
use_full_hex_values_for_flutter_colors: true
use_raw_strings: true
use_string_buffers: true
valid_regexps: true
Expand Down
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ void main(List<String> args) {
print(platform.numberOfProcessors);

final design = platform.when<String?>(
io: () => platform.when<String>(
vm: () => platform.when<String>(
material: () => 'Android or Fuchsia',
cupertino: () => 'macOS or iOS',
orElse: () => 'Windows or Linux',
),
web: () => 'Web',
js: () => 'Web',
);
print(design);

final operatingSystem = switch (platform.operatingSystem) {
OperatingSystem.android => 'Android',
OperatingSystem.fuchsia => 'Fuchsia',
OperatingSystem.iOS => 'iOS',
OperatingSystem.linux => 'Linux',
OperatingSystem.macOS => 'macOS',
OperatingSystem.windows => 'Windows',
OperatingSystem.unknown => 'Unknown',
const OperatingSystem.android() => 'Android',
const OperatingSystem.fuchsia() => 'Fuchsia',
const OperatingSystem.iOS() => 'iOS',
const OperatingSystem.linux() => 'Linux',
const OperatingSystem.macOS() => 'macOS',
const OperatingSystem.windows() => 'Windows',
const OperatingSystem.unknown() || _ => 'Unknown',
};
print(operatingSystem);

final buildMode = switch (platform.buildMode) {
BuildMode.debug => 'Debug',
BuildMode.profile => 'Profile',
BuildMode.release => 'Release',
BuildMode$Debug _ => 'Debug',
BuildMode$Profile _ => 'Profile',
BuildMode$Release _ => 'Release',
};
print(buildMode);
}
Loading

0 comments on commit 4c6fb44

Please sign in to comment.