Skip to content

Commit

Permalink
Release/v0.0.1 dev.4 (#5)
Browse files Browse the repository at this point in the history
- Optional automatic `minSdkLevel` check and update (Android)
- Updated README
- Updated CHANGELOG (uhm... sorry about that 😅)
  • Loading branch information
yardexx authored Nov 25, 2022
1 parent 0d0d4df commit a775a63
Show file tree
Hide file tree
Showing 19 changed files with 751 additions and 38 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/brick_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@ name: Very Good Workflow
on:
pull_request:
paths:
- ".github/workflows/brick_workflow.yaml"
- "hooks/**"
- "hooks/test/**"
- "pubspec.yaml"
- "hooks/pubspec.yaml"
push:
branches:
- main
paths:
- ".github/workflows/brick_workflow.yaml"
- "hooks/**"
- "hooks/test/**"
- "pubspec.yaml"
- "hooks/pubspec.yaml"

jobs:
semantic-pull-request:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1

build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1

ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./hooks

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.5.0
- uses: dart-lang/setup-dart@v1

- name: Install Dependencies
Expand All @@ -43,7 +39,7 @@ jobs:
- name: Run Tests
run: |
dart pub global activate coverage 1.3.0
dart test --coverage=coverage && dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
dart test --coverage=coverage && dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3.1.1
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# 0.1.0+1
# 0.0.1-dev.1

- TODO: Describe initial release.
**🎉 Initial version of freerasp_brick 🎉**
## ✨ Features
- 🛠 Configuration generation
- 🎯 Dependency check using `pub get`
- 🔧 Fix apply using `dart fix`

# 0.0.1-dev.2
## ✨ New Features
- Automatic dependency fetching using `pub add`

## 🎯 Improvements
- Unified CLI prompt design
- Expanded README.md

## 🛠 Fixed issues
- Typos in README.md

# 0.0.1-dev.3
## 🎯 Improvements
- GitHub actions
- Code analysis

## 🛠 Fixed issues
- Dynamic types

# 0.0.1-dev.4
## ✨ New Features
- Optional automatic `minSdkLevel` check and update (Android)

## 🎯 Improvements
- Updated README
- Updated CHANGELOG (uhm... sorry about that 😅)
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# freerasp_brick
# freeRASP brick

<p align="center">
<a href="https://github.com/felangel/mason"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge" alt="Powered by Mason"></a>
<a href="https://pub.dev/packages/freerasp"><img src="https://img.shields.io/badge/Supported%20freeRASP-%5E3.0.0-brightgreen" alt="Supported freeRASP"/></a>
<a href="https://github.com/yardexx/freerasp_brick/actions/workflows/brick_workflow.yml"><img src="https://github.com/yardexx/freerasp_brick/actions/workflows/brick_workflow.yml/badge.svg?branch=master"/></a>
<a href="https://codecov.io/gh/yardexx/freerasp_brick"><img src="https://codecov.io/gh/yardexx/freerasp_brick/branch/master/graph/badge.svg?token=300N5C20OB"/></a>
<a href="https://pub.dev/packages/very_good_analysis"><img src="https://img.shields.io/badge/style-very_good_analysis-B22C89.svg" alt="style: very good analysis"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-purple.svg" alt="License: MIT"></a>
</p>

<p align="center">
A brick for configuration generation and automatic setup for <a href="https://pub.dev/packages/freerasp">freeRASP</a>.
A brick for <a href="https://pub.dev/packages/freerasp">freeRASP</a> to generate configuration code
and automate necessary code checks.
</p>

> 🚧 This brick is experimental and not stable! Changes to API reserved. 🚧
> 🚧 This brick is experimental and not stable! Changes to API/file generation reserved.
> ⚠ This brick is supported for mason version `>=0.1.0-dev.40`.
## Overview
Setting up freeRASP can be quite tedious and repetitive. freerasp_brick provides you error-prone
Expand All @@ -20,6 +26,7 @@ way to create configuration.
- 🛠 Configuration generation
- 🎯 Dependency check using `pub get`
- 🔧 Fix apply using `dart fix`
- 🤖 Android SDK level check and automatic update

## How to add ➕
This brick is currently **NOT** available on [brickhub.dev](https://brickhub.dev/).
Expand Down Expand Up @@ -68,15 +75,21 @@ and provide it in `freerasp.g.dart`;
| pre-gen |||
| post-gen |||

## Getting started with [freeRASP][freerasp-pubdev]
> ⚠ Brick can behave unexpectedly if pre-gen or post-gen hooks are disabled.
## Contribution 🤝
For issues, bugs, or feature proposals feel free to [open issue](https://github.com/yardexx/freerasp_brick/issues)
or [create PR](https://github.com/yardexx/freerasp_brick/pulls).

## Useful resources 📚
If this is your first touch with freeRASP or Mason, please refer to resources to get started

### Getting started with [freeRASP][freerasp-pubdev] 🛡
- [freeRASP on GitHub][freerasp-github]
- [freeRASP website][freerasp-website]
- [Medium article: freeRASP — In-App protection SDK and app security monitoring service][freerasp-medium]

## Getting started with [mason][mason-github] 🧱

If this is your first touch with mason, please refer to resources to get started:

### Getting started with [mason][mason-github] 🧱
- [Mason on GitHub][mason-github]
- [Official Mason Documentation][mason-docs]
- [Code generation with Mason Blog][mason-blog]
Expand Down
4 changes: 2 additions & 2 deletions brick.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: freerasp_brick
description: A brick for configuration generation and automatic setup for freeRASP.

version: 0.0.1-dev.1
version: 0.0.1-dev.4

environment:
mason: ">=0.1.0-dev.26 <0.1.0"
mason: ">=0.1.0-dev.40 <0.1.0"

vars:
watcher_mail:
Expand Down
1 change: 1 addition & 0 deletions hooks/errors/errors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'freerasp_brick_exception.dart';
29 changes: 29 additions & 0 deletions hooks/errors/freerasp_brick_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class FreeRaspBrickException implements Exception {
const FreeRaspBrickException({
this.code = 'brick-failure',
this.message,
this.stackTrace,
});

factory FreeRaspBrickException.wtf({
StackTrace? stackTrace,
String? message,
}) {
return FreeRaspBrickException(
message: message ?? 'Unexpected error occurred.',
stackTrace: stackTrace,
);
}

factory FreeRaspBrickException.gradleUpdateFailure({StackTrace? stackTrace}) {
return FreeRaspBrickException(
code: 'gradle-failure',
message: 'Issue occurred during update of gradle file.',
stackTrace: stackTrace,
);
}

final String code;
final String? message;
final StackTrace? stackTrace;
}
26 changes: 26 additions & 0 deletions hooks/extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// coverage:ignore-file
import 'package:mason/mason.dart';

extension LoggerX on Logger {
String masonPrompt(
String? message, {
Object? defaultValue,
bool hidden = false,
}) {
return prompt(
'${green.wrap('?')} ${message ?? ''}',
defaultValue: defaultValue,
hidden: hidden,
);
}

bool masonConfirm(
String? message, {
bool defaultValue = false,
}) {
return confirm(
'${green.wrap('?')} ${message ?? ''}',
defaultValue: defaultValue,
);
}
}
26 changes: 25 additions & 1 deletion hooks/post_gen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// coverage:ignore-file
import 'dart:io';

import 'package:mason/mason.dart';

import 'utils/gradle_updater.dart';

const String androidBuild = 'build.gradle';
const String flutterBuild = 'lib';

Expand All @@ -11,6 +14,7 @@ Future<void> run(HookContext context) async {
await _runPubAdd(logger);
await _runPubGet(logger);
await _runDartFix(logger);
await _runGradleCheck(context);
}

Future<void> _runPubAdd(Logger logger) async {
Expand Down Expand Up @@ -42,6 +46,26 @@ Future<void> _runDartFix(Logger logger) async {
final progress = logger.progress('Running dart fix --apply');
final result = await Process.run('dart', ['fix', '--apply']);
return result.exitCode == 0
? progress.complete('Fix applied.')
? progress.complete('Fix applied')
: progress.fail("Fix couldn't be applied");
}

Future<void> _runGradleCheck(HookContext context) async {
final progress = context.logger.progress('Checking build.gradle file');

if (!(context.vars['check_gradle'] as bool)) {
progress.complete('Gradle check not required. Skipping...');
return;
}

try {
final hasUpdated = gradleUpdate('android/app/build.gradle');
progress.complete(
hasUpdated
? 'build.gradle successfully updated'
: 'build.gradle already contains supported API level',
);
} catch (_) {
progress.fail("Couldn't update build.gradle");
}
}
23 changes: 9 additions & 14 deletions hooks/pre_gen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// coverage:ignore-file
import 'package:mason/mason.dart';

import 'extensions.dart';

const defaultAppPackage = 'com.example.app';

void run(HookContext context) {
Expand Down Expand Up @@ -40,22 +43,14 @@ void parseAndroidData(HookContext context) {

final signingHash = logger.masonPrompt("What's app singing hash?");

final checkGradle = logger.masonConfirm(
'Do you want to check and update API level (minSdkVersion)?',
defaultValue: true,
);

context.vars.addAll({
'package_name': packageName,
'signing_hash': signingHash,
'check_gradle': checkGradle,
});
}

extension LoggerX on Logger {
String masonPrompt(
String? message, {
Object? defaultValue,
bool hidden = false,
}) {
return prompt(
'${green.wrap('?')} ${message ?? ''}',
defaultValue: defaultValue,
hidden: hidden,
);
}
}
2 changes: 2 additions & 0 deletions hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
file: ^6.1.4
mason: ^0.1.0-dev

dev_dependencies:
test: ^1.22.0
very_good_analysis: ^3.1.0
5 changes: 5 additions & 0 deletions hooks/test/test_inputs/gradle_files/gradle_files.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'invalid/missing_key.dart';
export 'invalid/missing_value.dart';
export 'valid/supported_build.dart';
export 'valid/value_build.dart';
export 'valid/variable_build.dart';
72 changes: 72 additions & 0 deletions hooks/test/test_inputs/gradle_files/invalid/missing_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const missingKeyGradle = r'''
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
''';
Loading

0 comments on commit a775a63

Please sign in to comment.