diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9985027..9478058 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -110,3 +110,28 @@ jobs: with: version: '9.21.0' packages: 'Editor X:1.5.0-beta.41+2c6d736c,NATS Server,CSV' + + test-install-path: + runs-on: ubuntu-24.04 + name: Test Install Path Output + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: ./ # Uses an action in the root directory + id: setup + with: + version: '9.32.3' + - name: Verify path output is under RUNNER_TEMP and tap is installed there + run: | + echo "setup path output: '$TAP_PATH'" + if [ -z "$TAP_PATH" ]; then + echo "::error::path output was not set" + exit 1 + fi + case "$TAP_PATH" in + "$RUNNER_TEMP"/*) : ;; + *) echo "::error::install path is not under RUNNER_TEMP ($RUNNER_TEMP)"; exit 1 ;; + esac + test -x "$TAP_PATH/tap" || { echo "::error::tap not found at TAP_PATH"; exit 1; } + # tap should also be resolvable via PATH (added by core.addPath) + tap package list --installed diff --git a/Readme.md b/Readme.md index 22ce2c9..e5032fb 100644 --- a/Readme.md +++ b/Readme.md @@ -17,3 +17,7 @@ There are a few arguments to help you select the right version of OpenTAP to ins - `architecture` - Defaults to the architecture of the runner - `os` - Defaults to the OS of the runner - `packages` - a list of additional packages to install. Format: `:,:`. This option requires `version` to be 9.17 or greater. + +## Outputs + +The temporary installation directory is available in the environment variable `TAP_PATH`, and prepended to `PATH` diff --git a/index.js b/index.js index f9e6a8a..2173fb2 100644 --- a/index.js +++ b/index.js @@ -3,14 +3,16 @@ const exec = require("@actions/exec"); const tc = require("@actions/tool-cache"); const fs = require("fs"); const os = require("os"); +const path = require("path"); main().catch((error) => setFailed(error.message)); -const INSTALL_DIRS = { - linux: "/opt/tap", - windows: "C:/Program Files/OpenTAP", - macos: "/Users/runner/Library/OpenTAP", -}; +// Resolve a per-worker installation directory. +// This resolves conflicts when the same machine is simultaneously installing different OpenTAP images. +function getInstallDir() { + const base = process.env.RUNNER_TEMP || os.tmpdir(); + return path.join(base, "OpenTAP"); +} function getArchitecture() { // Map Node's os.arch() values to the architecture strings expected by the @@ -83,13 +85,34 @@ async function extractZip(file, dest) { } try { - // Fall back to powershell if unzip is not available. This is the case on e.g. - // the official dotnet 8 SDK docker image, mcr.microsoft.com/dotnet/sdk:8.0 + // Fall back to pwsh if unzip is not available. This is the case on e.g. the official dotnet 8 SDK docker image, mcr.microsoft.com/dotnet/sdk:8.0 await exec.exec("pwsh", ["-c", `Expand-Archive -Path "${file}" -DestinationPath "${dest}"`]) return true; } catch { // ignore } + + + try { + // Fall back to powershell if pwsh is not available. This is the case on some Windows machines. + let script = ` +$filename = "${file}" +$dest = "${dest}" +$ext = [IO.Path]::GetExtension($filename) +if ($ext -ne ".zip") +{ + Move-Item "$filename" "$($filename).zip" + $filename = "$($filename).zip" +} +Expand-Archive -Path "$filename" -DestinationPath "$dest" +`; + + await exec.exec("powershell.exe", ["-c", script]) + return true; + } catch { + // ignore + } + return false } @@ -132,8 +155,9 @@ async function main() { // Extract OpenTAP package core.info("Unzipping OpenTAP: " + downloadedFilepath); - const destDir = INSTALL_DIRS[platform]; + const destDir = getInstallDir(); const settingsDir = destDir + "/Settings/"; + core.info("Installing OpenTAP to: " + destDir); const extracted = await extractZip(downloadedFilepath, destDir); if (!extracted) { core.setFailed("Unable to extract zip archive.") @@ -152,6 +176,8 @@ async function main() { // Add to path env core.addPath(destDir); + // Some plugins depend on this environment variable being set. + core.exportVariable('TAP_PATH', destDir); // Install packages if (core.getInput("packages")) {