Skip to content

Commit c9d315c

Browse files
committed
use libtea (#155)
Fixes #158 We now use vercel/ncc as a distribution pre-req because otherwise we’re way too big. Also we prune the koffi modules down to only what we need for the same reasons.
1 parent 972ff14 commit c9d315c

File tree

15 files changed

+336
-109
lines changed

15 files changed

+336
-109
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
echo "::set-output name=result::cancel"
2828
fi
2929
30-
- uses: andymckay/cancel-action@0.2
30+
- uses: andymckay/cancel-action@0.3
3131
if: ${{ steps.rev-parse.outputs.result == 'cancel' }}
3232

3333
ci:

.github/workflows/ci.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ jobs:
2828
verbose: VERBOSE
2929
steps:
3030
- uses: actions/checkout@v3
31-
- run: echo foo > foo
32-
- run: ./install.sh --yes node --eval 'console.log(1)'
31+
- run: ./install.sh node --eval 'console.log(1)'
3332
env:
3433
VERBOSE: ${{ matrix.verbose }}
3534
- run: ./install.sh sh -c "which tea"
@@ -44,7 +43,7 @@ jobs:
4443
- [self-hosted, macOS, ARM64]
4544
- [self-hosted, linux, ARM64]
4645
prefix:
47-
- ~
46+
- null
4847
- foo
4948
include:
5049
- os: ubuntu-latest
@@ -74,6 +73,7 @@ jobs:
7473
gha:
7574
runs-on: ${{ matrix.os }}
7675
strategy:
76+
fail-fast: false
7777
matrix:
7878
os:
7979
- macos-latest
@@ -169,9 +169,10 @@ jobs:
169169
runs-on: ubuntu-latest
170170
steps:
171171
- uses: actions/checkout@v3
172-
- uses: ludeeus/action-shellcheck@1.1.0
172+
- uses: ludeeus/action-shellcheck@2.0.0
173173
with:
174174
severity: warning
175+
ignore_paths: scripts # this action is badly designed you can’t be more specific that a directory or filename (not path)
175176
env:
176177
SHELLCHECK_OPTS: --shell dash
177178

@@ -196,6 +197,9 @@ jobs:
196197
- 0.26.3
197198
- 0.18.1
198199
- 0.17.3
200+
include:
201+
- version: ^0.33
202+
system: gha
199203
steps:
200204
- uses: actions/checkout@v3
201205
- uses: ./
@@ -204,7 +208,8 @@ jobs:
204208
version: ${{ matrix.version }}
205209
- run: ./install.sh --yes --version ${{ matrix.version }}
206210
if: ${{ matrix.system == 'direct' }}
207-
- run: test "$(tea --version)" = "tea ${{ matrix.version }}"
211+
- run: tea --version | grep ${{ matrix.version }}
212+
if: ${{ matrix.version != '^0.33' }}
208213

209214
sudo-not-required:
210215
runs-on: ubuntu-latest
@@ -295,3 +300,11 @@ jobs:
295300
if line.startswith(' '):
296301
print(f'Error: Space indentation found on line {line_number}')
297302
sys.exit(1)
303+
304+
check-dist-was-run:
305+
runs-on: ubuntu-latest
306+
steps:
307+
- uses: actions/checkout@v3
308+
- uses: ./
309+
- run: ./scripts/dist.sh
310+
- run: git diff --exit-code

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/out.gif
2+
.DS_Store
3+
/node_modules

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* [`install.sh`](./install.sh) is delivered when you `curl tea.xyz`.
44
* This repository also provides the `tea` GitHub Action.
55

6-
# GitHub Action 0.17.1
6+
# GitHub Action 0.18.0
77

88
```yaml
99
- uses: teaxyz/setup@v0

action.js

Lines changed: 66 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
const { execSync, spawn } = require('child_process')
2-
const https = require('https')
1+
const { prefab, hooks, Path, utils, semver, SemVer } = require("@teaxyz/lib")
2+
const { install, link, resolve, hydrate } = prefab
3+
const { getExecOutput, exec } = require("@actions/exec")
4+
const { useConfig, useSync, useCellar } = hooks
5+
const core = require('@actions/core')
36
const path = require('path')
4-
const fs = require('fs')
57
const os = require("os")
68

79
async function go() {
8-
process.stderr.write("determining latest tea version…\n")
10+
const TEA_PREFIX = core.getInput('prefix') || `${os.homedir()}/.tea`
911

10-
const PREFIX = process.env['INPUT_PREFIX'] || `${os.homedir()}/.tea`
1112
const TEA_DIR = (() => {
12-
let TEA_DIR = process.env['INPUT_SRCROOT']
13-
if (!TEA_DIR) return
14-
TEA_DIR = TEA_DIR.trim()
13+
let TEA_DIR = core.getInput('srcroot').trim()
1514
if (!TEA_DIR) return
1615
if (!TEA_DIR.startsWith("/")) {
1716
// for security this must be an absolute path
@@ -20,149 +19,115 @@ async function go() {
2019
return path.normalize(TEA_DIR)
2120
})()
2221

23-
const additional_pkgs = []
22+
let vtea = core.getInput('version') ?? ""
23+
if (vtea && !/^[*^~@=]/.test(vtea)) {
24+
vtea = `@${vtea}`
25+
}
26+
27+
const pkgs = [`tea.xyz${vtea}`]
2428
for (let key in process.env) {
2529
if (key.startsWith("INPUT_+")) {
2630
const value = process.env[key]
2731
if (key == 'INPUT_+') {
2832
for (const item of value.split(/\s+/)) {
2933
if (item.trim()) {
30-
additional_pkgs.push(`+${item}`)
34+
pkgs.push(item)
3135
}}} else {
32-
key = key.slice(6).toLowerCase()
33-
additional_pkgs.push(key+value)
36+
key = key.slice(7).toLowerCase()
37+
pkgs.push(key+value)
3438
}}}
3539

3640
// we build to /opt and special case this action so people new to
37-
// building aren’t immediatelyt flumoxed
38-
if (PREFIX == '/opt' && os.platform == 'darwin') {
39-
execSync('sudo chown $(whoami):staff /opt')
41+
// building aren’t immediately flumoxed
42+
if (TEA_PREFIX == '/opt' && os.platform == 'darwin') {
43+
await exec('sudo', ['chown', `${os.userInfo().username}:staff`, '/opt'])
4044
}
4145

42-
const midfix = (() => {
43-
switch (process.arch) {
44-
case 'arm64':
45-
return `${process.platform}/aarch64`
46-
case 'x64':
47-
return `${process.platform}/x86-64`
48-
default:
49-
throw new Error(`unsupported platform: ${process.platform}/${process.arch}`)
50-
}
51-
})()
52-
53-
const v = process.env['INPUT_VERSION'] || await new Promise((resolve, reject) => {
54-
https.get(`https://dist.tea.xyz/tea.xyz/${midfix}/versions.txt`, rsp => {
55-
if (rsp.statusCode != 200) return reject(rsp.statusCode)
56-
rsp.setEncoding('utf8')
57-
const chunks = []
58-
rsp.on("data", x => chunks.push(x))
59-
rsp.on("end", () => {
60-
resolve(chunks.join("").trim().split("\n").at(-1))
61-
})
62-
}).on('error', reject)
63-
})
64-
65-
process.stderr.write(`fetching tea.xyz@${v}\n`)
66-
67-
fs.mkdirSync(PREFIX, { recursive: true })
46+
core.info(`fetching ${pkgs.join(", ")}…`)
6847

