From 193eca70dbc932b52c5dcb40797535eea57bc0bf Mon Sep 17 00:00:00 2001 From: Thomas Schoffelen Date: Fri, 22 Feb 2019 11:38:37 +0000 Subject: [PATCH] Making improvements for cross-platform support. --- lib/utils.js | 14 +++++++++----- package-lock.json | 18 ++++++++++++++++++ package.json | 4 +++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 4bba765..53d51a4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,6 +3,8 @@ const path = require('path') const glob = require('glob') const chalk = require('chalk') const {exec} = require('shelljs') +const tmp = require('temp-dir') +const mkdirp = require('mkdirp') const cleanupHcl = (hcl) => { const objects = {} @@ -68,14 +70,16 @@ const resolveRunner = (uses, verbose) => { subdir = subdir || '' let baseName = `${user}-${repo}-${subdir.replace(/\//g, '-')}`.replace(/-+$/, '') - let cacheFile = `/tmp/gha.${baseName}-${version}` - let dockerFile = `${cacheFile}/*/${subdir}/Dockerfile` + let cacheFile = path.join(tmp, `gha.${baseName}-${version}`) + let dockerFile = path.join(cacheFile, '*', subdir, 'Dockerfile') if (!glob.sync(dockerFile).length) { exec(`curl -o ${cacheFile}.tgz --fail --silent --show-error --location https://api.github.com/repos/${user}/${repo}/tarball/${version}`) - exec(`mkdir -p ${cacheFile}`) + mkdirp.sync(cacheFile) exec(`tar xf ${cacheFile}.tgz -C ${cacheFile}/`) - exec(`rm ${cacheFile}.tgz`) + try { + fs.unlinkSync(`${cacheFile}.tgz`) + } catch (e) {} } if (!glob.sync(dockerFile).length) { @@ -164,7 +168,7 @@ const runAction = (actionTitle, actions, event, verbose) => { `--rm`, `-t`, `-v \`pwd\`:/github/workspace`, - `-v /tmp/gh-home:/github/home`, + `-v ${path.join(tmp, 'gh-home')}:/github/home`, `-v ${assetPath}:/github/workflow/event.json:ro`, `-w /github/workspace`, args.join(' '), diff --git a/package-lock.json b/package-lock.json index 7d8ab9c..ada02d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -119,6 +119,19 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -171,6 +184,11 @@ "has-flag": "^3.0.0" } }, + "temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=" + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 68fe6f7..8a59a0a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "commander": "^2.19.0", "glob": "^7.1.3", "hcl": "^0.1.0", - "shelljs": "^0.8.3" + "mkdirp": "^0.5.1", + "shelljs": "^0.8.3", + "temp-dir": "^1.0.0" } }