1
1
import * as core from "@actions/core" ;
2
2
import * as exec from "@actions/exec" ;
3
- import * as io from "@actions/io" ;
4
3
import * as installer from "./installer" ;
5
- import { getPlatform , OS } from "./platform" ;
4
+ import { getPlatform , Platform , OS } from "./platform" ;
6
5
import path from "path" ;
7
6
8
7
const hasErrorMessage = ( e : unknown ) : e is { message : string | Error } => {
9
8
return typeof e === "object" && e !== null && "message" in e ;
10
9
} ;
11
10
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
+
12
46
async function run ( ) : Promise < void > {
13
47
try {
14
48
const version = core . getInput ( "chrome-version" ) || "latest" ;
@@ -18,17 +52,14 @@ async function run(): Promise<void> {
18
52
19
53
const binPath = await installer . install ( platform , version ) ;
20
54
const installDir = path . dirname ( binPath ) ;
21
- const binName = path . basename ( binPath ) ;
22
55
23
56
core . addPath ( path . join ( installDir ) ) ;
24
- core . info ( `Successfully setup chromium version ${ version } ` ) ;
25
57
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 ) ;
32
63
} catch ( error ) {
33
64
if ( hasErrorMessage ( error ) ) {
34
65
core . setFailed ( error . message ) ;
0 commit comments