Skip to content

Commit 5e56652

Browse files
Merge pull request #7 from vicdotdevelop/feature/deployment-pipeline
tested pre-merge pipeline
2 parents f89d3ff + 055f5f9 commit 5e56652

File tree

11 files changed

+200
-36
lines changed

11 files changed

+200
-36
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Pre-merge checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- master
8+
push:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
test-publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# Checkout repository
19+
- name: Checkout code
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
# Set up Flutter
25+
- name: Set up Flutter
26+
uses: subosito/flutter-action@v2
27+
with:
28+
flutter-version: '3.29.0' # Specify exact version instead of just 'stable'
29+
channel: 'stable'
30+
31+
# Cache Flutter dependencies to speed up workflow
32+
- name: Cache Flutter dependencies
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.pub-cache
36+
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pub-
39+
40+
# Install dependencies
41+
- name: Install dependencies
42+
run: flutter pub get
43+
44+
# Run tests
45+
- name: Run tests
46+
run: flutter test
47+
48+
# Static code analysis
49+
- name: Analyze code
50+
run: flutter analyze --no-fatal-warnings
51+
52+
# Verify package format is correct
53+
- name: Format check
54+
run: dart format --set-exit-if-changed .
55+
56+
# Verify package
57+
- name: Verify package
58+
run: flutter pub publish --dry-run
59+
60+
# Check if package can be published
61+
- name: Check publication readiness
62+
run: flutter pub publish --dry-run
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish to Pub.dev
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # This triggers the action for tags like v1.0.0, v2.3.4, etc.
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Checkout repository
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0 # Fetches all history for all tags and branches
18+
19+
# Set up Flutter
20+
- name: Set up Flutter
21+
uses: subosito/flutter-action@v2
22+
with:
23+
flutter-version: '3.29.0' # Specify exact version instead of just 'stable'
24+
channel: 'stable'
25+
26+
# Cache Flutter dependencies to speed up workflow
27+
- name: Cache Flutter dependencies
28+
uses: actions/cache@v3
29+
with:
30+
path: ~/.pub-cache
31+
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}
32+
restore-keys: |
33+
${{ runner.os }}-pub-
34+
35+
# Install dependencies
36+
- name: Install dependencies
37+
run: flutter pub get
38+
39+
# Parse the tag to get the version without 'v' prefix
40+
- name: Extract version from tag
41+
id: get_version
42+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
43+
44+
# Verify the pubspec version matches the tag
45+
- name: Verify version
46+
run: |
47+
echo "Tag version: $VERSION"
48+
PUBSPEC_VERSION=$(grep -m 1 'version:' pubspec.yaml | awk '{print $2}')
49+
echo "Pubspec version: $PUBSPEC_VERSION"
50+
if [ "$VERSION" != "$PUBSPEC_VERSION" ]; then
51+
echo "Error: The version in pubspec.yaml ($PUBSPEC_VERSION) does not match the tag version ($VERSION)"
52+
exit 1
53+
fi
54+
55+
# Publish to pub.dev
56+
- name: Publish to Pub.dev
57+
env:
58+
PUB_DEV_TOKEN: ${{ secrets.PUB_DEV_TOKEN }}
59+
run: |
60+
# Configure Pub credentials
61+
mkdir -p ~/.pub-cache
62+
echo "$PUB_DEV_TOKEN" > ~/.pub-cache/credentials.json
63+
# Publish the package
64+
flutter pub publish --force
65+
66+
# Clean up after publish
67+
- name: Clean up
68+
run: |
69+
rm -f ~/.pub-cache/credentials.json

.idea/codeStyleConfig.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.pubignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.dart_tool/
2+
.idea/
3+
.vscode/
4+
build/
5+
.packages
6+
pubspec.lock
7+
.DS_Store
8+
.pub/
9+
.git/
10+
.github/
11+
.gitignore
12+
.travis/
13+
.travis.yml
14+
test/
15+
android/.idea
16+
example/build/
17+
example/.dart_tool/
18+
example/.packages
19+
example/pubspec.lock
20+
21+
# Don't exclude these files even though they are in .gitignore
22+
!.idea/codeStyleConfig.xml
23+
!.vscode/settings.json

.vscode/settings.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

example/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: ../../analysis_options.yaml
1+
include: ../analysis_options.yaml

example/lib/main.dart

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore_for_file: unused_local_variable
2-
32
import 'package:flutter/material.dart';
43
import 'package:native_flutter_proxy/native_flutter_proxy.dart';
54

@@ -12,13 +11,15 @@ void main() async {
1211
var enabled = false;
1312
String? host;
1413
int? port;
14+
1515
try {
1616
final settings = await NativeProxyReader.proxySetting;
1717
enabled = settings.enabled;
1818
host = settings.host;
1919
port = settings.port;
2020
} catch (e) {
21-
print(e);
21+
// Using debugPrint instead of print for production code
22+
debugPrint('Error fetching proxy settings: $e');
2223
}
2324

2425
// Enable the proxy if it is enabled and the host is not null.
@@ -27,22 +28,36 @@ void main() async {
2728
debugPrint('proxy enabled');
2829
}
2930

30-
runApp(MyApp());
31+
runApp(const MyApp());
3132
}
3233

34+
/// The main application widget.
35+
///
36+
/// This widget is the root of the application.
3337
class MyApp extends StatelessWidget {
38+
/// Creates a new instance of [MyApp].
39+
const MyApp({super.key});
40+
3441
@override
3542
Widget build(BuildContext context) {
3643
return MaterialApp(
3744
title: 'Flutter Demo',
3845
theme: ThemeData(primarySwatch: Colors.blue),
39-
home: MyHomePage(title: 'Flutter Demo Home Page'),
46+
home: const MyHomePage(title: 'Flutter Demo Home Page'),
4047
);
4148
}
4249
}
4350

51+
/// A widget that displays the home page of the application.
52+
///
53+
/// This widget is stateful and keeps track of a counter value.
4454
class MyHomePage extends StatefulWidget {
45-
MyHomePage({super.key, required this.title});
55+
/// Creates a new instance of [MyHomePage].
56+
///
57+
/// The [title] parameter is required and displayed in the app bar.
58+
const MyHomePage({required this.title, super.key});
59+
60+
/// The title displayed in the app bar.
4661
final String title;
4762

4863
@override
@@ -52,6 +67,7 @@ class MyHomePage extends StatefulWidget {
5267
class _MyHomePageState extends State<MyHomePage> {
5368
int counter = 0;
5469

70+
/// Increments the counter value.
5571
void _incrementCounter() => setState(() => counter++);
5672

5773
@override
@@ -62,7 +78,7 @@ class _MyHomePageState extends State<MyHomePage> {
6278
child: Column(
6379
mainAxisAlignment: MainAxisAlignment.center,
6480
children: [
65-
Text('You have pushed the button this many times:'),
81+
const Text('You have pushed the button this many times:'),
6682
Text(
6783
'$counter',
6884
style: Theme.of(context).textTheme.headlineMedium,
@@ -73,7 +89,7 @@ class _MyHomePageState extends State<MyHomePage> {
7389
floatingActionButton: FloatingActionButton(
7490
onPressed: _incrementCounter,
7591
tooltip: 'Increment',
76-
child: Icon(Icons.add),
92+
child: const Icon(Icons.add),
7793
),
7894
);
7995
}

example/pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,13 @@ packages:
5858
url: "https://pub.dev"
5959
source: hosted
6060
version: "2.1.4"
61+
very_good_analysis:
62+
dependency: "direct dev"
63+
description:
64+
name: very_good_analysis
65+
sha256: "9ae7f3a3bd5764fb021b335ca28a34f040cd0ab6eec00a1b213b445dae58a4b8"
66+
url: "https://pub.dev"
67+
source: hosted
68+
version: "5.1.0"
6169
sdks:
6270
dart: ">=3.7.0-0 <4.0.0"

example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ dependencies:
1111
sdk: flutter
1212
native_flutter_proxy: ^0.2.0
1313

14+
dev_dependencies:
15+
very_good_analysis: ^5.1.0
16+
1417
flutter:
1518
uses-material-design: true

lib/src/custom_proxy.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class CustomProxy {
6161
static CustomProxy? fromString({required String proxy}) {
6262
// Check if the proxy string is empty
6363
if (proxy.isEmpty) {
64-
assert(false, 'Proxy string passed to CustomProxy.fromString() is invalid.');
65-
64+
assert(
65+
false,
66+
'Proxy string passed to CustomProxy.fromString() is invalid.',
67+
);
6668
return null;
6769
}
6870

0 commit comments

Comments
 (0)