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

ci: Add release please and other github actions #3

Merged
merged 6 commits into from
Aug 22, 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
22 changes: 22 additions & 0 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI - On Main

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

# This job is triggered when a new tag is pushed to the main branch.
jobs:
# This job uses the release-please action to create a release PR.
# See https://github.com/googleapis/release-please
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
manifest-file: "release-please/.release-please-manifest.json"
config-file: "release-please/release-please-config.json"
9 changes: 9 additions & 0 deletions .github/workflows/on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: CI - On Release
on:
push:
tags:
- "*"
# jobs:
## This job is triggered when a new tag is pushed to the repository.
## Typically this would be a release from release-please.
## Here you may want to create a build, publish to a package registry, etc.
57 changes: 57 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI - Pull Request

on:
pull_request:
# pull_request_target: # Uncomment this line if you are using pull_request_target

# Pull Request Runs on the same branch will be cancelled
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
code-quality:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@v4
with:
fetch-depth: 0

# Use the flutter-action to set up flutter, and cache dependencies
- uses: subosito/flutter-action@v2
with:
cache: true

# If you have generated code, you may want to run build_runner to generate the code
# - run: dart run build_runner build --delete-conflicting-outputs

# Uses the flutter-code-quality action to run code quality checks
# This will return a status check to the pull request
- uses: ZebraDevs/[email protected]
with:
token: ${{secrets.GITHUB_TOKEN}}

# You may want to add more jobs here, such as building and testing your code.
# The following commented job is an example of deploying a preview version of your app
# deploy-preview:
# name: Deploy preview version of the storybook on firebase
# needs: code-quality
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# repository: ${{github.event.pull_request.head.repo.full_name}}
# ref: ${{ github.head_ref }}
# - uses: subosito/flutter-action@v2
# with:
# cache: true
# - name: Setup flutter
# run: flutter pub get
# - name: Build example app
# run: flutter build web
# - uses: FirebaseExtended/action-hosting-deploy@v0
# with:
# repoToken: "${{ secrets.GITHUB_TOKEN }}"
# firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_ZETA_DS }}"
# channelId: "pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }}"
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'package:zeta_flutter/zeta_flutter.dart';

import 'package:zeta_flutter_template/src/utils/routes.dart';

// coverage:ignore-start
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
// coverage:ignore-end

