From 77a546c265a09dbf54594101fc4fdf7cb3028303 Mon Sep 17 00:00:00 2001 From: Ben Ford Date: Wed, 21 Jan 2026 15:29:40 -0800 Subject: [PATCH] add hook for setup script This gives you the ability to pass script text to the `setup-ruby` action. The script will be executed after Ruby and Bundler are installed, but before `bundle install` is run. If you want to execute a script on disk, just pass the filename, like `'./setup.sh'` or `'ruby setup.rb'` If you intend to use this to install a custom Bundler version or the like, make sure to specify `bundler: none` so you don't get a second version installed. --- action.yml | 5 +++++ dist/index.js | 10 ++++++++++ index.js | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/action.yml b/action.yml index 733938dbe..402c26d9d 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,11 @@ inputs: For 'latest', `gem update --system` is run to update to the latest compatible RubyGems version. Ruby head/master builds will not be updated. Similarly, if a version number is given, `gem update --system ` is run to update to that version of RubyGems, as long as that version is newer than the one provided by default. + setup-script: + description: | + Setup code to be executed after Ruby and Bundler are installed, but before `bundle install` is run. + If you want to execute a script on disk, just pass the filename, like `'./setup.sh'` or `'ruby setup.rb'` + If you intend to use this to install a custom Bundler version or the like, make sure to specify `bundler: none`. bundler: description: | The version of Bundler to install. Either 'Gemfile.lock' (the default), 'default', 'latest', 'none', or a version number (e.g., 1, 2, 2.1, 2.1.4). diff --git a/dist/index.js b/dist/index.js index 801b222ca..da22b2e49 100644 --- a/dist/index.js +++ b/dist/index.js @@ -92443,6 +92443,7 @@ const inputDefaults = { 'rubygems': 'default', 'bundler': 'Gemfile.lock', 'bundler-cache': 'false', + 'setup-script': '', 'working-directory': '.', 'cache-version': bundler.DEFAULT_CACHE_VERSION, 'self-hosted': 'false', @@ -92527,6 +92528,15 @@ async function setupRuby(options = {}) { bundler.installBundler(inputs['bundler'], rubygemsInputSet, lockFile, platform, rubyPrefix, engine, version)) } + if (inputs['setup-script'] !== '') { + await common.measure('Running setup script', async () => { + const lines = inputs['setup-script'].split(/\r?\n/) + for (const line of lines) { + await exec.exec(line) + } + }) + } + if (inputs['bundler-cache'] === 'true') { await common.time('bundle install', async () => bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version'])) diff --git a/index.js b/index.js index 29c753d1e..b171c5028 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ const inputDefaults = { 'rubygems': 'default', 'bundler': 'Gemfile.lock', 'bundler-cache': 'false', + 'setup-script': '', 'working-directory': '.', 'cache-version': bundler.DEFAULT_CACHE_VERSION, 'self-hosted': 'false', @@ -98,6 +99,15 @@ export async function setupRuby(options = {}) { bundler.installBundler(inputs['bundler'], rubygemsInputSet, lockFile, platform, rubyPrefix, engine, version)) } + if (inputs['setup-script'] !== '') { + await common.measure('Running setup script', async () => { + const lines = inputs['setup-script'].split(/\r?\n/) + for (const line of lines) { + await exec.exec(line) + } + }) + } + if (inputs['bundler-cache'] === 'true') { await common.time('bundle install', async () => bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version']))