@@ -11,21 +11,22 @@ const dstdir = (() => {
1111 fs . accessSync ( '/usr/local/bin' , fs . constants . W_OK ) ;
1212 return '/usr/local/bin' ;
1313 } catch ( err ) {
14- return path . join ( process . env . INPUT_PKGX_DIR || path . join ( process . env . HOME , '.pkgx' ) , 'bin' ) ;
14+ return path . join ( process . env . INPUT_PKGX_DIR || path . join ( os . homedir ( ) , '.pkgx' ) , 'bin' ) ;
1515 }
1616} ) ( ) ;
1717
1818fs . writeFileSync ( process . env [ "GITHUB_PATH" ] , `${ dstdir } \n` ) ;
1919
2020function platform_key ( ) {
21- const platform = os . platform ( ) ; // 'darwin', 'linux', 'win32', etc.
21+ let platform = os . platform ( ) ; // 'darwin', 'linux', 'win32', etc.
22+ if ( platform == 'win32' ) platform = 'windows' ;
2223 let arch = os . arch ( ) ; // 'x64', 'arm64', etc.
2324 if ( arch == 'x64' ) arch = 'x86-64' ;
2425 if ( arch == 'arm64' ) arch = 'aarch64' ;
2526 return `${ platform } /${ arch } ` ;
2627}
2728
28- function downloadAndExtract ( url , destination ) {
29+ function downloadAndExtract ( url , destination , strip ) {
2930 return new Promise ( ( resolve , reject ) => {
3031 https . get ( url , ( response ) => {
3132 if ( response . statusCode !== 200 ) {
@@ -35,7 +36,7 @@ function downloadAndExtract(url, destination) {
3536
3637 console . log ( `extracting tarball…` ) ;
3738
38- const tar_stream = tar . x ( { cwd : destination , strip : 3 } ) ;
39+ const tar_stream = tar . x ( { cwd : destination , strip } ) ;
3940
4041 response
4142 . pipe ( tar_stream ) // Extract directly to destination
@@ -86,34 +87,47 @@ function parse_pkgx_output(output) {
8687}
8788
8889async function install_pkgx ( ) {
89- let url = `https://dist.pkgx.dev/pkgx.sh/ ${ platform_key ( ) } /versions.txt` ;
90+ let strip = 3 ;
9091
91- console . log ( `::group::installing ${ dstdir } /pkgx` ) ;
92- console . log ( `fetching ${ url } ` ) ;
92+ async function get_url ( ) {
93+ if ( platform_key ( ) . startsWith ( 'windows' ) ) {
94+ // not yet versioned
95+ strip = 0 ;
96+ return 'https://pkgx.sh/Windows/x86_64.tgz' ;
97+ }
98+
99+ let url = `https://dist.pkgx.dev/pkgx.sh/${ platform_key ( ) } /versions.txt` ;
100+
101+ console . log ( `fetching ${ url } ` ) ;
93102
94- const rsp = await fetch ( url ) ;
95- const txt = await rsp . text ( ) ;
103+ const rsp = await fetch ( url ) ;
104+ const txt = await rsp . text ( ) ;
96105
97- const versions = txt . split ( '\n' ) ;
98- const version = process . env . INPUT_VERSION
99- ? semver . maxSatisfying ( versions , process . env . INPUT_VERSION )
100- : versions . slice ( - 1 ) [ 0 ] ;
106+ const versions = txt . split ( '\n' ) ;
107+ const version = process . env . INPUT_VERSION
108+ ? semver . maxSatisfying ( versions , process . env . INPUT_VERSION )
109+ : versions . slice ( - 1 ) [ 0 ] ;
101110
102- if ( ! version ) {
103- throw new Error ( `no version found for ${ process . env . INPUT_VERSION } ` ) ;
111+ if ( ! version ) {
112+ throw new Error ( `no version found for ${ process . env . INPUT_VERSION } ` ) ;
113+ }
114+
115+ console . log ( `selected pkgx v${ version } ` ) ;
116+
117+ return `https://dist.pkgx.dev/pkgx.sh/${ platform_key ( ) } /v${ version } .tar.gz` ;
104118 }
105119
106- console . log ( `selected pkgx v ${ version } ` ) ;
120+ console . log ( `::group::installing ${ path . join ( dstdir , 'pkgx' ) } ` ) ;
107121
108- url = `https://dist.pkgx.dev/pkgx.sh/ ${ platform_key ( ) } /v ${ version } .tar.gz` ;
122+ const url = await get_url ( ) ;
109123
110124 console . log ( `fetching ${ url } ` ) ;
111125
112126 if ( ! fs . existsSync ( dstdir ) ) {
113127 fs . mkdirSync ( dstdir , { recursive : true } ) ;
114128 }
115129
116- await downloadAndExtract ( url , dstdir ) ;
130+ await downloadAndExtract ( url , dstdir , strip ) ;
117131
118132 console . log ( `::endgroup::` ) ;
119133}
@@ -134,8 +148,12 @@ async function install_pkgx() {
134148
135149 if ( process . env [ 'INPUT_+' ] ) {
136150 console . log ( `::group::installing pkgx input packages` ) ;
137- const args = process . env [ 'INPUT_+' ] . split ( ' ' ) ;
138- const cmd = `${ dstdir } /pkgx ${ args . map ( x => `+${ x } ` ) . join ( ' ' ) } ` ;
151+ let args = process . env [ 'INPUT_+' ] . split ( ' ' ) ;
152+ if ( os . platform ( ) == 'win32' ) {
153+ // cmd.exe uses ^ as an escape character
154+ args = args . map ( x => x . replace ( '^' , '^^' ) ) ;
155+ }
156+ const cmd = `${ path . join ( dstdir , 'pkgx' ) } ${ args . map ( x => `+${ x } ` ) . join ( ' ' ) } ` ;
139157 console . log ( `running: \`${ cmd } \`` ) ;
140158 let env = undefined ;
141159 if ( process . env . INPUT_PKGX_DIR ) {
0 commit comments