Skip to content

Commit

Permalink
Add a self-hosted input to force considering the current runner as se…
Browse files Browse the repository at this point in the history
…lf-hosted

* Since checking for self-hosted is based on guessing as there is
  no proper predicate for it in GitHub Actions (AFAIK).
  • Loading branch information
eregon committed Mar 3, 2023
1 parent 377a94b commit d01c52a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 11 additions & 2 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])

Expand Down

0 comments on commit d01c52a

Please sign in to comment.