11import * as core from "@actions/core" ;
22import * as exec from "@actions/exec" ;
3- import * as io from "@actions/io" ;
43import * as installer from "./installer" ;
5- import { getPlatform , OS } from "./platform" ;
4+ import { getPlatform , Platform , OS } from "./platform" ;
65import path from "path" ;
76
87const hasErrorMessage = ( e : unknown ) : e is { message : string | Error } => {
98 return typeof e === "object" && e !== null && "message" in e ;
109} ;
1110
11+ const testVersion = async (
12+ platform : Platform ,
13+ bin : string
14+ ) : Promise < string > => {
15+ if ( platform . os === OS . WINDOWS ) {
16+ const output = await exec . getExecOutput ( `powershell` , [
17+ "-Command" ,
18+ `(Get-Item (Get-Command '${ bin } ').Source).VersionInfo.ProductVersion` ,
19+ ] ) ;
20+ if ( output . exitCode !== 0 ) {
21+ throw new Error (
22+ `shell exits with status ${ output . exitCode } : ${ output . stderr } `
23+ ) ;
24+ }
25+ return output . stdout . trimStart ( ) . trimEnd ( ) ;
26+ }
27+
28+ const output = await exec . getExecOutput ( `"${ bin } "` , [ "--version" ] , { } ) ;
29+ if ( output . exitCode !== 0 ) {
30+ throw new Error (
31+ `chromium exits with status ${ output . exitCode } : ${ output . stderr } `
32+ ) ;
33+ }
34+ if (
35+ ! output . stdout . startsWith ( "Chromium " ) &&
36+ ! output . stdout . startsWith ( "Google Chrome " )
37+ ) {
38+ throw new Error ( `chromium outputs unexpected results: ${ output . stdout } ` ) ;
39+ }
40+ return output . stdout
41+ . replace ( "Chromium " , "" )
42+ . replace ( "Google Chrome " , "" )
43+ . split ( " " , 1 ) [ 0 ] ;
44+ } ;
45+
1246async function run ( ) : Promise < void > {
1347 try {
1448 const version = core . getInput ( "chrome-version" ) || "latest" ;
@@ -18,17 +52,14 @@ async function run(): Promise<void> {
1852
1953 const binPath = await installer . install ( platform , version ) ;
2054 const installDir = path . dirname ( binPath ) ;
21- const binName = path . basename ( binPath ) ;
2255
2356 core . addPath ( path . join ( installDir ) ) ;
24- core . info ( `Successfully setup chromium version ${ version } ` ) ;
2557
26- if ( platform . os === OS . WINDOWS ) {
27- // Unable to run with command-line option on windows
28- await io . which ( "chrome" , true ) ;
29- } else if ( platform . os === OS . DARWIN || platform . os === OS . LINUX ) {
30- await exec . exec ( binName , [ "--version" ] ) ;
31- }
58+ const actualVersion = await testVersion ( platform , binPath ) ;
59+
60+ core . info ( `Successfully setup chromium version ${ actualVersion } ` ) ;
61+
62+ core . setOutput ( "chrome-version" , actualVersion ) ;
3263 } catch ( error ) {
3364 if ( hasErrorMessage ( error ) ) {
3465 core . setFailed ( error . message ) ;
0 commit comments