mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Add workflow to deploy the sample index (#791)
* Add workflow to build and deploy the sample index * update gh-pages action * fix yaml * create web/ directory in build * grammar * add ignored directories * revert pubspec.lock files * add job to run _tool/verify_samples.dart * Update filipino_cuisine for Flutter 2 * remove timeflow demo. The unnamed List constructor is now deprecated, refactoring this code to use add() requires more knowledge about the code for this demo. https://dart.dev/null-safety/understanding-null-safety#no-unnamed-list-constructor * update slide_puzzle * ensure stable channel is used to verify * move verify web demos action into separate yaml file - avoid running on each flutter version. * add on: pull_request * update slide_puzzle * Update gh-pages.yml * Add copyright header
This commit is contained in:
43
web/_tool/build_ci.dart
Normal file
43
web/_tool/build_ci.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'common.dart';
|
||||
|
||||
final ignoredDirectories = ['_tool', 'samples_index'];
|
||||
|
||||
main() async {
|
||||
final packageDirs = [
|
||||
...listPackageDirs(Directory.current)
|
||||
.map((path) => p.relative(path, from: Directory.current.path))
|
||||
.where((path) => !ignoredDirectories.contains(path))
|
||||
];
|
||||
|
||||
print('Building the sample index...');
|
||||
await run('samples_index', 'pub', ['get']);
|
||||
await run('samples_index', 'pub', ['run', 'grinder', 'deploy']);
|
||||
|
||||
// Create the directory each Flutter Web sample lives in
|
||||
Directory(p.join(Directory.current.path, 'samples_index', 'public', 'web'))
|
||||
.createSync(recursive: true);
|
||||
|
||||
for (var i = 0; i < packageDirs.length; i++) {
|
||||
var directory = packageDirs[i];
|
||||
|
||||
logWrapped(ansiMagenta, '\n$directory (${i + 1} of ${packageDirs.length})');
|
||||
|
||||
// Create the target directory
|
||||
var directoryName = p.basename(directory);
|
||||
var sourceBuildDir =
|
||||
p.join(Directory.current.path, directory, 'build', 'web');
|
||||
var targetDirectory = p.join(Directory.current.path, 'samples_index',
|
||||
'public', 'web', directoryName);
|
||||
|
||||
// Build the sample and copy the files
|
||||
await run(directory, 'flutter', ['pub', 'get']);
|
||||
await run(directory, 'flutter', ['build', 'web']);
|
||||
await run(directory, 'mv', [sourceBuildDir, targetDirectory]);
|
||||
}
|
||||
}
|
||||
@@ -36,3 +36,16 @@ Future<bool> run(
|
||||
void logWrapped(int code, String message) {
|
||||
print('\x1B[${code}m$message\x1B[0m');
|
||||
}
|
||||
|
||||
Iterable<String> listPackageDirs(Directory dir) sync* {
|
||||
if (File('${dir.path}/pubspec.yaml').existsSync()) {
|
||||
yield dir.path;
|
||||
} else {
|
||||
for (var subDir in dir
|
||||
.listSync(followLinks: true)
|
||||
.whereType<Directory>()
|
||||
.where((d) => !Uri.file(d.path).pathSegments.last.startsWith('.'))) {
|
||||
yield* listPackageDirs(subDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
const _ansiGreen = 32;
|
||||
const _ansiRed = 31;
|
||||
const _ansiMagenta = 35;
|
||||
|
||||
void main() async {
|
||||
final packageDirs = _listPackageDirs(Directory.current)
|
||||
final packageDirs = listPackageDirs(Directory.current)
|
||||
.map((path) => p.relative(path, from: Directory.current.path))
|
||||
.toList();
|
||||
|
||||
@@ -21,7 +18,7 @@ void main() async {
|
||||
final results = <bool>[];
|
||||
for (var i = 0; i < packageDirs.length; i++) {
|
||||
final dir = packageDirs[i];
|
||||
logWrapped(_ansiMagenta, '\n$dir (${i + 1} of ${packageDirs.length})');
|
||||
logWrapped(ansiMagenta, '\n$dir (${i + 1} of ${packageDirs.length})');
|
||||
results.add(await run(dir, 'flutter', [
|
||||
'pub',
|
||||
'pub',
|
||||
@@ -46,19 +43,6 @@ void _printStatus(List<bool> results) {
|
||||
var success = (successCount == results.length);
|
||||
var pct = 100 * successCount / results.length;
|
||||
|
||||
logWrapped(success ? _ansiGreen : _ansiRed,
|
||||
logWrapped(success ? ansiGreen : ansiRed,
|
||||
'$successCount of ${results.length} (${pct.toStringAsFixed(2)}%)');
|
||||
}
|
||||
|
||||
Iterable<String> _listPackageDirs(Directory dir) sync* {
|
||||
if (File('${dir.path}/pubspec.yaml').existsSync()) {
|
||||
yield dir.path;
|
||||
} else {
|
||||
for (var subDir in dir
|
||||
.listSync(followLinks: true)
|
||||
.whereType<Directory>()
|
||||
.where((d) => !Uri.file(d.path).pathSegments.last.startsWith('.'))) {
|
||||
yield* _listPackageDirs(subDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user