From 7f50f6e3b36eb57491405d1cd2f4270349273884 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Tue, 6 Jan 2026 00:21:26 +0000 Subject: [PATCH] Add token input and pass it to release assets download. --- README.md | 17 +++++++++++++++++ action.yml | 7 +++++++ common.js | 3 ++- dist/index.js | 20 ++++++++++++++------ index.js | 2 ++ ruby-builder.js | 3 ++- windows.js | 12 ++++++++---- 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6f13dbc..1ddfa86 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,23 @@ and the [condition and expression syntax](https://help.github.com/en/actions/ref The `working-directory` input can be set to resolve `.ruby-version`, `.tool-versions`, `mise.toml` and `Gemfile.lock` if they are not at the root of the repository, see [action.yml](action.yml) for details. +### Authentication Token + +By default, this action uses `${{ github.token }}` to authenticate when downloading Ruby release assets from GitHub. +This helps avoid rate limiting issues. + +If you're running this action on a GitHub Enterprise Server (GHES) instance, or if you're experiencing rate limiting, +you can provide a custom token: + +```yaml + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + token: ${{ secrets.MY_GITHUB_TOKEN }} +``` + +In most cases, you don't need to set this input as the default value is sufficient for use on github.com. + ### RubyGems By default, the default RubyGems version that comes with each Ruby is used. diff --git a/action.yml b/action.yml index 3e05212..3b8daad 100644 --- a/action.yml +++ b/action.yml @@ -44,6 +44,13 @@ inputs: It also sets environment variables using 'ridk' or 'vcvars64.bat' based on the selected Ruby. At present, the only other setting than 'default' is 'none', which only adds Ruby to PATH. No build tools or packages are installed, nor are any ENV setting changed to activate them. + token: + description: | + Used to authenticate with GitHub when downloading Ruby release assets. + Since there is a default, this is typically not supplied by the user. + When running this action on github.com, the default value is sufficient. + When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. + default: ${{ github.server_url == 'https://github.com' && github.token || '' }} outputs: ruby-prefix: diff --git a/common.js b/common.js index 7e8b0e5..988d0ba 100644 --- a/common.js +++ b/common.js @@ -16,7 +16,8 @@ export const drive = (windows ? (process.env['RUNNER_TEMP'] || 'C')[0] : undefin const PATH_ENV_VAR = windows ? 'Path' : 'PATH' export const inputs = { - selfHosted: undefined + selfHosted: undefined, + token: undefined } export function partition(string, separator) { diff --git a/dist/index.js b/dist/index.js index 20ffc9a..dbf8d09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -348,7 +348,8 @@ const drive = (windows ? (process.env['RUNNER_TEMP'] || 'C')[0] : undefined) const PATH_ENV_VAR = windows ? 'Path' : 'PATH' const inputs = { - selfHosted: undefined + selfHosted: undefined, + token: undefined } function partition(string, separator) { @@ -71373,8 +71374,9 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) { const downloadPath = await common.measure('Downloading Ruby', async () => { const url = getDownloadURL(platform, engine, version) console.log(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined try { - return await tc.downloadTool(url) + return await tc.downloadTool(url, undefined, auth) } catch (error) { if (error.message.includes('404')) { throw new Error(`Unavailable version ${version} for ${engine} on ${platform} @@ -71599,7 +71601,8 @@ async function install(platform, engine, version) { async function downloadAndExtract(engine, version, url, base, rubyPrefix) { const downloadPath = await common.measure('Downloading Ruby', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = process.env.RUNNER_TEMP @@ -71631,7 +71634,8 @@ async function installJRubyTools() { async function installMSYS2(url, rubyPrefix = process.env.RUNNER_TEMP) { const downloadPath = await common.measure('Downloading msys2 build tools', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = path.join(process.env.RUNNER_TEMP, 'msys64') @@ -71678,7 +71682,8 @@ async function installMSYS1(url) { const downloadPath = await common.measure('Downloading msys1 build tools', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const msys1Path = `${common.drive}:\\DevKit64` @@ -71714,7 +71719,8 @@ async function installMSYS1(url) { async function installVCPKG(url) { const downloadPath = await common.measure('Downloading mswin vcpkg packages', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = process.env.VCPKG_INSTALLATION_ROOT @@ -85300,6 +85306,7 @@ const inputDefaults = { 'cache-version': bundler.DEFAULT_CACHE_VERSION, 'self-hosted': 'false', 'windows-toolchain': 'default', + 'token': '', } // entry point when this action is run on its own @@ -85327,6 +85334,7 @@ async function setupRuby(options = {}) { } } common.inputs.selfHosted = inputs['self-hosted'] + common.inputs.token = inputs['token'] process.chdir(inputs['working-directory']) diff --git a/index.js b/index.js index d6fc89c..29c753d 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ const inputDefaults = { 'cache-version': bundler.DEFAULT_CACHE_VERSION, 'self-hosted': 'false', 'windows-toolchain': 'default', + 'token': '', } // entry point when this action is run on its own @@ -45,6 +46,7 @@ export async function setupRuby(options = {}) { } } common.inputs.selfHosted = inputs['self-hosted'] + common.inputs.token = inputs['token'] process.chdir(inputs['working-directory']) diff --git a/ruby-builder.js b/ruby-builder.js index c2d9713..b0173c5 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -74,8 +74,9 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) { const downloadPath = await common.measure('Downloading Ruby', async () => { const url = getDownloadURL(platform, engine, version) console.log(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined try { - return await tc.downloadTool(url) + return await tc.downloadTool(url, undefined, auth) } catch (error) { if (error.message.includes('404')) { throw new Error(`Unavailable version ${version} for ${engine} on ${platform} diff --git a/windows.js b/windows.js index 12567ec..0a33ce3 100644 --- a/windows.js +++ b/windows.js @@ -81,7 +81,8 @@ export async function install(platform, engine, version) { async function downloadAndExtract(engine, version, url, base, rubyPrefix) { const downloadPath = await common.measure('Downloading Ruby', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = process.env.RUNNER_TEMP @@ -113,7 +114,8 @@ export async function installJRubyTools() { async function installMSYS2(url, rubyPrefix = process.env.RUNNER_TEMP) { const downloadPath = await common.measure('Downloading msys2 build tools', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = path.join(process.env.RUNNER_TEMP, 'msys64') @@ -160,7 +162,8 @@ async function installMSYS1(url) { const downloadPath = await common.measure('Downloading msys1 build tools', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const msys1Path = `${common.drive}:\\DevKit64` @@ -196,7 +199,8 @@ async function installMSYS1(url) { async function installVCPKG(url) { const downloadPath = await common.measure('Downloading mswin vcpkg packages', async () => { console.log(url) - return await tc.downloadTool(url) + const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined + return await tc.downloadTool(url, undefined, auth) }) const extractPath = process.env.VCPKG_INSTALLATION_ROOT