1- const { porcelain, hooks, Path, utils, semver, SemVer } = require ( "@teaxyz/lib" )
2- const { getExecOutput, exec } = require ( "@actions/exec" )
3- const { useConfig, useSync, useCellar } = hooks
4- const core = require ( '@actions/core' )
1+ import { porcelain , hooks , Path , utils , PackageRequirement } from "@teaxyz/lib"
2+ import { exec } from "@actions/exec"
3+ import * as core from '@actions/core'
4+ import * as path from 'path'
5+ import * as os from "os"
6+
7+ const { useConfig, useShellEnv } = hooks
58const { install } = porcelain
6- const path = require ( 'path' )
7- const os = require ( "os" )
9+ const { flatmap } = utils
810
911async function go ( ) {
10- const TEA_PREFIX = core . getInput ( 'prefix' ) || `${ os . homedir ( ) } /.tea`
11-
12- const TEA_DIR = ( ( ) => {
13- let TEA_DIR = core . getInput ( 'srcroot' ) . trim ( )
14- if ( ! TEA_DIR ) return
15- if ( ! TEA_DIR . startsWith ( "/" ) ) {
16- // for security this must be an absolute path
17- TEA_DIR = `${ process . cwd ( ) } /${ TEA_DIR } `
18- }
19- return path . normalize ( TEA_DIR )
20- } ) ( )
12+ const TEA_DIR = core . getInput ( 'TEA_DIR' )
2113
2214 let vtea = core . getInput ( 'version' ) ?? ""
2315 if ( vtea && ! / ^ [ * ^ ~ @ = ] / . test ( vtea ) ) {
@@ -37,70 +29,41 @@ async function go() {
3729 pkgs . push ( key + value )
3830 } } }
3931
32+
4033 // we build to /opt and special case this action so people new to
4134 // building aren’t immediately flumoxed
42- if ( TEA_PREFIX == '/opt' && os . platform == 'darwin' ) {
35+ if ( TEA_DIR == '/opt' && os . platform ( ) == 'darwin' ) {
4336 await exec ( 'sudo' , [ 'chown' , `${ os . userInfo ( ) . username } :staff` , '/opt' ] )
4437 }
4538
4639 core . info ( `fetching ${ pkgs . join ( ", " ) } …` )
4740
41+ const prefix = flatmap ( TEA_DIR , ( x : string ) => new Path ( x ) ) ?? Path . home ( ) . join ( ".tea" )
42+
4843 useConfig ( {
49- prefix : new Path ( TEA_PREFIX ) ,
44+ prefix,
45+ cache : prefix . join ( ".cache" ) ,
5046 pantries : [ ] ,
51- cache : new Path ( TEA_PREFIX ) . join ( 'tea.xyz/var/www' ) ,
5247 UserAgent : 'tea.setup/0.1.0' , //TODO version
5348 options : { compression : 'gz' }
5449 } )
50+ const { map, flatten } = useShellEnv ( )
5551
56- await install ( pkgs )
57-
58- const tea = await useCellar ( ) . resolve ( { project : 'tea.xyz' , constraint : new semver . Range ( '*' ) } )
59- const teafile = tea . path . join ( 'bin/tea' ) . string
60- const env_args = [ ]
52+ await hooks . useSync ( )
6153
62- if ( TEA_DIR && tea . pkg . version . gte ( new SemVer ( "0.19" ) ) ) {
63- env_args . push ( '--env' , '--keep-going' )
64- } else if ( TEA_DIR ) {
65- env_args . push ( '--env' )
66- }
67-
68- let args = tea . pkg . version . gte ( new SemVer ( "0.21" ) )
69- ? [ ]
70- : tea . pkg . version . gte ( new SemVer ( "0.19" ) )
71- ? [ "--dry-run" ]
72- : [ "--dump" ]
73-
74- if ( core . getBooleanInput ( "chaste" ) ) {
75- args . push ( '--chaste' )
76- }
54+ const pkgrqs = await Promise . all ( pkgs . map ( parse ) )
55+ const installations = await install ( pkgrqs )
56+ const env = flatten ( await map ( { installations } ) )
7757
78- //FIXME we’re running tea/cli since dev-envs are not in libtea
79- // and we don’t want them in libtea, but we may need a libteacli as a result lol
80- const { stdout : out } = await getExecOutput (
81- teafile ,
82- [ ...env_args , ...args , ...pkgs . map ( x => `+${ x } ` ) ] ,
83- { env : { ...process . env , TEA_DIR , TEA_PREFIX } } )
84-
85- const lines = out . split ( "\n" )
86- for ( const line of lines ) {
87- const match = line . match ( / ( e x p o r t ) ? ( [ A - Z a - z 0 - 9 _ ] + ) = [ ' " ] ? ( .* ) / )
88- if ( ! match ) continue
89- const [ , , key , value ] = match
58+ for ( const [ key , value ] of Object . entries ( env ) ) {
9059 if ( key == 'PATH' ) {
91- for ( const part of value . split ( ":" ) . reverse ( ) ) {
92- core . addPath ( part )
93- }
60+ core . addPath ( value )
9461 } else {
9562 core . exportVariable ( key , value )
96- if ( key == 'VERSION' ) {
97- core . setOutput ( 'version' , value )
98- }
9963 }
10064 }
10165
10266 if ( TEA_DIR ) {
103- core . setOutput ( 'srcroot' , TEA_DIR )
10467 core . exportVariable ( 'TEA_DIR' , TEA_DIR )
10568 }
10669
@@ -114,17 +77,22 @@ async function go() {
11477 }
11578 }
11679
117- //TODO deprecated exe/md
118- //NOTE BUT LEAVE BECAUSE WE ONCE SUPPORTED THIS
119- const target = core . getInput ( 'target' )
120- if ( target ) {
121- await exec ( teafile , [ target ] , { env : { ...process . env , TEA_DIR , TEA_PREFIX } } )
122- }
123-
124- core . exportVariable ( 'TEA_PREFIX' , TEA_PREFIX )
125- core . setOutput ( 'prefix' , TEA_PREFIX )
126-
127- core . info ( `installed ${ tea . path } ` )
80+ core . info ( `installed ${ installations . map ( ( { pkg} ) => utils . pkg . str ( pkg ) ) . join ( ', ' ) } ` )
12881}
12982
13083go ( ) . catch ( core . setFailed )
84+
85+
86+ async function parse ( input : string ) : Promise < PackageRequirement > {
87+ const find = hooks . usePantry ( ) . find
88+ const rawpkg = utils . pkg . parse ( input )
89+
90+ const projects = await find ( rawpkg . project )
91+ if ( projects . length <= 0 ) throw new Error ( `not found ${ rawpkg . project } ` )
92+ if ( projects . length > 1 ) throw new Error ( `ambiguous project ${ rawpkg . project } ` )
93+
94+ const project = projects [ 0 ] . project //FIXME libtea forgets to correctly assign type
95+ const constraint = rawpkg . constraint
96+
97+ return { project, constraint }
98+ }
0 commit comments