Skip to content

Commit

Permalink
Don’t use cURL in action.js (still needs tar tho) (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl authored Sep 29, 2022
1 parent 5bb9c04 commit 5afc02c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ jobs:
- name: HACKS
run: .github/mk-pantry-accessible.sh ${{ secrets.TEMP_JACOBS_GITHUB_PAT }}

# install.sh cannot find our cURL if the prefix is not set to where it exists
#TODO though, we *could* install it ourselves first
- run: echo 'CURL=/opt/curl.se/v*/bin/curl' >> $GITHUB_ENV
if: ${{ matrix.container == 'ghcr.io/teaxyz/infuser:latest' && matrix.prefix != '/opt' }}

- uses: ./
id: tea
with:
Expand All @@ -87,8 +82,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: sudo rm -rf .git README.md
- name: HACKS
run: .github/mk-pantry-accessible.sh ${{ secrets.TEMP_JACOBS_GITHUB_PAT }}
- uses: ./

shellcheck:
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.4.10
# GitHub Action 0.5.0

This repository also provides the `tea` GitHub Action.

Expand Down
60 changes: 45 additions & 15 deletions action.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
const { execSync } = require('child_process')
const { execSync, spawn } = require('child_process')
const https = require('https')
const fs = require('fs')
const os = require("os")

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

const PREFIX = process.env['INPUT_PREFIX'].trim() || `${os.homedir()}/opt`
const PREFIX = process.env['INPUT_PREFIX'] || `${os.homedir()}/opt`

// we build to /opt and special case this action so people new to
// building aren’t immediatelyt flumoxed
if (PREFIX == '/opt' && os.platform == 'darwin') {
execSync('sudo chown $(whoami):staff /opt')
}

let out = execSync(`${__dirname}/install.sh`, {
env: {
...process.env,
PREFIX,
YES: '1',
FORCE: '1'
//^^ so running this twice doesn’t do unexpected things
//^^ NOTE ideally we would have a flag to just abort if already installed
const midfix = (() => {
switch (process.arch) {
case 'arm64':
return `${process.platform}/aarch64`
case 'x64':
return `${process.platform}/x86-64`
default:
throw new Error(`unsupported platform: ${process.platform}/${process.arch}`)
}
}).toString()
})()

const v = await new Promise((resolve, reject) => {
https.get(`https://${process.env.TEA_SECRET}/tea.xyz/${midfix}/versions.txt`, rsp => {
if (rsp.statusCode != 200) return reject(rsp.statusCode)
rsp.setEncoding('utf8')
const chunks = []
rsp.on("data", x => chunks.push(x))
rsp.on("end", () => {
resolve(chunks.join("").split("\n").at(-1))
})
}).on('error', reject)
})

process.stdout.write(`fetching tea.xyz@${v}\n`)

fs.mkdirSync(PREFIX, { recursive: true })

const exitcode = await new Promise((resolve, reject) => {
https.get(`https://${process.env.TEA_SECRET}/tea.xyz/${midfix}/v${v}.tar.gz`, rsp => {
if (rsp.statusCode != 200) return reject(rsp.statusCode)
const tar = spawn('tar', ['xzf', '-'], { stdio: ['pipe', 'inherit', 'inherit'], cwd: PREFIX })
rsp.pipe(tar.stdin)
tar.on("close", resolve)
}).on('error', reject)
})

if (exitcode != 0) {
throw new Error(`tar: ${exitcode}`)
}

const v = out.trim().split("\n").pop().match(/\/tea.xyz\/v(\d+)\//)[1]
const GITHUB_PATH = process.env['GITHUB_PATH']
const bindir = `${PREFIX}/tea.xyz/v${v}/bin`
fs.appendFileSync(GITHUB_PATH, `${bindir}\n`, {encoding: 'utf8'})
Expand Down Expand Up @@ -52,8 +81,9 @@ try {
}

process.stdout.write(`::set-output name=prefix::${PREFIX}`)
}

} catch (err) {
go().catch(err => {
console.error(err)
process.exitCode = 1
}
})

0 comments on commit 5afc02c

Please sign in to comment.