69-
const exitcode = await new Promise((resolve, reject) => {
70-
https.get(`https://dist.tea.xyz/tea.xyz/${midfix}/v${v}.tar.gz`, rsp => {
71-
if (rsp.statusCode != 200) return reject(rsp.statusCode)
72-
const tar = spawn('tar', ['xzf', '-'], { stdio: ['pipe', 'inherit', 'inherit'], cwd: PREFIX })
73-
rsp.pipe(tar.stdin)
74-
tar.on("close", resolve)
75-
}).on('error', reject)
48+
useConfig({
49+
prefix: new Path(TEA_PREFIX),
50+
pantries: [],
51+
cache: new Path(TEA_PREFIX).join('tea.xyz/var/www'),
52+
UserAgent: 'tea.setup/0.1.0', //TODO version
53+
options: { compression: 'gz' }
7654
})
77-
78-
if (exitcode != 0) {
79-
throw new Error(`tar: ${exitcode}`)
55+
await useSync()
56+
const { pkgs: tree } = await hydrate(pkgs.map(utils.pkg.parse))
57+
const { pending } = await resolve(tree)
58+
for (const pkg of pending) {
59+
core.info(`installing ${utils.pkg.str(pkg)}`)
60+
const installation = await install(pkg)
61+
await link(installation)
8062
}
8163

82-
const oldwd = process.cwd()
83-
process.chdir(`${PREFIX}/tea.xyz`)
84-
if (fs.existsSync(`v*`)) fs.unlinkSync(`v*`)
85-
fs.symlinkSync(`v${v}`, `v*`, 'dir')
86-
if (fs.existsSync(`v0`)) fs.unlinkSync(`v0`)
87-
fs.symlinkSync(`v${v}`, `v0`, 'dir') //FIXME
88-
process.chdir(oldwd)
89-
90-
const GITHUB_PATH = process.env['GITHUB_PATH']
91-
const bindir = `${PREFIX}/tea.xyz/v${v}/bin`
92-
fs.appendFileSync(GITHUB_PATH, `${bindir}\n`, {encoding: 'utf8'})
64+
const tea = await useCellar().resolve({project: 'tea.xyz', constraint: new semver.Range('*')})
65+
const teafile = tea.path.join('bin/tea').string
66+
const env_args = ['--env']
9367

94-
const teafile = `${bindir}/tea`
95-
96-
const env = {
97-
TEA_DIR,
98-
...process.env
68+
if (TEA_DIR && tea.pkg.version.gte(new SemVer("0.19"))) {
69+
env_args.push('--keep-going')
9970
}
10071

101-
const GITHUB_ENV = process.env['GITHUB_ENV']
102-
const GITHUB_OUTPUT = process.env['GITHUB_OUTPUT']
103-
104-
const vv = parseFloat(v)
105-
const env_flag = TEA_DIR ? vv >= 0.19 ? '--env --keep-going' : '--env' : ''
72+
let args = tea.pkg.version.gte(new SemVer("0.21"))
73+
? []
74+
: tea.pkg.version.gte(new SemVer("0.19"))
75+
? ["--dry-run"]
76+
: ["--dump"]
10677

107-
// get env FIXME one call should do init
108-
109-
let args = vv >= 0.21
110-
? ""
111-
: vv >= 0.19
112-
? "--dry-run"
113-
: "--dump"
114-
115-
if (process.env["INPUT_CHASTE"] == "true") {
116-
args += " --chaste"
78+
if (core.getBooleanInput("chaste")) {
79+
args.push('--chaste')
11780
}
11881

119-
out = execSync(`${teafile} --sync ${env_flag} ${args} ${additional_pkgs.join(" ")}`, {env}).toString()
82+
//FIXME we’re running tea/cli since dev-envs are not in libtea
83+
// and we don’t want them in libtea, but we may need a libteacli as a result lol
84+
const { stdout: out } = await getExecOutput(
85+
teafile,
86+
[...env_args, ...args, ...pkgs.map(x=>`+${x}`)],
87+
{env: { ...process.env, TEA_DIR, TEA_PREFIX }})
12088

12189
const lines = out.split("\n")
12290
for (const line of lines) {
12391
const match = line.match(/(export )?([A-Za-z0-9_]+)=['"]?(.*)/)
12492
if (!match) continue
12593
const [,,key,value] = match
126-
if (key == 'VERSION') {
127-
fs.appendFileSync(GITHUB_OUTPUT, `version=${value}\n`, {encoding: 'utf8'})
128-
}
12994
if (key == 'PATH') {
13095
for (const part of value.split(":").reverse()) {
131-
fs.appendFileSync(GITHUB_PATH, `${part}\n`, {encoding: 'utf8'})
96+
core.addPath(part)
13297
}
13398
} else {
134-
fs.appendFileSync(GITHUB_ENV, `${key}=${value}\n`, {encoding: 'utf8'})
99+
core.exportVariable(key, value)
100+
if (key == 'VERSION') {
101+
core.setOutput('version', value)
102+
}
135103
}
136104
}
137105

138106
if (TEA_DIR) {
139-
fs.appendFileSync(GITHUB_OUTPUT, `srcroot=${TEA_DIR}\n`, {encoding: 'utf8'})
140-
fs.appendFileSync(GITHUB_ENV, `TEA_DIR=${TEA_DIR}\n`, {encoding: 'utf8'})
107+
core.setOutput('srcroot', TEA_DIR)
108+
core.exportVariable('TEA_DIR', TEA_DIR)
141109
}
142110

143111
if (os.platform() != 'darwin') {
144112
const sh = path.join(path.dirname(__filename), "install-pre-reqs.sh")
145113
if (process.getuid() == 0) {
146-
execSync(sh)
114+
await exec(sh)
147115
} else {
148-
execSync(`sudo ${sh}`)
116+
await exec('sudo', [sh])
149117
}
150118
}
151119

152120
//TODO deprecated exe/md
153121
//NOTE BUT LEAVE BECAUSE WE ONCE SUPPORTED THIS
154-
const target = process.env['INPUT_TARGET']
122+
const target = core.getInput('target')
155123
if (target) {
156-
execSync(`${teafile} ${target}`, {stdio: "inherit", env})
124+
await exec(teafile, [target], { env: { ...process.env, TEA_DIR, TEA_PREFIX } })
157125
}
158126

159-
fs.appendFileSync(GITHUB_ENV, `TEA_PREFIX=${PREFIX}\n`, {encoding: 'utf8'})
160-
fs.appendFileSync(GITHUB_OUTPUT, `prefix=${PREFIX}\n`, {encoding: 'utf8'})
127+
core.exportVariable('TEA_PREFIX', TEA_PREFIX)
128+
core.setOutput('prefix', TEA_PREFIX)
161129

162-
process.stderr.write(`installed ${PREFIX}/tea.xyz/v${v}\n`)
130+
core.info(`installed ${tea.path}`)
163131
}
164132

165-
go().catch(err => {
166-
console.error(err)
167-
process.exitCode = 1
168-
})
133+
go().catch(core.setFailed)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ outputs:
4242
description: Your project’s version.
4343
runs:
4444
using: node16
45-
main: action.js
45+
main: dist/out/index.js
869 KB
Binary file not shown.
979 KB
Binary file not shown.
1000 KB
Binary file not shown.
1.11 MB
Binary file not shown.

0 commit comments

Comments
 (0)