Skip to content

Commit

Permalink
Updates for action v1 (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Sep 15, 2023
1 parent aa0024b commit 2e47b53
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 197 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
required: true

jobs:
qa.installer:
qa-installer:
uses: ./.github/workflows/ci.installer.yml
qa.action:
qa-action:
uses: ./.github/workflows/ci.action.yml

dist:
needs: [qa.installer, qa.action]
needs: [qa-installer, qa-action]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -Ssf https://tea.xyz/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
- run: ./scripts/dist.sh
- run: ./scripts/dist.sh --minify
- uses: actions/upload-artifact@v2
with:
name: dist
Expand Down
83 changes: 18 additions & 65 deletions .github/workflows/ci.action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -Ssf https://tea.xyz/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
- run: ./scripts/dist.sh
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist

gha:
std:
needs: dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: ./
- run: tea --version

plus-pkgs:
needs: dist
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -41,10 +52,6 @@ jobs:
include:
- os: ubuntu-latest
container: debian:buster-slim
srcroot: .
- os: ubuntu-latest
container: debian:buster-slim
srcroot: null
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v4
Expand All @@ -54,69 +61,15 @@ jobs:
path: dist

- uses: ./
id: tea
with:
prefix: ${{ matrix.prefix }}
srcroot: ${{ matrix.srcroot || github.workspace }}
TEA_DIR: ${{ matrix.prefix }}
+: node@18 deno.land

- run: test -n "$VERSION"
- run: test -n "${{ steps.tea.outputs.version }}"
- run: test v$VERSION = v${{ steps.tea.outputs.version }}
- run: tea --env
- run: which tea
- run: test -f '${{ matrix.prefix }}/tea.xyz/v*/bin/tea'
if: ${{ matrix.prefix }}
- run: tea --version
- run: node --eval 'console.log(1)'

chaste:
needs: dist
runs-on: ubuntu-latest
container: debian:buster-slim
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: ./
with:
chaste: true
- run:
if node --version; then
exit 1;
fi

additional-pkgs:
needs: dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: ./
with:
+deno.land: ^1.30
# ^^ produces a warning, but we like this syntax
# we're hoping GH allows us to suppress this warning in the future
# discussion: https://github.com/octokit/request-action/issues/26
- run: deno --version

additional-pkgs-2:
needs: dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: ./
with:
+: |
deno.land^1.30
cli.github.com
- run: deno --version
- run: gh --version

multiple-apply-is-ok:
runs-on: ubuntu-latest
Expand Down
43 changes: 14 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
![tea](https://tea.xyz/banner.png)

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

# GitHub Action 0.18.3

# GitHub Action

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

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

```yaml
- uses: teaxyz/setup@v0
- uses: teaxyz/setup@v1
with:
+: |
deno.land^1.30
rust-lang.org^1.60
+: deno@1.30 rust@1.60
```

Our packages are named after their homepages, to see what is available you
can browse the pantry on our website:
[tea.xyz] (we agree this isn’t great UX)

## Magic
### Shell Integration

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

## Should you Cache `~/.tea`?
### Should you Cache `~/.tea`?

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

## Interesting Usages

At tea, we consider the version in the `README` the definitive version.
Thus we use GitHub Actions to automatically tag and publish that version when
the README is edited and the version changes.

See our CI scripts for details.

 


# `tea` Installer

To install tea:
To install `tea`:

```sh
$ curl https://tea.xyz | sh
Expand Down
108 changes: 38 additions & 70 deletions action.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
const { porcelain, hooks, Path, utils, semver, SemVer } = require("@teaxyz/lib")
const { getExecOutput, exec } = require("@actions/exec")
const { useConfig, useSync, useCellar } = hooks
const core = require('@actions/core')
import { porcelain, hooks, Path, utils, PackageRequirement } from "@teaxyz/lib"
import { exec } from "@actions/exec"
import * as core from '@actions/core'
import * as path from 'path'
import * as os from "os"

const { useConfig, useShellEnv } = hooks
const { install } = porcelain
const path = require('path')
const os = require("os")
const { flatmap } = utils

async function go() {
const TEA_PREFIX = core.getInput('prefix') || `${os.homedir()}/.tea`

const TEA_DIR = (() => {
let TEA_DIR = core.getInput('srcroot').trim()
if (!TEA_DIR) return
if (!TEA_DIR.startsWith("/")) {
// for security this must be an absolute path
TEA_DIR = `${process.cwd()}/${TEA_DIR}`
}
return path.normalize(TEA_DIR)
})()
const TEA_DIR = core.getInput('TEA_DIR')

let vtea = core.getInput('version') ?? ""
if (vtea && !/^[*^~@=]/.test(vtea)) {
Expand All @@ -37,70 +29,41 @@ async function go() {
pkgs.push(key+value)
}}}


// we build to /opt and special case this action so people new to
// building aren’t immediately flumoxed
if (TEA_PREFIX == '/opt' && os.platform == 'darwin') {
if (TEA_DIR == '/opt' && os.platform() == 'darwin') {
await exec('sudo', ['chown', `${os.userInfo().username}:staff`, '/opt'])
}

core.info(`fetching ${pkgs.join(", ")}…`)

const prefix = flatmap(TEA_DIR, (x: string) => new Path(x)) ?? Path.home().join(".tea")

useConfig({
prefix: new Path(TEA_PREFIX),
prefix,
cache: prefix.join(".cache"),
pantries: [],
cache: new Path(TEA_PREFIX).join('tea.xyz/var/www'),
UserAgent: 'tea.setup/0.1.0', //TODO version
options: { compression: 'gz' }
})
const { map, flatten } = useShellEnv()

await install(pkgs)

const tea = await useCellar().resolve({project: 'tea.xyz', constraint: new semver.Range('*')})
const teafile = tea.path.join('bin/tea').string
const env_args = []
await hooks.useSync()

if (TEA_DIR && tea.pkg.version.gte(new SemVer("0.19"))) {
env_args.push('--env', '--keep-going')
} else if (TEA_DIR) {
env_args.push('--env')
}

let args = tea.pkg.version.gte(new SemVer("0.21"))
? []
: tea.pkg.version.gte(new SemVer("0.19"))
? ["--dry-run"]
: ["--dump"]

if (core.getBooleanInput("chaste")) {
args.push('--chaste')
}
const pkgrqs = await Promise.all(pkgs.map(parse))
const installations = await install(pkgrqs)
const env = flatten(await map({ installations }))

//FIXME we’re running tea/cli since dev-envs are not in libtea
// and we don’t want them in libtea, but we may need a libteacli as a result lol
const { stdout: out } = await getExecOutput(
teafile,
[...env_args, ...args, ...pkgs.map(x=>`+${x}`)],
{env: { ...process.env, TEA_DIR, TEA_PREFIX }})

const lines = out.split("\n")
for (const line of lines) {
const match = line.match(/(export )?([A-Za-z0-9_]+)=['"]?(.*)/)
if (!match) continue
const [,,key,value] = match
for (const [key, value] of Object.entries(env)) {
if (key == 'PATH') {
for (const part of value.split(":").reverse()) {
core.addPath(part)
}
core.addPath(value)
} else {
core.exportVariable(key, value)
if (key == 'VERSION') {
core.setOutput('version', value)
}
}
}

if (TEA_DIR) {
core.setOutput('srcroot', TEA_DIR)
core.exportVariable('TEA_DIR', TEA_DIR)
}

Expand All @@ -114,17 +77,22 @@ async function go() {
}
}

//TODO deprecated exe/md
//NOTE BUT LEAVE BECAUSE WE ONCE SUPPORTED THIS
const target = core.getInput('target')
if (target) {
await exec(teafile, [target], { env: { ...process.env, TEA_DIR, TEA_PREFIX } })
}

core.exportVariable('TEA_PREFIX', TEA_PREFIX)
core.setOutput('prefix', TEA_PREFIX)

core.info(`installed ${tea.path}`)
core.info(`installed ${installations.map(({pkg}) => utils.pkg.str(pkg)).join(', ')}`)
}

go().catch(core.setFailed)


async function parse(input: string): Promise<PackageRequirement> {
const find = hooks.usePantry().find
const rawpkg = utils.pkg.parse(input)

const projects = await find(rawpkg.project)
if (projects.length <= 0) throw new Error(`not found ${rawpkg.project}`)
if (projects.length > 1) throw new Error(`ambiguous project ${rawpkg.project}`)

const project = projects[0].project //FIXME libtea forgets to correctly assign type
const constraint = rawpkg.constraint

return { project, constraint }
}
Loading

0 comments on commit 2e47b53

Please sign in to comment.