From 2e47b539e5a09b6a145a560293974f2d6dc39dbf Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 15 Sep 2023 13:08:24 -0400 Subject: [PATCH] Updates for action v1 (#188) --- .github/workflows/cd.yml | 8 +-- .github/workflows/ci.action.yml | 83 ++++++------------------ README.md | 43 +++++-------- action.ts | 108 +++++++++++--------------------- action.yml | 37 ++++------- scripts/dist.sh | 5 +- 6 files changed, 87 insertions(+), 197 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 29e1623a..0fb7c876 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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 diff --git a/.github/workflows/ci.action.yml b/.github/workflows/ci.action.yml index e2a04e95..e78e6032 100644 --- a/.github/workflows/ci.action.yml +++ b/.github/workflows/ci.action.yml @@ -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: @@ -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 @@ -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 diff --git a/README.md b/README.md index f52666c0..3e6cc4cb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.ts b/action.ts index 7ad06e06..b7b814dd 100644 --- a/action.ts +++ b/action.ts @@ -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)) { @@ -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) } @@ -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 { + 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 } +} diff --git a/action.yml b/action.yml index 58ee6255..59547723 100644 --- a/action.yml +++ b/action.yml @@ -2,44 +2,29 @@ name: tea/setup description: > Installs tea.xyz to your GitHub Actions runner. inputs: - prefix: - description: > - Where tea stows its packages. - Defaults to `$HOME/.tea`. - required: false - version: - description: > - The version of teaxyz/cli to install. - Defaults to the most recent published version. - default: ^0 - chaste: - description: > - Do not install packages. - Defaults to `false`. - default: false +: description: | Whitespace separated, pkgs to supplement the environment. eg. ```yaml - +: | - deno.land^1.30 - rust-lang.org^1.60 + +: + deno.land@1.30 + rust-lang.org@1.60 ``` By default tea reads your developer environment and adds those packages. Specifying additional packages here is a way to augment that. required: false - srcroot: - description: | - Override detection of the developer-environment’s `$SRCROOT`. - - Set to `null` to disable the developer-environment. - default: . + TEA_DIR: + description: > + Where pkgs are cached. + Defaults to `$HOME/.tea`. required: false -outputs: version: - description: Your project’s version. + description: > + The version of teaxyz/cli to install. + Defaults to the @latest. + required: false runs: using: node16 main: dist/out/index.js diff --git a/scripts/dist.sh b/scripts/dist.sh index 8666fdfd..3b575abe 100755 --- a/scripts/dist.sh +++ b/scripts/dist.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env -S tea +npm bash +#!/bin/bash set -e @@ -6,7 +6,7 @@ npm install --include=dev rm -rf dist -npx -- ncc build action.ts --minify --out dist/out +npx -- ncc build action.ts "$@" --out dist/out cp -R node_modules/koffi/build dist @@ -18,5 +18,4 @@ rm -rf koffi_linux_arm32hf rm -rf koffi_linux_riscv64hf64 cd ../../out -rm installer.sh ln -s ../../installer.sh