diff --git a/action.yml b/action.yml index 0775d1e..a4a0795 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: description: 'Branch or tag to use from smalltalkCI repository' required: false default: 'master' + smalltalkCI-workspace: + description: 'Path to install smalltalkCI to' + required: false outputs: smalltalk-image: description: 'Smalltalk image selection' diff --git a/dist/index.js b/dist/index.js index c70f0a4..8dadb11 100644 --- a/dist/index.js +++ b/dist/index.js @@ -18,7 +18,7 @@ const tc = __nccwpck_require__(784) const IS_LINUX = process.platform === 'linux' const IS_WINDOWS = process.platform === 'win32' -const INSTALLATION_DIRECTORY = path.join(os.homedir(), '.smalltalkCI') +const DEFAULT_WORKSPACE = os.homedir() const DEFAULT_BRANCH = 'master' const DEFAULT_SOURCE = 'hpi-swa/smalltalkCI' const LSB_FILE = '/etc/lsb-release' @@ -52,20 +52,23 @@ async function run() { core.setOutput('smalltalk-image', image) core.setOutput('smalltalk-version', version) + const smalltalkCIWorkspace = core.getInput('smalltalkCI-workspace') || DEFAULT_WORKSPACE const smalltalkCIBranch = core.getInput('smalltalkCI-branch') || DEFAULT_BRANCH const smalltalkCISource = core.getInput('smalltalkCI-source') || DEFAULT_SOURCE + const installationDirectory = path.join(smalltalkCIWorkspace, '.smalltalkCI') + let tempDirectory = path.join(smalltalkCIWorkspace, '.smalltalkCI-temp') + /* Download and extract smalltalkCI. */ console.log('Downloading and extracting smalltalkCI...') - let tempDir = path.join(os.homedir(), '.smalltalkCI-temp') if (IS_WINDOWS) { const toolPath = await tc.downloadTool(`https://github.com/${smalltalkCISource}/archive/${smalltalkCIBranch}.zip`) - tempDir = await tc.extractZip(toolPath, tempDir) + tempDirectory = await tc.extractZip(toolPath, tempDirectory) } else { const toolPath = await tc.downloadTool(`https://github.com/${smalltalkCISource}/archive/${smalltalkCIBranch}.tar.gz`) - tempDir = await tc.extractTar(toolPath, tempDir) + tempDirectory = await tc.extractTar(toolPath, tempDirectory) } - await io.mv(path.join(tempDir, `smalltalkCI-${smalltalkCIBranch}`), INSTALLATION_DIRECTORY) + await io.mv(path.join(tempDirectory, `smalltalkCI-${smalltalkCIBranch}`), installationDirectory) /* Install dependencies if any. */ if (IS_LINUX) { @@ -85,16 +88,19 @@ async function run() { } /* Set up smalltalkci command. */ - core.addPath(path.join(INSTALLATION_DIRECTORY, 'bin')) + core.addPath(path.join(installationDirectory, 'bin')) + let envList if (!IS_WINDOWS) { /* Find and export smalltalkCI's env vars. */ - const envList = child_process.execSync('smalltalkci --print-env').toString() - for (const envItem of envList.split('\n')) { - const parts = envItem.split('=') - if (parts.length == 2) { - core.exportVariable(parts[0], parts[1]) - } + envList = child_process.execSync('smalltalkci --print-env').toString() + } else { + envList = child_process.execSync('bash -l -c ".smalltalkCI/bin/smalltalkci --print-env"').toString() + } + for (const envItem of envList.split('\n')) { + const parts = envItem.split('=') + if (parts.length == 2) { + core.exportVariable(parts[0], parts[1]) } } } catch (error) { diff --git a/index.js b/index.js index ea92f40..0cb0369 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const tc = require('@actions/tool-cache') const IS_LINUX = process.platform === 'linux' const IS_WINDOWS = process.platform === 'win32' -const INSTALLATION_DIRECTORY = path.join(os.homedir(), '.smalltalkCI') +const DEFAULT_WORKSPACE = os.homedir() const DEFAULT_BRANCH = 'master' const DEFAULT_SOURCE = 'hpi-swa/smalltalkCI' const LSB_FILE = '/etc/lsb-release' @@ -45,20 +45,23 @@ async function run() { core.setOutput('smalltalk-image', image) core.setOutput('smalltalk-version', version) + const smalltalkCIWorkspace = core.getInput('smalltalkCI-workspace') || DEFAULT_WORKSPACE const smalltalkCIBranch = core.getInput('smalltalkCI-branch') || DEFAULT_BRANCH const smalltalkCISource = core.getInput('smalltalkCI-source') || DEFAULT_SOURCE + const installationDirectory = path.join(smalltalkCIWorkspace, '.smalltalkCI') + let tempDirectory = path.join(smalltalkCIWorkspace, '.smalltalkCI-temp') + /* Download and extract smalltalkCI. */ console.log('Downloading and extracting smalltalkCI...') - let tempDir = path.join(os.homedir(), '.smalltalkCI-temp') if (IS_WINDOWS) { const toolPath = await tc.downloadTool(`https://github.com/${smalltalkCISource}/archive/${smalltalkCIBranch}.zip`) - tempDir = await tc.extractZip(toolPath, tempDir) + tempDirectory = await tc.extractZip(toolPath, tempDirectory) } else { const toolPath = await tc.downloadTool(`https://github.com/${smalltalkCISource}/archive/${smalltalkCIBranch}.tar.gz`) - tempDir = await tc.extractTar(toolPath, tempDir) + tempDirectory = await tc.extractTar(toolPath, tempDirectory) } - await io.mv(path.join(tempDir, `smalltalkCI-${smalltalkCIBranch}`), INSTALLATION_DIRECTORY) + await io.mv(path.join(tempDirectory, `smalltalkCI-${smalltalkCIBranch}`), installationDirectory) /* Install dependencies if any. */ if (IS_LINUX) { @@ -78,16 +81,19 @@ async function run() { } /* Set up smalltalkci command. */ - core.addPath(path.join(INSTALLATION_DIRECTORY, 'bin')) + core.addPath(path.join(installationDirectory, 'bin')) + let envList if (!IS_WINDOWS) { /* Find and export smalltalkCI's env vars. */ - const envList = child_process.execSync('smalltalkci --print-env').toString() - for (const envItem of envList.split('\n')) { - const parts = envItem.split('=') - if (parts.length == 2) { - core.exportVariable(parts[0], parts[1]) - } + envList = child_process.execSync('smalltalkci --print-env').toString() + } else { + envList = child_process.execSync('bash -l -c ".smalltalkCI/bin/smalltalkci --print-env"').toString() + } + for (const envItem of envList.split('\n')) { + const parts = envItem.split('=') + if (parts.length == 2) { + core.exportVariable(parts[0], parts[1]) } } } catch (error) {