Skip to content

Commit cb74a62

Browse files
committed
Updates for action v1 (#188)
1 parent aa0024b commit cb74a62

File tree

6 files changed

+88
-198
lines changed

6 files changed

+88
-198
lines changed

.github/workflows/cd.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ on:
55
required: true
66

77
jobs:
8-
qa.installer:
8+
qa-installer:
99
uses: ./.github/workflows/ci.installer.yml
10-
qa.action:
10+
qa-action:
1111
uses: ./.github/workflows/ci.action.yml
1212

1313
dist:
14-
needs: [qa.installer, qa.action]
14+
needs: [qa-installer, qa-action]
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
1818
- run: curl -Ssf https://tea.xyz/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
19-
- run: ./scripts/dist.sh
19+
- run: ./scripts/dist.sh --minify
2020
- uses: actions/upload-artifact@v2
2121
with:
2222
name: dist
@@ -61,7 +61,7 @@ jobs:
6161
- uses: git-actions/set-user@v1
6262
- run: |
6363
git add dist
64-
git commit -m 'v${{ github.event.inputs.version }}
64+
git commit -m v${{ github.event.inputs.version }}
6565
git tag v${{ github.event.inputs.version }}
6666
git push origin v${{ github.event.inputs.version }} main
6767

.github/workflows/ci.action.yml

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- run: curl -Ssf https://tea.xyz/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
1918
- run: ./scripts/dist.sh
2019
- uses: actions/upload-artifact@v2
2120
with:
2221
name: dist
2322
path: dist
2423

25-
gha:
24+
std:
25+
needs: dist
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/download-artifact@v2
30+
with:
31+
name: dist
32+
path: dist
33+
- uses: ./
34+
- run: tea --version
35+
36+
plus-pkgs:
2637
needs: dist
2738
runs-on: ${{ matrix.os }}
2839
strategy:
@@ -41,10 +52,6 @@ jobs:
4152
include:
4253
- os: ubuntu-latest
4354
container: debian:buster-slim
44-
srcroot: .
45-
- os: ubuntu-latest
46-
container: debian:buster-slim
47-
srcroot: null
4855
container: ${{ matrix.container }}
4956
steps:
5057
- uses: actions/checkout@v4
@@ -54,69 +61,15 @@ jobs:
5461
path: dist
5562

5663
- uses: ./
57-
id: tea
5864
with:
59-
prefix: ${{ matrix.prefix }}
60-
srcroot: ${{ matrix.srcroot || github.workspace }}
65+
TEA_DIR: ${{ matrix.prefix }}
66+
+: node@18 deno.land
6167

62-
- run: test -n "$VERSION"
63-
- run: test -n "${{ steps.tea.outputs.version }}"
64-
- run: test v$VERSION = v${{ steps.tea.outputs.version }}
65-
- run: tea --env
66-
- run: which tea
68+
- run: test -f '${{ matrix.prefix }}/tea.xyz/v*/bin/tea'
69+
if: ${{ matrix.prefix }}
70+
- run: tea --version
6771
- run: node --eval 'console.log(1)'
68-
69-
chaste:
70-
needs: dist
71-
runs-on: ubuntu-latest
72-
container: debian:buster-slim
73-
steps:
74-
- uses: actions/checkout@v4
75-
- uses: actions/download-artifact@v2
76-
with:
77-
name: dist
78-
path: dist
79-
- uses: ./
80-
with:
81-
chaste: true
82-
- run:
83-
if node --version; then
84-
exit 1;
85-
fi
86-
87-
additional-pkgs:
88-
needs: dist
89-
runs-on: ubuntu-latest
90-
steps:
91-
- uses: actions/checkout@v4
92-
- uses: actions/download-artifact@v2
93-
with:
94-
name: dist
95-
path: dist
96-
- uses: ./
97-
with:
98-
+deno.land: ^1.30
99-
# ^^ produces a warning, but we like this syntax
100-
# we're hoping GH allows us to suppress this warning in the future
101-
# discussion: https://github.com/octokit/request-action/issues/26
102-
- run: deno --version
103-
104-
additional-pkgs-2:
105-
needs: dist
106-
runs-on: ubuntu-latest
107-
steps:
108-
- uses: actions/checkout@v4
109-
- uses: actions/download-artifact@v2
110-
with:
111-
name: dist
112-
path: dist
113-
- uses: ./
114-
with:
115-
+: |
116-
deno.land^1.30
117-
cli.github.com
11872
- run: deno --version
119-
- run: gh --version
12073

12174
multiple-apply-is-ok:
12275
runs-on: ubuntu-latest

README.md

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
![tea](https://tea.xyz/banner.png)
22

3-
* [`installer.sh`](./installer.sh) is delivered when you `curl tea.xyz`.
4-
* This repository also provides the `tea` GitHub Action.
3+
* This repository provides the `tea` GitHub Action.
4+
* It also hosts [`installer.sh`](./installer.sh); the result of `curl tea.xyz`.
55

6-
# GitHub Action 0.18.3
6+
7+
# GitHub Action
78

89
```yaml
9-
- uses: teaxyz/setup@v0
10+
- uses: teaxyz/setup@v1
1011
```
1112
12-
Installs tea, your dependencies (computed from your developer environment),
13-
adds your deps to `PATH` and exports some other *tea’ish* variables like
14-
`VERSION`.
13+
Installs the latest version of `tea`.
1514

1615
See [`action.yml`] for all inputs and outputs, but here’s the usual ones:
1716

1817
```yaml
19-
- uses: teaxyz/setup@v0
18+
- uses: teaxyz/setup@v1
2019
with:
21-
+: |
22-
deno.land^1.30
23-
rust-lang.org^1.60
20+
2421
```
2522

26-
Our packages are named after their homepages, to see what is available you
27-
can browse the pantry on our website:
28-
[tea.xyz] (we agree this isn’t great UX)
29-
30-
## Magic
23+
### Shell Integration
3124

32-
We cannot install our shell magic into GitHub Actions. So unless your dev-env
33-
includes the package or you manually add the package with `+:` you will need
34-
to ensure it is called with a `tea` prefix, eg. `tea npx`.
25+
We cannot integrate with the GitHub Actions shell. But you probably don’t
26+
need it.
3527

36-
## Should you Cache `~/.tea`?
28+
### Should you Cache `~/.tea`?
3729

3830
No. tea packages are just tarballs. Caching is just a tarball. You’ll likely
3931
just slow things down.
4032

41-
## Interesting Usages
42-
43-
At tea, we consider the version in the `README` the definitive version.
44-
Thus we use GitHub Actions to automatically tag and publish that version when
45-
the README is edited and the version changes.
46-
47-
See our CI scripts for details.
48-
33+
 
4934

5035

5136
# `tea` Installer
5237

53-
To install tea:
38+
To install `tea`:
5439

5540
```sh
5641
$ curl https://tea.xyz | sh

action.ts

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
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
58
const { install } = porcelain
6-
const path = require('path')
7-
const os = require("os")
9+
const { flatmap } = utils
810

911
async 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(/(export )?([A-Za-z0-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

13083
go().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

Comments
 (0)