Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Build Dart with Gradle
apply plugin: 'base'
//-------------------------------------------------------------------------------------------------
// Analyze
task update() {
doLast {
exec { executable = 'pub'; args = [ "update" ] }
}
}
task analyzePackage(
group: "analyze") {
mustRunAfter update
doLast {
[
"lib/components.dart",
"lib/components/interfaces/actions.dart",
"lib/components/interfaces/stores.dart",
"lib/dialogs.dart",
"lib/events.dart",
"lib/model.dart",
"lib/proxies.dart",
"lib/stores.dart",
"lib/mock.dart",
"lib/validation.dart",
"lib/services/device/DeviceService.dart",
"lib/services/job/JobService.dart",
"lib/services/job/LocalJobService.dart",
"lib/services/job/LocalMediaService.dart",
"lib/services/job/MediaService.dart",
"lib/services/upload/UploadServiceForZip.dart",
"lib/services/utils/fire_event_mixins.dart",
"lib/services/utils/ListSync.dart",
"lib/services/stats/StatsService.dart",
"lib/services/LoginService.dart"
].each {
def file = it
exec { executable = 'dartanalyzer'; args = [ file ] }
}
}
}
task analyzeTests(
group: "analyze") {
mustRunAfter update
doLast {
def root= new File('.').getCanonicalFile()
def tree = fileTree(dir: 'test')
// Add include and exclude patterns to the tree
tree.include '**/*.dart'
tree.exclude 'integration/_utils/utils.dart'
tree.each { File testFile ->
def file = root.toPath().relativize(testFile.toPath())
exec { executable = 'dartanalyzer'; args = [ file ] }
}
}
}
task analyzeSamples(
group: "analyze") {
mustRunAfter update
doLast {
def root= new File('.').getCanonicalFile()
def tree = fileTree(dir: 'samples')
// Add include and exclude patterns to the tree
tree.include '**/main.dart'
//tree.exclude '**/Abstract*'
tree.each { File testFile ->
def file = root.toPath().relativize(testFile.toPath())
//println(file);
exec { executable = 'dartanalyzer'; args = [ file ] }
}
}
}
task analyze(
group: "analyze",
description: "Analyze Dart-Script")
analyze.dependsOn update, analyzePackage, analyzeTests /*, analyzeSamples*/
//-------------------------------------------------------------------------------------------------
// Build
task sitegen() {
doLast {
exec { executable = 'sitegen'; args = ['-c'] }
}
}
task pubBuild(
dependsOn: sitegen ) {
def outputDirectory = "docker/server/static/config/usr/share/nginx"
doLast {
exec { executable = 'pub'; args = ['build', "--output", outputDirectory ] }
}
}
build.dependsOn pubBuild
//-------------------------------------------------------------------------------------------------
// Tests
task pullContainer() {
doLast {
exec {
executable = 'docker/_ci/run.sh'
args = ['--pull']
}
}
}
task startContainer(dependsOn: pullContainer) {
doLast {
exec {
executable = 'docker/_ci/run.sh'
args = ['--start']
}
}
}
task stopContainer() {
doLast {
exec {
executable = 'docker/_ci/run.sh'
args = ['--stop']
}
}
}
task testUnit(
group: "test",
description: "Runs Dart-Unit-Tests",
type: Exec) {
executable = "pub"
args = ["run", "test", "test/unit" ]
}
task testIntegration(
group: "test",
description: "Runs Dart-Integration-Tests",
type: Exec) {
mustRunAfter testUnit
executable = "pub"
args = ["run", "test", "test/integration" ]
}
task test(
group: "test",
description: "Runs Dart-Tests"
)
testIntegration.dependsOn startContainer
testIntegration.finalizedBy stopContainer
test.dependsOn /*analyze,*/ testUnit , testIntegration
//-------------------------------------------------------------------------------------------------
// Docker
// Versionsnummer von Git für Docker
task versionNumberForDocker() {
doLast {
exec { executable = 'tool/scripts/create_tag4docker'; args = [] }
}
}
// Hostname wird auf den AWS-Hostname geändert
task setHostnameToAWSHostname() {
doLast {
exec { executable = 'tool/scripts/set_host_in_service_config'; args = [] }
}
}
task buildDockerImage(
group: "build",
dependsOn: [ versionNumberForDocker, setHostnameToAWSHostname ] ) {
doLast {
exec { executable = 'docker/server/nginx/build'; args = [ '--build'] }
}
}
task pushImageToAWS(
group: "build",
dependsOn: [ buildDockerImage ] ) {
mustRunAfter buildDockerImage
doLast {
exec { executable = 'docker/server/nginx/build'; args = [ '--push'] }
}
}
task deployToDocker(dependsOn: [ buildDockerImage ])
//-------------------------------------------------------------------------------------------------
// DockerContainer + Debian-Package wird automatisch erstellt
//clean.dependsOn cleanAptlyFolders, cleanPGPFolders, cleanDebian
task deploy(dependsOn: [
build, analyze, test , buildDockerImage, pushImageToAWS ]
) {
doLast {
logger.lifecycle("\nSuccessfully deployed ${rootProject.name}")
}
}
import 'dart:core';
import 'package:grinder/grinder.dart';
import 'package:grinder/grinder_tools.dart';
import 'package:path/path.dart' as path;
import 'package:http/http.dart' as http;
import 'package:docker/docker.dart';
import 'dart:async';
final String containerNameToCheck = " mobiad-db-production";
main(final List<String> args) => grind(args);
@Task()
//@Depends(genCss,test)
@Depends(genCss)
build() {
Pub.build(outputDirectory: "docker/server/static/config/usr/share/nginx");
}
@Task()
@Depends(analyze,testUnit,testIntegration)
test() { }
@Task()
testUnit() {
new TestRunner().testAsync(files: "test/unit");
// Alle test mit @TestOn("browser") im header
new TestRunner().testAsync(files: "test/unit",platformSelector: "chrome");
}
@Task()
@Depends(initDb)
testIntegration() async {
await new TestRunner().testAsync(files: "test/integration");
// Alle test mit @TestOn("content-shell") im header
await new TestRunner().testAsync(files: "test/integration",platformSelector: "chrome",concurrency: 1);
}
@Task()
analyze() {
final List<String> libs = [
"lib/components.dart",
"lib/components/interfaces/actions.dart",
"lib/components/interfaces/stores.dart",
"lib/dialogs.dart",
"lib/events.dart",
"lib/model.dart",
"lib/proxies.dart",
"lib/stores.dart",
"lib/mock.dart",
"lib/validation.dart",
"lib/services/device/DeviceService.dart",
"lib/services/job/JobService.dart",
"lib/services/job/LocalJobService.dart",
"lib/services/job/LocalMediaService.dart",
"lib/services/job/MediaService.dart",
"lib/services/upload/UploadServiceForZip.dart",
"lib/services/utils/fire_event_mixins.dart",
"lib/services/utils/ListSync.dart",
"lib/services/stats/StatsService.dart",
"lib/services/LoginService.dart"
];
final List<String> samples = [
"mmui_connections/web/main.dart",
"mmui_device/web/main.dart",
"mmui_device_details/web/main.dart",
"mmui_image/web/main.dart",
"mmui_job/web/main.dart",
"mmui_jobedit/web/main.dart",
"mmui_jobtoolbar/web/main.dart",
"mmui_locationedit/web/main.dart",
"mmui_login/web/main.dart",
"mmui_zipupload/web/main.dart"
];
libs.forEach((final String lib) => Analyzer.analyze(lib));
samples.forEach((final String sample ) {
final String sampleFolder = sample.replaceAll("/web/main.dart","");
run("tool/scripts/analyze-sample.sh",arguments: [ "samples/${sampleFolder}", "web/main.dart" ]);
});
Analyzer.analyze("test");
Analyzer.analyze("web/main.dart");
}
@Task()
genCss() {
run("/Users/mikemitterer/.pub-cache/bin/sitegen", arguments: [ "-c" ]);
}
@Task()
genDemoCss() {
final String src = "example/_assets/assets/styles/demo.scss";
final String target = "${path.withoutExtension(src)}.css";
run("sassc", arguments: [ src, target ] );
}
@Task("Stops containers")
dockerStopp() {
["db-webappbase-test", containerNameToCheck ].forEach((final String container) {
log("Stopping container: $container");
new Docker()..stop([container ],quiet: true);
});
}
@Task("Start container")
dockerStart() {
new Docker()..start([ containerNameToCheck ],quiet: true);
}
@Task("Check if container runs and if container is available")
containerCheck() async {
final Docker docker = new Docker();
// [ "db-webappbase-test"].forEach((final String name) => docker.stop([ name ]));
docker.start([ containerNameToCheck] );
final Container container = new Container(runningContainerIDs());
container.names.forEach((final String name) {
log("Active containers: ${name}");
});
if(!container.names.contains(containerNameToCheck)) {
throw new ArgumentError("${containerNameToCheck} must be running for this test!");
}
}
@Task("Initializes DB on server")
//@Depends(containerCheck)
initDb() async {
final String url = "https://mobiad.int.mikemitterer.at:8080/api/v1/admin/database";
final http.Response response = await http.post(url, headers: {
'Accept' : 'application/json'
});
log("Server-DB init returned status: ${response.statusCode}");
log("Waiting 2secs...");
await new Future.delayed(new Duration(seconds: 2));
log("Done!");
}
@Task()
clean() => defaultClean();
@Task()
@Depends(build)
deploy() {
// Versionsnummer von Git für Docker
run("tool/scripts/create_tag4docker");
// Hostname wird auf den AWS-Hostname geändert
run("tool/scripts/set_host_in_service_config");
// Docker build
runAsync("docker/server/nginx/build",arguments: [ "--build" ] ,quiet: false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment