From d01c52ad8bb5e96ea744946c5283be6a168feece Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 3 Mar 2023 17:10:02 +0100 Subject: [PATCH] Add a self-hosted input to force considering the current runner as self-hosted * Since checking for self-hosted is based on guessing as there is no proper predicate for it in GitHub Actions (AFAIK). --- action.yml | 5 +++++ common.js | 13 +++++++++++-- dist/index.js | 16 ++++++++++++++-- index.js | 2 ++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 9328b12..55dbb3e 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,11 @@ inputs: description: | Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need to invalidate the cache. + self-hosted: + description: | + Consider the runner as a self-hosted runner, which means not using prebuilt Ruby binaries which only work + on GitHub-hosted runners or self-hosted runners with a very similar image to the ones used by GitHub runners. + The default is to detect this automatically based on the OS, OS version and $RUNNER_TOOL_CACHE. outputs: ruby-prefix: description: 'The prefix of the installed ruby' diff --git a/common.js b/common.js index 5ec89a1..9e591c4 100644 --- a/common.js +++ b/common.js @@ -13,6 +13,10 @@ export const windows = (os.platform() === 'win32') // Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14 export const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined) +export const inputs = { + selfHosted: undefined +} + export function partition(string, separator) { const i = string.indexOf(separator) if (i === -1) { @@ -166,8 +170,13 @@ const GitHubHostedPlatforms = [ // * the OS and OS version does not correspond to a GitHub-hosted runner image, // * or the hosted tool cache is different from the default tool cache path export function isSelfHostedRunner() { - return !GitHubHostedPlatforms.includes(getOSNameVersionArch()) || - getRunnerToolCache() !== getDefaultToolCachePath() + if (inputs.selfHosted === undefined) { + throw new Error('inputs.selfHosted should have been already set') + } + + return inputs.selfHosted === 'true' || + !GitHubHostedPlatforms.includes(getOSNameVersionArch()) || + getRunnerToolCache() !== getDefaultToolCachePath() } let virtualEnvironmentName = undefined diff --git a/dist/index.js b/dist/index.js index 977d2e6..99c9c72 100644 --- a/dist/index.js +++ b/dist/index.js @@ -296,6 +296,7 @@ __nccwpck_require__.d(__webpack_exports__, { "getVirtualEnvironmentName": () => (/* binding */ getVirtualEnvironmentName), "hasBundlerDefaultGem": () => (/* binding */ hasBundlerDefaultGem), "hashFile": () => (/* binding */ hashFile), + "inputs": () => (/* binding */ inputs), "isBundler1Default": () => (/* binding */ isBundler1Default), "isBundler2Default": () => (/* binding */ isBundler2Default), "isBundler2dot2Default": () => (/* binding */ isBundler2dot2Default), @@ -366,6 +367,10 @@ const windows = (os.platform() === 'win32') // Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14 const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined) +const inputs = { + selfHosted: undefined +} + function partition(string, separator) { const i = string.indexOf(separator) if (i === -1) { @@ -519,8 +524,13 @@ const GitHubHostedPlatforms = [ // * the OS and OS version does not correspond to a GitHub-hosted runner image, // * or the hosted tool cache is different from the default tool cache path function isSelfHostedRunner() { - return !GitHubHostedPlatforms.includes(getOSNameVersionArch()) || - getRunnerToolCache() !== getDefaultToolCachePath() + if (inputs.selfHosted === undefined) { + throw new Error('inputs.selfHosted should have been already set') + } + + return inputs.selfHosted === 'true' || + !GitHubHostedPlatforms.includes(getOSNameVersionArch()) || + getRunnerToolCache() !== getDefaultToolCachePath() } let virtualEnvironmentName = undefined @@ -69022,6 +69032,7 @@ const inputDefaults = { 'bundler-cache': 'false', 'working-directory': '.', 'cache-version': bundler.DEFAULT_CACHE_VERSION, + 'self-hosted': 'false', } // entry point when this action is run on its own @@ -69045,6 +69056,7 @@ async function setupRuby(options = {}) { inputs[key] = core.getInput(key) || inputDefaults[key] } } + common.inputs.selfHosted = inputs['self-hosted'] process.chdir(inputs['working-directory']) diff --git a/index.js b/index.js index 2fe5aca..bb8af70 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const inputDefaults = { 'bundler-cache': 'false', 'working-directory': '.', 'cache-version': bundler.DEFAULT_CACHE_VERSION, + 'self-hosted': 'false', } // entry point when this action is run on its own @@ -39,6 +40,7 @@ export async function setupRuby(options = {}) { inputs[key] = core.getInput(key) || inputDefaults[key] } } + common.inputs.selfHosted = inputs['self-hosted'] process.chdir(inputs['working-directory'])