Skip to content

Commit d01c52a

Browse files
committed
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).
1 parent 377a94b commit d01c52a

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ inputs:
3030
description: |
3131
Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need
3232
to invalidate the cache.
33+
self-hosted:
34+
description: |
35+
Consider the runner as a self-hosted runner, which means not using prebuilt Ruby binaries which only work
36+
on GitHub-hosted runners or self-hosted runners with a very similar image to the ones used by GitHub runners.
37+
The default is to detect this automatically based on the OS, OS version and $RUNNER_TOOL_CACHE.
3338
outputs:
3439
ruby-prefix:
3540
description: 'The prefix of the installed ruby'

common.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const windows = (os.platform() === 'win32')
1313
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
1414
export const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
1515

16+
export const inputs = {
17+
selfHosted: undefined
18+
}
19+
1620
export function partition(string, separator) {
1721
const i = string.indexOf(separator)
1822
if (i === -1) {
@@ -166,8 +170,13 @@ const GitHubHostedPlatforms = [
166170
// * the OS and OS version does not correspond to a GitHub-hosted runner image,
167171
// * or the hosted tool cache is different from the default tool cache path
168172
export function isSelfHostedRunner() {
169-
return !GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
170-
getRunnerToolCache() !== getDefaultToolCachePath()
173+
if (inputs.selfHosted === undefined) {
174+
throw new Error('inputs.selfHosted should have been already set')
175+
}
176+
177+
return inputs.selfHosted === 'true' ||
178+
!GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
179+
getRunnerToolCache() !== getDefaultToolCachePath()
171180
}
172181

173182
let virtualEnvironmentName = undefined

dist/index.js

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const inputDefaults = {
1616
'bundler-cache': 'false',
1717
'working-directory': '.',
1818
'cache-version': bundler.DEFAULT_CACHE_VERSION,
19+
'self-hosted': 'false',
1920
}
2021

2122
// entry point when this action is run on its own
@@ -39,6 +40,7 @@ export async function setupRuby(options = {}) {
3940
inputs[key] = core.getInput(key) || inputDefaults[key]
4041
}
4142
}
43+
common.inputs.selfHosted = inputs['self-hosted']
4244

4345
process.chdir(inputs['working-directory'])
4446

0 commit comments

Comments
 (0)