@@ -42,6 +42,7 @@ const {
4242 fetchBuffer,
4343 fetchJsonOrNull,
4444 findBaseline,
45+ latestPlatformResults,
4546 publicUrl,
4647 reportPrefix,
4748} = require ( './storage' ) ;
@@ -50,6 +51,10 @@ const fs = require('node:fs');
5051const path = require ( 'node:path' ) ;
5152
5253const PLATFORMS = [ 'android' , 'ios' ] ;
54+ const WORKFLOW_PLATFORMS = {
55+ 'Test Android' : [ 'android' ] ,
56+ 'Test iOS' : [ 'ios' ] ,
57+ } ;
5358// The default Actions token posts as this bot. Only its comments are edited.
5459const COMMENT_AUTHOR = 'github-actions[bot]' ;
5560
@@ -61,6 +66,10 @@ function requireEnv(name) {
6166 return value ;
6267}
6368
69+ function platformsForWorkflow ( workflowName ) {
70+ return WORKFLOW_PLATFORMS [ workflowName ] ?? PLATFORMS ;
71+ }
72+
6473function writeFile ( filePath , contents ) {
6574 fs . mkdirSync ( path . dirname ( filePath ) , { recursive : true } ) ;
6675 fs . writeFileSync ( filePath , contents ) ;
@@ -231,7 +240,7 @@ function missingCapture(platform, context) {
231240 results : [ ] ,
232241 error : {
233242 title : 'no capture' ,
234- summary : `Test All run ${ context . runId } has no ${ platform } capture, so there is nothing to compare. Its capture job failed or didn't run: check the run for a build or capture failure.` ,
243+ summary : `Run ${ context . runId } has no ${ platform } capture, so there is nothing to compare. Its capture job failed or didn't run: check the run for a build or capture failure.` ,
235244 } ,
236245 } ;
237246}
@@ -299,7 +308,9 @@ async function prepare() {
299308 const prefix = reportPrefix ( context ) ;
300309
301310 const platforms = [ ] ;
302- for ( const expectedPlatform of PLATFORMS ) {
311+ for ( const expectedPlatform of platformsForWorkflow (
312+ process . env . CAPTURE_WORKFLOW ,
313+ ) ) {
303314 const captureDir = path . join (
304315 artifactsDir ,
305316 `visual-capture-${ expectedPlatform } ` ,
@@ -367,6 +378,27 @@ async function prepare() {
367378 }
368379}
369380
381+ function imageUrlFor ( publicBaseUrl , platform , prefix ) {
382+ const expectedById = new Map (
383+ platform . results
384+ . filter ( result => result . expected != null )
385+ . map ( result => [ result . id , result . expected ] ) ,
386+ ) ;
387+ return ( kind , id ) =>
388+ kind === 'expected'
389+ ? publicUrl (
390+ publicBaseUrl ,
391+ baselineImageKey (
392+ { environmentKey : platform . environmentKey , ...platform . baseline } ,
393+ expectedById . get ( id ) ,
394+ ) ,
395+ )
396+ : publicUrl (
397+ publicBaseUrl ,
398+ `${ prefix } /${ platform . platform } /${ kind } /${ id } .png` ,
399+ ) ;
400+ }
401+
370402async function report ( ) {
371403 const github = createGitHubClient ( ) ;
372404 const outDir = requireEnv ( 'OUT_DIR' ) ;
@@ -377,30 +409,13 @@ async function report() {
377409 if ( state == null ) {
378410 return ;
379411 }
380- const { context, reportPrefix : prefix , fingerprint } = state ;
412+ const { context, reportPrefix : prefix } = state ;
381413 const detailsUrl = publicUrl ( publicBaseUrl , `${ prefix } /results.json` ) ;
382414
383415 const summaryLines = [ ] ;
384- const commentPlatforms = [ ] ;
416+ const checkUrls = new Map ( ) ;
385417 for ( const platform of state . platforms ) {
386- const expectedById = new Map (
387- platform . results
388- . filter ( result => result . expected != null )
389- . map ( result => [ result . id , result . expected ] ) ,
390- ) ;
391- const imageUrl = ( kind , id ) =>
392- kind === 'expected'
393- ? publicUrl (
394- publicBaseUrl ,
395- baselineImageKey (
396- { environmentKey : platform . environmentKey , ...platform . baseline } ,
397- expectedById . get ( id ) ,
398- ) ,
399- )
400- : publicUrl (
401- publicBaseUrl ,
402- `${ prefix } /${ platform . platform } /${ kind } /${ id } .png` ,
403- ) ;
418+ const imageUrl = imageUrlFor ( publicBaseUrl , platform , prefix ) ;
404419 const output = renderCheckOutput ( { ...platform , imageUrl} ) ;
405420 const { hasDifferences} = summarize ( platform . results ) ;
406421 const checkRun = await github . createCheckRun ( {
@@ -415,7 +430,7 @@ async function report() {
415430 output,
416431 detailsUrl,
417432 } ) ;
418- commentPlatforms . push ( { ... platform , imageUrl , checkUrl : checkRun . html_url } ) ;
433+ checkUrls . set ( platform . platform , checkRun . html_url ) ;
419434 summaryLines . push (
420435 `## ${ output . title } ` ,
421436 '' ,
@@ -427,6 +442,32 @@ async function report() {
427442 }
428443
429444 if ( context . kind === 'pull' ) {
445+ const platforms = await latestPlatformResults ( {
446+ bucket : requireEnv ( 'VISUAL_BUCKET' ) ,
447+ publicBaseUrl,
448+ prNumber : context . prNumber ,
449+ headSha : context . headSha ,
450+ current : state ,
451+ } ) ;
452+ const fingerprint = differenceFingerprint ( platforms ) ;
453+ const commentPlatforms = [ ] ;
454+ for ( const platform of platforms ) {
455+ const checkUrl =
456+ checkUrls . get ( platform . platform ) ??
457+ (
458+ await github . findCheckRun (
459+ context . headSha ,
460+ `${ CHECK_NAME_PREFIX } (${ platform . platform } )` ,
461+ )
462+ ) ?. html_url ??
463+ publicUrl ( publicBaseUrl , `${ platform . reportPrefix } /results.json` ) ;
464+ commentPlatforms . push ( {
465+ ...platform ,
466+ imageUrl : imageUrlFor ( publicBaseUrl , platform , platform . reportPrefix ) ,
467+ checkUrl,
468+ } ) ;
469+ }
470+
430471 const labels = await github . labels ( context . prNumber ) ;
431472 const approval =
432473 fingerprint == null
@@ -511,4 +552,9 @@ if (require.main === module) {
511552 } ) ;
512553}
513554
514- module . exports = { comparePlatform, resolveContext, stageBaseline} ;
555+ module . exports = {
556+ comparePlatform,
557+ platformsForWorkflow,
558+ resolveContext,
559+ stageBaseline,
560+ } ;
0 commit comments