Skip to content

Commit

Permalink
Merge pull request #1 from madmini/feature/gh-actions
Browse files Browse the repository at this point in the history
Add GitHub Actions workflow
  • Loading branch information
madmini authored Jul 23, 2022
2 parents 2aefa1a + 78919ee commit a490eb8
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 57 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# for reference see:
# - Workflow syntax: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
# - Contexts: https://docs.github.com/en/actions/learn-github-actions/contexts
# - Expressions: https://docs.github.com/en/actions/learn-github-actions/expressions
name: CI

on:
workflow_dispatch: # run from the Actions tab
push:
branches: [ "main" ]
tags: [ "v*" ]
pull_request:
branches: [ "main" ]

permissions:
contents: write

env:
DART_DEFINES: >-
--dart-define=GIT_URL=https://github.com/madmini/epc-qr
--dart-define=GIT_REF=${{ github.ref_name }}
--dart-define=CI_PROVIDER=GitHubActions
--dart-define=COMMIT_HASH=${{ github.sha }}
--dart-define=VERSION_TAG=${{ github.ref_name }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
container: cirrusci/flutter:stable
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: flutter pub get

- name: Build web
run: flutter build web --release --base-href "/epc-qr/" $DART_DEFINES

- name: Compress web build
run: zip -r ../web.zip .
working-directory: build/web

- name: Store web build
uses: actions/upload-artifact@v3
with:
name: build-web
path: build/web.zip

- if: github.ref_type == 'tag'
name: Set-up GitHub Pages deployment
run: apt-get update && apt-get install -y rsync

- if: github.ref_type == 'tag'
name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/web

- name: Build Android
run: flutter build apk --release $DART_DEFINES

- name: Store android build
uses: actions/upload-artifact@v3
with:
name: build-android
path: build/app/outputs/flutter-apk/app-release.apk

- if: github.ref_type == 'tag'
name: Prepare release
run: |
mkdir artifacts
mv build/web.zip artifacts/epc-qr_${{ github.ref_name }}_web.zip
mv build/app/outputs/flutter-apk/app-release.apk artifacts/epc-qr_${{ github.ref_name }}.apk
- if: github.ref_type == 'tag'
name: Create release
uses: ncipollo/release-action@v1
with:
draft: true
artifacts: artifacts/*
Binary file not shown.
Binary file added assets/fonts/RobotoMono-VariableFont_wght.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
title: 'EPC-QR Generator',
home: const EpcQrFormPage(),
themeMode: ThemeMode.system,
theme: theme,
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/form.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:epc_qr/data/qr_data.dart';
import 'package:epc_qr/screens/view_code.dart';
import 'package:epc_qr/widgets/about_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
Expand Down Expand Up @@ -28,6 +29,7 @@ class _EpcQrFormPageState extends State<EpcQrFormPage> {
return Scaffold(
appBar: AppBar(
title: const Text('Enter Payment Data'),
actions: const [AboutButton()],
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.qr_code),
Expand Down Expand Up @@ -69,8 +71,9 @@ class _EpcQrFormPageState extends State<EpcQrFormPage> {
),
initialValue: useRef,
onChanged: (value) {
if (value == null) return;
setState(() {
useRef = value!;
useRef = value;
});
},
decoration: const InputDecoration(
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/view_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:epc_qr/data/qr_data.dart';
import 'package:epc_qr/share/share_stub.dart'
if (dart.library.html) 'package:epc_qr/share/share_web.dart'
if (dart.library.io) 'package:epc_qr/share/share_io.dart';
import 'package:epc_qr/widgets/share/share_stub.dart'
if (dart.library.html) 'package:epc_qr/widgets/share/share_web.dart'
if (dart.library.io) 'package:epc_qr/widgets/share/share_io.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:qr_flutter/qr_flutter.dart';
Expand Down
75 changes: 75 additions & 0 deletions lib/widgets/about_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:epc_qr/widgets/linkify_on_open.dart';
import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart';

const kGitUrl = String.fromEnvironment('GIT_URL');
const kGitRef = String.fromEnvironment('GIT_REF');
const kCommitHash = String.fromEnvironment('COMMIT_HASH');
const kCiProvider = String.fromEnvironment('CI_PROVIDER');
const kVersionTag = String.fromEnvironment('VERSION_TAG');

class AboutButton extends StatelessWidget {
const AboutButton({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.info),
onPressed: () => showAboutDialog(
context: context,
applicationName: 'EPC-QR Generator',
applicationVersion: kVersionTag != '' ? kVersionTag : null,
children: kGitUrl != '' ? const [AboutSourceText()] : null,
),
);
}
}

class AboutSourceText extends StatelessWidget {
const AboutSourceText({Key? key}) : super(key: key);

TextStyle _codeStyle(BuildContext context) => TextStyle(
fontFamily: 'RobotoMono',
color: Theme.of(context).textTheme.headline4?.color,
fontWeight: Theme.of(context).brightness == Brightness.light
? FontWeight.bold
: null,
);

TextStyle _linkStyle(BuildContext context) => TextStyle(
fontFamily: 'RobotoMono',
color: Theme.of(context).brightness == Brightness.dark
? const Color(0xFF9BCAFF)
: const Color(0xFF0062A0),
);

@override
Widget build(BuildContext context) {
if (kGitUrl == '') return const SizedBox();

return SelectableText.rich(
TextSpan(children: [
const TextSpan(
text: 'Built${kCiProvider != '' ? ' by $kCiProvider' : ''} from ',
),
LinkifySpan(
text: kGitUrl,
linkStyle: _linkStyle(context),
onOpen: onOpenLaunchUrl,
),
if (kCommitHash != '')
TextSpan(children: [
const TextSpan(text: ' at '),
TextSpan(text: kCommitHash, style: _codeStyle(context)),
]),
if (kGitRef != '')
TextSpan(children: [
const TextSpan(text: ' ('),
TextSpan(text: kGitRef, style: _codeStyle(context)),
const TextSpan(text: ')'),
]),
const TextSpan(text: '.'),
]),
);
}
}
8 changes: 8 additions & 0 deletions lib/widgets/linkify_on_open.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';

/// Launches the given URL.
void onOpenLaunchUrl(LinkableElement link) async {
final uri = Uri.parse(link.url);
await launchUrl(uri);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
bool get shareFeatureAvailable {
throw (UnimplementedError("STUB"));
return false;
}

Future<void> shareFile(String name, List<int> data, {String? mimeType}) {
throw UnimplementedError();
throw UnimplementedError('Sharing files is not supported on this platform.');
}
File renamed without changes.
60 changes: 17 additions & 43 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -36,13 +29,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
ffi:
dependency: transitive
description:
Expand All @@ -69,6 +55,15 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "7.4.0"
flutter_linkify:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "2795ccf4d98d284b6e0934ffe8550510961f8cf4"
url: "https://github.com/madmini/flutter_linkify.git"
source: git
version: "5.0.2"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -100,13 +95,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "7.2.0"
image:
dependency: "direct main"
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
intl:
dependency: transitive
description:
Expand All @@ -121,6 +109,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
linkify:
dependency: transitive
description:
name: linkify
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -205,13 +200,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -352,15 +340,8 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
url_launcher:
dependency: transitive
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
Expand Down Expand Up @@ -436,13 +417,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+1"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
sdks:
dart: ">=2.17.1 <3.0.0"
flutter: ">=3.0.0"
13 changes: 11 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: EPC-QR code generator (for European SEPA transfers) in flutter.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.1.0
version: 0.2.0

environment:
sdk: ">=2.17.1 <3.0.0"
Expand All @@ -21,10 +21,19 @@ dependencies:
share_plus: ^4.0.10
path_provider: ^2.0.11
path: ^1.8.1
image: ^3.2.0
flutter_linkify:
git: https://github.com/madmini/flutter_linkify.git
url_launcher: ^6.1.5

dev_dependencies:
flutter_lints: ^2.0.1

flutter:
uses-material-design: true

fonts:
- family: RobotoMono
fonts:
- asset: assets/fonts/RobotoMono-VariableFont_wght.ttf
- asset: assets/fonts/RobotoMono-Italic-VariableFont_wght.ttf
style: italic
1 change: 1 addition & 0 deletions web/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 5 additions & 5 deletions web/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "epc_qr",
"short_name": "epc_qr",
"name": "EPC-QR Generator",
"short_name": "EPC-QR",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"background_color": "#FDFCFF",
"theme_color": "#0062A0",
"description": "Generates QR-codes for European SEPA transfers.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
Expand Down

0 comments on commit a490eb8

Please sign in to comment.