Skip to content

Commit

Permalink
k, setting $TEA_DIR always was bad (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl authored Sep 29, 2022
1 parent f0bec2e commit 19092c2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ jobs:
- /opt
container:
- ~
- ghcr.io/teaxyz/infuser:latest
exclude:
- os: macos-latest
include:
- os: ubuntu-latest
container: ghcr.io/teaxyz/infuser:latest
srcroot: .
- os: ubuntu-latest
container: ghcr.io/teaxyz/infuser:latest
srcroot: ~
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v3
Expand All @@ -64,6 +67,7 @@ jobs:
with:
prefix: ${{ matrix.prefix }}
target: test
srcroot: ${{ matrix.srcroot || github.workspace }}

- run: test -n "$VERSION"
- run: test -n "${{ steps.tea.outputs.version }}"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[`install.sh`](./install.sh) is delivered when you `curl tea.xyz`.


# GitHub Action 0.5.1
# GitHub Action 0.5.3

This repository also provides the `tea` GitHub Action.

Expand Down
23 changes: 16 additions & 7 deletions action.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
const { execSync, spawn } = require('child_process')
const https = require('https')
const path = require('path')
const fs = require('fs')
const os = require("os")

async function go() {
process.stdout.write("installing tea…\n")

const PREFIX = process.env['INPUT_PREFIX'] || `${os.homedir()}/opt`
const TEA_DIR = (() => {
let TEA_DIR = process.env['INPUT_SRCROOT']
if (!TEA_DIR) return
TEA_DIR = TEA_DIR.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)
})()

// we build to /opt and special case this action so people new to
// building aren’t immediatelyt flumoxed
Expand Down Expand Up @@ -59,13 +71,9 @@ async function go() {
fs.appendFileSync(GITHUB_PATH, `${bindir}\n`, {encoding: 'utf8'})

const teafile = `${bindir}/tea`
const TEA_DIR = process.cwd()

const env = {
TEA_DIR,
// ^^ if there's no git then the checkout action uses the GitHub API
// to check out the repo. So there won’t be a `.git` directory and tea
// won’t find the SRCROOT
...process.env
}

Expand All @@ -85,9 +93,10 @@ async function go() {
fs.appendFileSync(GITHUB_ENV, `VERSION=${version}\n`, {encoding: 'utf8'})
}

process.stdout.write(`::set-output name=srcroot::${TEA_DIR}\n`)
fs.appendFileSync(GITHUB_ENV, `TEA_DIR=${TEA_DIR}\n`, {encoding: 'utf8'})

if (TEA_DIR) {
process.stdout.write(`::set-output name=srcroot::${TEA_DIR}\n`)
fs.appendFileSync(GITHUB_ENV, `TEA_DIR=${TEA_DIR}\n`, {encoding: 'utf8'})
}
} catch {
// `tea -Eds` returns exit code 1 if no SRCROOT is found
//TODO a flag so it returns 0 so we can not just swallow all errors lol
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ inputs:
Set to `null` to install to the tea default (~/.tea).
For GHA we default to `~/opt`.
required: false
srcroot:
description: |
Override detection of `$SRCROOT`.
tea normally finds your `$SRCROOT` by looking for a `.git` directory.
However, if git is not installed the checkout action uses the GitHub
API to download the repository.
You will need this if you depend on the virtual environment tea
provides.
outputs:
version:
description: Your project’s version.
Expand Down

0 comments on commit 19092c2

Please sign in to comment.