@@ -23,69 +23,65 @@ public async Task GeneratePdf()
2323
2424 string ? isGitHubActions = Environment . GetEnvironmentVariable ( "RUNNING_ON_GITHUB_ACTIONS" ) ;
2525
26- // the PDF generation with puppeteer is currently not working in GitHub Actions
27- if ( isGitHubActions != null )
26+
27+ if ( File . Exists ( FilePath ) )
28+ File . Delete ( FilePath ) ;
29+
30+ OperatingSystem ? os = Environment . OSVersion ;
31+
32+ Log . WriteInfo ( "Test Log" , $ "OS: { os } ") ;
33+
34+ string path = "" ;
35+ BrowserFetcher ? browserFetcher = default ;
36+
37+ switch ( os . Platform )
2838 {
29- if ( File . Exists ( FilePath ) )
30- File . Delete ( FilePath ) ;
31-
32- OperatingSystem ? os = Environment . OSVersion ;
33-
34- Log . WriteInfo ( "Test Log" , $ "OS: { os } ") ;
35-
36- string path = "" ;
37- BrowserFetcher ? browserFetcher = default ;
38-
39- switch ( os . Platform )
40- {
41- case PlatformID . Win32NT :
42- browserFetcher = new ( ) ;
43- break ;
44- case PlatformID . Unix :
45- path = ChromeBinPathLinux ;
46- browserFetcher = new ( new BrowserFetcherOptions { Path = path , Platform = Platform . Linux , Browser = SupportedBrowser . Chrome } ) ;
47- break ;
48- default :
39+ case PlatformID . Win32NT :
40+ browserFetcher = new ( ) ;
41+ break ;
42+ case PlatformID . Unix :
43+ path = ChromeBinPathLinux ;
44+ browserFetcher = new ( new BrowserFetcherOptions { Path = path , Platform = Platform . Linux , Browser = SupportedBrowser . Chrome } ) ;
45+ break ;
46+ default :
4947 break ;
50- }
51-
52- InstalledBrowser ? brw = await browserFetcher . DownloadAsync ( BrowserTag . Stable ) ;
53-
54- using IBrowser ? browser = await Puppeteer . LaunchAsync ( new LaunchOptions
55- {
56- ExecutablePath = isGitHubActions != null ? "/usr/bin/chromium-browser" : brw . GetExecutablePath ( ) ,
57- Headless = true ,
58- DumpIO = isGitHubActions != null ? true : false , // Enables debug logs
59- //Args = isGitHubActions!=null ?
60- // new[] { "--no-sandbox", "--database=/tmp", "--disable-setuid-sandbox" }
61- // : [] // No additional arguments locally
62- } ) ;
63-
64- try
65- {
66- await TryCreatePDF ( browser , PaperFormat . A0 ) ;
67- await TryCreatePDF ( browser , PaperFormat . A1 ) ;
68- await TryCreatePDF ( browser , PaperFormat . A2 ) ;
69- await TryCreatePDF ( browser , PaperFormat . A3 ) ;
70- await TryCreatePDF ( browser , PaperFormat . A4 ) ;
71- await TryCreatePDF ( browser , PaperFormat . A5 ) ;
72- await TryCreatePDF ( browser , PaperFormat . A6 ) ;
73-
74- await TryCreatePDF ( browser , PaperFormat . Ledger ) ;
75- await TryCreatePDF ( browser , PaperFormat . Legal ) ;
76- await TryCreatePDF ( browser , PaperFormat . Letter ) ;
77- await TryCreatePDF ( browser , PaperFormat . Tabloid ) ;
78- }
79- catch ( Exception )
80- {
81- throw ;
82- }
83- finally
84- {
85- await browser . CloseAsync ( ) ;
86- }
8748 }
8849
50+ InstalledBrowser ? brw = await browserFetcher . DownloadAsync ( BrowserTag . Stable ) ;
51+
52+ using IBrowser ? browser = await Puppeteer . LaunchAsync ( new LaunchOptions
53+ {
54+ ExecutablePath = isGitHubActions != null ? "/usr/bin/chromium-browser" : brw . GetExecutablePath ( ) ,
55+ Headless = true ,
56+ DumpIO = isGitHubActions != null ? true : false , // Enables debug logs
57+ //Args = isGitHubActions!=null ?
58+ // new[] { "--no-sandbox", "--database=/tmp", "--disable-setuid-sandbox" }
59+ // : [] // No additional arguments locally
60+ } ) ;
61+
62+ try
63+ {
64+ await TryCreatePDF ( browser , PaperFormat . A0 ) ;
65+ await TryCreatePDF ( browser , PaperFormat . A1 ) ;
66+ await TryCreatePDF ( browser , PaperFormat . A2 ) ;
67+ await TryCreatePDF ( browser , PaperFormat . A3 ) ;
68+ await TryCreatePDF ( browser , PaperFormat . A4 ) ;
69+ await TryCreatePDF ( browser , PaperFormat . A5 ) ;
70+ await TryCreatePDF ( browser , PaperFormat . A6 ) ;
71+
72+ await TryCreatePDF ( browser , PaperFormat . Ledger ) ;
73+ await TryCreatePDF ( browser , PaperFormat . Legal ) ;
74+ await TryCreatePDF ( browser , PaperFormat . Letter ) ;
75+ await TryCreatePDF ( browser , PaperFormat . Tabloid ) ;
76+ }
77+ catch ( Exception )
78+ {
79+ throw ;
80+ }
81+ finally
82+ {
83+ await browser . CloseAsync ( ) ;
84+ }
8985 }
9086
9187 private static bool IsValidHTML ( string html )
@@ -124,7 +120,7 @@ private async Task TryCreatePDF(IBrowser browser, PaperFormat paperFormat)
124120 catch ( Exception )
125121 {
126122 throw new Exception ( "This paper kind is currently not supported. Please choose another one or \" Custom\" for a custom size." ) ;
127- }
123+ }
128124 }
129125
130126 [ OneTimeTearDown ]
0 commit comments