Skip to content

Commit 7c51083

Browse files
committed
Add token input and pass it to release assets download.
1 parent b90be12 commit 7c51083

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ and the [condition and expression syntax](https://help.github.com/en/actions/ref
152152
The `working-directory` input can be set to resolve `.ruby-version`, `.tool-versions`, `mise.toml` and `Gemfile.lock`
153153
if they are not at the root of the repository, see [action.yml](action.yml) for details.
154154

155+
### Authentication Token
156+
157+
By default, this action uses `${{ github.token }}` to authenticate when downloading Ruby release assets from GitHub.
158+
This helps avoid rate limiting issues.
159+
160+
If you're running this action on a GitHub Enterprise Server (GHES) instance, or if you're experiencing rate limiting,
161+
you can provide a custom token:
162+
163+
```yaml
164+
- uses: ruby/setup-ruby@v1
165+
with:
166+
ruby-version: '3.4'
167+
token: ${{ secrets.MY_GITHUB_TOKEN }}
168+
```
169+
170+
In most cases, you don't need to set this input as the default value is sufficient for use on github.com.
171+
155172
### RubyGems
156173

157174
By default, the default RubyGems version that comes with each Ruby is used.

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ inputs:
4444
It also sets environment variables using 'ridk' or 'vcvars64.bat' based on the selected Ruby.
4545
At present, the only other setting than 'default' is 'none', which only adds Ruby to PATH.
4646
No build tools or packages are installed, nor are any ENV setting changed to activate them.
47+
token:
48+
description: |
49+
Used to authenticate with GitHub when downloading Ruby release assets.
50+
Since there is a default, this is typically not supplied by the user.
51+
When running this action on github.com, the default value is sufficient.
52+
When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
53+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
4754

4855
outputs:
4956
ruby-prefix:

common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const drive = (windows ? (process.env['RUNNER_TEMP'] || 'C')[0] : undefin
1616
const PATH_ENV_VAR = windows ? 'Path' : 'PATH'
1717

1818
export const inputs = {
19-
selfHosted: undefined
19+
selfHosted: undefined,
20+
token: undefined
2021
}
2122

2223
export function partition(string, separator) {

dist/index.js

Lines changed: 14 additions & 6 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
@@ -18,6 +18,7 @@ const inputDefaults = {
1818
'cache-version': bundler.DEFAULT_CACHE_VERSION,
1919
'self-hosted': 'false',
2020
'windows-toolchain': 'default',
21+
'token': '',
2122
}
2223

2324
// entry point when this action is run on its own
@@ -45,6 +46,7 @@ export async function setupRuby(options = {}) {
4546
}
4647
}
4748
common.inputs.selfHosted = inputs['self-hosted']
49+
common.inputs.token = inputs['token']
4850

4951
process.chdir(inputs['working-directory'])
5052

ruby-builder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) {
7474
const downloadPath = await common.measure('Downloading Ruby', async () => {
7575
const url = getDownloadURL(platform, engine, version)
7676
console.log(url)
77+
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
7778
try {
78-
return await tc.downloadTool(url)
79+
return await tc.downloadTool(url, undefined, auth)
7980
} catch (error) {
8081
if (error.message.includes('404')) {
8182
throw new Error(`Unavailable version ${version} for ${engine} on ${platform}

windows.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export async function install(platform, engine, version) {
8181
async function downloadAndExtract(engine, version, url, base, rubyPrefix) {
8282
const downloadPath = await common.measure('Downloading Ruby', async () => {
8383
console.log(url)
84-
return await tc.downloadTool(url)
84+
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
85+
return await tc.downloadTool(url, undefined, auth)
8586
})
8687

8788
const extractPath = process.env.RUNNER_TEMP
@@ -113,7 +114,8 @@ export async function installJRubyTools() {
113114
async function installMSYS2(url, rubyPrefix = process.env.RUNNER_TEMP) {
114115
const downloadPath = await common.measure('Downloading msys2 build tools', async () => {
115116
console.log(url)
116-
return await tc.downloadTool(url)
117+
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
118+
return await tc.downloadTool(url, undefined, auth)
117119
})
118120

119121
const extractPath = path.join(process.env.RUNNER_TEMP, 'msys64')
@@ -160,7 +162,8 @@ async function installMSYS1(url) {
160162

161163
const downloadPath = await common.measure('Downloading msys1 build tools', async () => {
162164
console.log(url)
163-
return await tc.downloadTool(url)
165+
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
166+
return await tc.downloadTool(url, undefined, auth)
164167
})
165168

166169
const msys1Path = `${common.drive}:\\DevKit64`
@@ -196,7 +199,8 @@ async function installMSYS1(url) {
196199
async function installVCPKG(url) {
197200
const downloadPath = await common.measure('Downloading mswin vcpkg packages', async () => {
198201
console.log(url)
199-
return await tc.downloadTool(url)
202+
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
203+
return await tc.downloadTool(url, undefined, auth)
200204
})
201205

202206
const extractPath = process.env.VCPKG_INSTALLATION_ROOT

0 commit comments

Comments
 (0)