class MyApp extends StatefulWidget {
const MyApp({super.key});
Expand Down
12 changes: 6 additions & 6 deletions lib/src/pages/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _ExamplePageState extends State<ExamplePage> {
child: Row(
children: [
ZetaButton(
label: 'Button',
label: 'Open Dialog',
onPressed: () {
showZetaDialog(
context,
Expand Down Expand Up @@ -199,10 +199,10 @@ class _ExamplePageState extends State<ExamplePage> {
child: Row(
children: [
SizedBox(width: 250, child: ZetaDateInput(label: 'Date Input')),
const SizedBox(width: 250, child: ZetaPasswordInput(label: 'Password input')),
const SizedBox(width: 250, child: ZetaPhoneInput(label: 'Phone Input')),
const SizedBox(width: 250, child: ZetaTimeInput(label: 'Phone Input')),
const SizedBox(width: 250, child: ZetaTextInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaPasswordInput(label: 'Password input')),
SizedBox(width: 250, child: ZetaPhoneInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaTimeInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaTextInput(label: 'Phone Input')),
SizedBox(
width: 250,
child: ZetaSelectInput(
Expand Down Expand Up @@ -238,7 +238,7 @@ class _ExamplePageState extends State<ExamplePage> {
onActionButtonPressed: () {},
title: const Text('Screen Header Bar'),
),
const ZetaSearchBar(),
ZetaSearchBar(),
ZetaSegmentedControl(
segments: const [
ZetaButtonSegment(value: 1, child: Text('Segmented')),
Expand Down
10 changes: 5 additions & 5 deletions lib/src/utils/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final goRouter = GoRouter(
builder: (context, state, navigationShell) {
return LayoutBuilder(
builder: (context, constraints) {
final showBottomBar = constraints.maxWidth < 479;
final showBottomBar = constraints.maxWidth < 500;

final body = CustomScrollView(
slivers: [
Expand Down Expand Up @@ -42,8 +42,8 @@ final goRouter = GoRouter(
onSelect: (value) => navigationShell.goBranch(value),
selectedIndex: state.fullPath == '/' ? 0 : 1,
items: const [
ZetaNavigationRailItem(label: 'Welcome', icon: Icon(ZetaIcons.content_round)),
ZetaNavigationRailItem(label: 'Example', icon: Icon(ZetaIcons.star_round)),
ZetaNavigationRailItem(label: 'Welcome', icon: Icon(ZetaIcons.content)),
ZetaNavigationRailItem(label: 'Example', icon: Icon(ZetaIcons.star)),
],
),
Expanded(child: body),
Expand All @@ -54,8 +54,8 @@ final goRouter = GoRouter(
onTap: (value) => navigationShell.goBranch(value),
currentIndex: state.fullPath == '/' ? 0 : 1,
items: const [
ZetaNavigationBarItem(icon: ZetaIcons.content_round, label: 'Welcome'),
ZetaNavigationBarItem(icon: ZetaIcons.star_round, label: 'Example'),
ZetaNavigationBarItem(icon: ZetaIcons.content, label: 'Welcome'),
ZetaNavigationBarItem(icon: ZetaIcons.star, label: 'Example'),
],
)
: null,
Expand Down
2 changes: 1 addition & 1 deletion macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
flutter:
sdk: flutter
go_router: ^14.2.0
zeta_flutter: ^0.14.0
zeta_flutter: ^0.15.1

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions release-please/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
62 changes: 62 additions & 0 deletions release-please/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"packages": {
".": {
"release-type": "dart"
}
},
"changelog-sections": [
{
"type": "feat",
"section": "✨ New Features"
},
{
"type": "fix",
"section": "🪲 Bug Fixes"
},
{
"type": "revert",
"section": "👀 Reverts"
},
{
"type": "docs",
"section": "📈 Documentation"
},
{
"type": "deps",
"section": "⛓️ Dependencies"
},
{
"type": "test",
"section": "🧪 Tests"
},
{
"type": "chore",
"section": "🧹 Miscellaneous Chores"
},
{
"type": "perf",
"section": "Performance Improvements",
"hidden": true
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": true
},
{
"type": "style",
"section": "Styles",
"hidden": true
},
{
"type": "build",
"section": "Build System",
"hidden": true
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
]
}
104 changes: 94 additions & 10 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,110 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import 'package:zeta_flutter_template/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
testWidgets('App runs', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
});

testWidgets('Bottom navigation bar works on small screen', (WidgetTester tester) async {
// Set the screen size to a small value
tester.view.devicePixelRatio = 1.0;
tester.view.physicalSize = const Size(481, 480);

// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();

// Find the bottom navigation bar widget
final bottomNavigationBarFinder = find.byType(ZetaNavigationBar);

// Verify that the bottom navigation bar is present
expect(bottomNavigationBarFinder, findsOneWidget);

// Perform a tap on the first item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.content_round));
await tester.pump();

// Verify that the first item is selected
expect(bottomNavigationBarFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationBar>(bottomNavigationBarFinder).currentIndex, 0);

// Perform a tap on the second item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.star_round));
await tester.pump();

// // Verify that the second item is selected
expect(bottomNavigationBarFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationBar>(bottomNavigationBarFinder).currentIndex, 1);
});

testWidgets('Side navigation bar works on large screen', (WidgetTester tester) async {
// Set the screen size to a small value
tester.view.devicePixelRatio = 1.0;
tester.view.physicalSize = const Size(881, 480);

// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

// Find the bottom navigation bar widget
final navigationRailFinder = find.byType(ZetaNavigationRail);

// Verify that the bottom navigation bar is present
expect(navigationRailFinder, findsOneWidget);

// Perform a tap on the first item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.content));
await tester.pump();

// Verify that the first item is selected
expect(navigationRailFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationRail>(navigationRailFinder).selectedIndex, 0);

// Perform a tap on the second item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.star));
await tester.pump();

// // Verify that the second item is selected
expect(navigationRailFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationRail>(navigationRailFinder).selectedIndex, 1);
});

testWidgets('Switching between light and dark mode', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Find the switch widget
final switchFinder = find.byType(ZetaSwitch).first;

// Verify that the switch is present
// expect(switchFinder, findsOneWidget);

// Get the current brightness mode
final zetaFinder = find.byType(Zeta);
final initialBrightness = tester.widget<Zeta>(zetaFinder).brightness;
// final brightnessMode = tester.binding.window.platformBrightness;

// Perform a tap on the switch to toggle the brightness mode
await tester.tap(switchFinder);
await tester.pump();

// Verify that the brightness mode has changed
expect(tester.widget<Zeta>(zetaFinder).brightness, isNot(initialBrightness));

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
// Perform another tap on the switch to toggle back to the original brightness mode
await tester.tap(switchFinder);
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
// Verify that the brightness mode has changed back to the original mode
expect(tester.widget<Zeta>(zetaFinder).brightness, initialBrightness);
});
}