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

Refine CI/CD #36

Merged
merged 20 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/actions/setup_flutter/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Setup Flutter
description: Setup flutter project and toolchains for subsequent actions.

inputs:
target:
description: "The working directory where the Flutter project is located."
required: false
default: "."

runs:
using: "composite"
steps:
- name: Install Flutter SDK
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.x
cache: true

- name: Flutter version
run: flutter --version
shell: bash

- name: Install dependencies
run: flutter pub get
shell: bash
working-directory: ${{ inputs.target }}
84 changes: 84 additions & 0 deletions .github/workflows/code_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Code Check
on:
push:
branches: main
pull_request:

env:
FLUTTER_TEST_REPORT: ${{github.workspace}}/flutter-test-report.json
PATTERN_CHECKER: ${{github.workspace}}/scripts/pattern_checker.sh

jobs:
# Change detection
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
dart-files: ${{ steps.filter.outputs.dart-files }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
dart-files:
- '**.dart'

# Static code analysis
analysis:
needs: changes
if: ${{ needs.changes.outputs.dart-files == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
target: [package, cookbook]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
target: ${{ matrix.target }}

- name: Format
run: dart format . -o none --set-exit-if-changed
working-directory: ${{ matrix.target }}

- name: Analyze
run: dart analyze
working-directory: ${{ matrix.target }}

- name: Disallowed patterns check
run: bash ${{ env.PATTERN_CHECKER }} "*.dart" "--" "debugPrint"
working-directory: ${{ matrix.target }}

# Unit testing
testing:
needs: changes
if: ${{ needs.changes.outputs.dart-files == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
checks: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
target: package

- name: Run unit tests
run: flutter test --file-reporter="json:${{ env.FLUTTER_TEST_REPORT }}"
working-directory: package

- name: Write test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Test Report
path: ${{ env.FLUTTER_TEST_REPORT }}
reporter: flutter-json
30 changes: 0 additions & 30 deletions .github/workflows/code_check.yml

This file was deleted.

26 changes: 9 additions & 17 deletions .github/workflows/dry_publish.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
name: Dry Publish
on:
push:
branches: [main, "release/*"]

env:
package_dir: ./package
branches: main
pull_request:
branches: main

jobs:
dry-publish:
name: Dry Publish
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.package_dir }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Flutter SDK
uses: subosito/flutter-action@v2
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
channel: stable
flutter-version: 3.x

- run: flutter --version
- run: flutter pub get
target: package

- uses: axel-op/dart-package-analyzer@master
id: analysis
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
relativePath: ${{ env.package_dir }}
relativePath: package

- uses: fujidaiti/dart-package-inspector@v1
with:
Expand All @@ -42,3 +33,4 @@ jobs:
supported-platforms: ios, android

- run: flutter pub publish --dry-run
working-directory: package
12 changes: 4 additions & 8 deletions .github/workflows/publish.yml → .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ on:

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Flutter SDK
uses: subosito/flutter-action@v2
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
channel: stable
flutter-version: 3.x

- name: Flutter version
run: flutter --version
target: package

- name: Publish to pub.dev
run: flutter pub publish --force
working-directory: package
47 changes: 0 additions & 47 deletions .github/workflows/unit_testing.yaml

This file was deleted.

94 changes: 90 additions & 4 deletions package/test/foundation/sheet_physics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {
);
});

test('does not apply any resistance if the position is in bounds', () {
test('does not apply any resistance if position is in bounds', () {
final positionAtNearTopEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels - 10);
final positionAtNearBottomEdge = _referenceSheetMetrics.copyWith(
Expand Down Expand Up @@ -78,7 +78,7 @@ void main() {
);
});

test('creates no ballistic simulation if the position is in bounds', () {
test('creates no ballistic simulation if position is in bounds', () {
expect(
physicsUnderTest.createBallisticSimulation(0, _positionAtMiddle),
isNull,
Expand Down Expand Up @@ -141,7 +141,7 @@ void main() {
);
});

test('creates settling simulation which ends at the nearest edge', () {
test('creates settling simulation which ends at nearest edge', () {
final moreOverDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels + 200,
);
Expand Down Expand Up @@ -186,7 +186,7 @@ void main() {
behaviorUnderTest = const SnapToNearestEdge(minFlingSpeed: 50);
});

test('snaps to the nearest edge if the velocity is small enough', () {
test('snaps to nearest edge if velocity is small enough', () {
final positionAtNearTopEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels - 50,
);
Expand Down Expand Up @@ -215,6 +215,92 @@ void main() {
);
});

test('is disabled if position is out of bounds', () {
final overDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels + 10,
);
final underDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.minPixels - 10,
);

expect(
behaviorUnderTest.findSnapPixels(0, overDraggedPosition),
isNull,
);
expect(
behaviorUnderTest.findSnapPixels(0, underDraggedPosition),
isNull,
);
});
});
group('$SnapToNearest', () {
late SnapToNearest behaviorUnderTest;

setUp(() {
behaviorUnderTest = SnapToNearest(
minFlingSpeed: 50,
snapTo: [
Extent.pixels(_positionAtBottomEdge.pixels),
Extent.pixels(_positionAtMiddle.pixels),
Extent.pixels(_positionAtTopEdge.pixels),
],
);
});

test('snaps to nearest edge if velocity is small enough', () {
final positionAtNearTopEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels - 50,
);
final positionAtNearMiddle = _referenceSheetMetrics.copyWith(
pixels: _positionAtMiddle.pixels + 50,
);
final positionAtNearBottomEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.minPixels + 50,
);

expect(
behaviorUnderTest.findSnapPixels(0, positionAtNearTopEdge),
moreOrLessEquals(_referenceSheetMetrics.maxPixels),
);
expect(
behaviorUnderTest.findSnapPixels(0, positionAtNearMiddle),
moreOrLessEquals(_positionAtMiddle.pixels),
);
expect(
behaviorUnderTest.findSnapPixels(0, positionAtNearBottomEdge),
moreOrLessEquals(_referenceSheetMetrics.minPixels),
);
});

test('is aware of fling gesture direction', () {
final positionAtAboveMiddle = _positionAtMiddle.copyWith(
pixels: _positionAtMiddle.pixels + 10,
);
final positionAtBelowMiddle = _positionAtMiddle.copyWith(
pixels: _positionAtMiddle.pixels - 10,
);
// Flings up at the bottom edge
expect(
behaviorUnderTest.findSnapPixels(50, _positionAtBottomEdge),
moreOrLessEquals(_positionAtMiddle.pixels),
);
// Flings up at the slightly above the middle position
expect(
behaviorUnderTest.findSnapPixels(50, positionAtAboveMiddle),
moreOrLessEquals(_positionAtTopEdge.pixels),
);
// Flings down at the top edge
expect(
behaviorUnderTest.findSnapPixels(-50, _positionAtTopEdge),
moreOrLessEquals(_positionAtMiddle.pixels),
);
// Flings down at the slightly below the middle position
expect(
behaviorUnderTest.findSnapPixels(-50, positionAtBelowMiddle),
moreOrLessEquals(_positionAtBottomEdge.pixels),
);
});

test('is disabled if position is out of bounds', () {
final overDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels + 10,
Expand Down
Loading