Unverified Commit d0491dcf authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add the `channel` parameter to the Dartpad samples (#115018)

* Add the channel paramter to the Dartpad samples

* Add sanity check test

* Make sample_id more generic
parent dccc761e
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</p> </p>
</div> </div>
<iframe class="snippet-dartpad" <iframe class="snippet-dartpad"
src="https://dartpad.dev/embed-flutter.html?split=60&amp;run=true&amp;null_safety=true&amp;sample_id={{id}}&amp;sample_channel={{channel}}"> src="https://dartpad.dev/embed-flutter.html?split=60&amp;run=true&amp;null_safety=true&amp;sample_id={{id}}&amp;sample_channel={{channel}}&amp;channel={{channel}}">
</iframe> </iframe>
</div> </div>
{@end-inject-html} {@end-inject-html}
\ No newline at end of file
...@@ -394,7 +394,7 @@ void _sanityCheckExample(String fileString, String regExpString) { ...@@ -394,7 +394,7 @@ void _sanityCheckExample(String fileString, String regExpString) {
final RegExp regExp = RegExp(regExpString, dotAll: true); final RegExp regExp = RegExp(regExpString, dotAll: true);
final String contents = file.readAsStringSync(); final String contents = file.readAsStringSync();
if (!regExp.hasMatch(contents)) { if (!regExp.hasMatch(contents)) {
throw Exception("Missing example code in ${file.path}. Either it didn't get published, publishing has changed, or the example no longer exists."); throw Exception("Missing example code matching '$regExpString' in ${file.path}.");
} }
} else { } else {
throw Exception( throw Exception(
...@@ -403,7 +403,7 @@ void _sanityCheckExample(String fileString, String regExpString) { ...@@ -403,7 +403,7 @@ void _sanityCheckExample(String fileString, String regExpString) {
} }
/// Runs a sanity check by running a test. /// Runs a sanity check by running a test.
void sanityCheckDocs() { void sanityCheckDocs([Platform platform = const LocalPlatform()]) {
final List<String> canaries = <String>[ final List<String> canaries = <String>[
'$kPublishRoot/assets/overrides.css', '$kPublishRoot/assets/overrides.css',
'$kPublishRoot/api/dart-io/File-class.html', '$kPublishRoot/api/dart-io/File-class.html',
...@@ -414,6 +414,7 @@ void sanityCheckDocs() { ...@@ -414,6 +414,7 @@ void sanityCheckDocs() {
'$kPublishRoot/api/material/Material-class.html', '$kPublishRoot/api/material/Material-class.html',
'$kPublishRoot/api/material/Tooltip-class.html', '$kPublishRoot/api/material/Tooltip-class.html',
'$kPublishRoot/api/widgets/Widget-class.html', '$kPublishRoot/api/widgets/Widget-class.html',
'$kPublishRoot/api/widgets/Listener-class.html',
]; ];
for (final String canary in canaries) { for (final String canary in canaries) {
if (!File(canary).existsSync()) { if (!File(canary).existsSync()) {
...@@ -434,11 +435,28 @@ void sanityCheckDocs() { ...@@ -434,11 +435,28 @@ void sanityCheckDocs() {
r'\s*<pre.*id="sample-code">.*Color\s+get\s+barrierColor.*</pre>', r'\s*<pre.*id="sample-code">.*Color\s+get\s+barrierColor.*</pre>',
); );
// Check a "dartpad" example, any one will do. // Check a "dartpad" example, any one will do, and check for the correct URL
// arguments.
// Just use "master" for any branch other than the LUCH_BRANCH.
final String? luciBranch = platform.environment['LUCI_BRANCH']?.trim();
final String expectedBranch = luciBranch != null && luciBranch.isNotEmpty ? luciBranch : 'master';
final List<String> argumentRegExps = <String>[
r'split=\d+',
r'run=true',
r'null_safety=true',
r'sample_id=widgets\.Listener\.\d+',
'sample_channel=$expectedBranch',
'channel=$expectedBranch',
];
for (final String argumentRegExp in argumentRegExps) {
_sanityCheckExample( _sanityCheckExample(
'$kPublishRoot/api/widgets/PhysicalShape-class.html', '$kPublishRoot/api/widgets/Listener-class.html',
r'\s*<iframe\s+class="snippet-dartpad"\s+src="https://dartpad\.dev.*sample_id=widgets\.PhysicalShape\.\d+.*">\s*</iframe>', r'\s*<iframe\s+class="snippet-dartpad"\s+src="'
r'https:\/\/dartpad.dev\/embed-flutter.html\?.*?\b'
'$argumentRegExp'
r'\b.*">\s*<\/iframe>',
); );
}
} }
/// Creates a custom index.html because we try to maintain old /// Creates a custom index.html because we try to maintain old
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment