Skip to content

Commit d5f787c

Browse files
committed
Define a helper to download to avoid duplication
1 parent 1010da4 commit d5f787c

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,8 @@ export function isExactCacheKeyMatch(key, cacheKey) {
442442
}) === 0
443443
);
444444
}
445+
446+
export async function download(url) {
447+
const auth = inputs.token ? `token ${inputs.token}` : undefined
448+
return await tc.downloadTool(url, undefined, auth)
449+
}

dist/index.js

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

ruby-builder.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const path = require('path')
44
const core = require('@actions/core')
55
const exec = require('@actions/exec')
66
const io = require('@actions/io')
7-
const tc = require('@actions/tool-cache')
87
const common = require('./common')
98
const rubyBuilderVersions = require('./ruby-builder-versions')
109

@@ -74,9 +73,8 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) {
7473
const downloadPath = await common.measure('Downloading Ruby', async () => {
7574
const url = getDownloadURL(platform, engine, version)
7675
console.log(url)
77-
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
7876
try {
79-
return await tc.downloadTool(url, undefined, auth)
77+
return await common.download(url)
8078
} catch (error) {
8179
if (error.message.includes('404')) {
8280
throw new Error(`Unavailable version ${version} for ${engine} on ${platform}

windows.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const path = require('path')
77
const cp = require('child_process')
88
const core = require('@actions/core')
99
const exec = require('@actions/exec')
10-
const tc = require('@actions/tool-cache')
1110
const common = require('./common')
1211
const rubyInstallerVersions = require('./windows-versions.json')
1312
const toolchainVersions = require('./windows-toolchain-versions.json')
@@ -81,8 +80,7 @@ export async function install(platform, engine, version) {
8180
async function downloadAndExtract(engine, version, url, base, rubyPrefix) {
8281
const downloadPath = await common.measure('Downloading Ruby', async () => {
8382
console.log(url)
84-
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
85-
return await tc.downloadTool(url, undefined, auth)
83+
return await common.download(url)
8684
})
8785

8886
const extractPath = process.env.RUNNER_TEMP
@@ -114,8 +112,7 @@ export async function installJRubyTools() {
114112
async function installMSYS2(url, rubyPrefix = process.env.RUNNER_TEMP) {
115113
const downloadPath = await common.measure('Downloading msys2 build tools', async () => {
116114
console.log(url)
117-
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
118-
return await tc.downloadTool(url, undefined, auth)
115+
return await common.download(url)
119116
})
120117

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

163160
const downloadPath = await common.measure('Downloading msys1 build tools', async () => {
164161
console.log(url)
165-
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
166-
return await tc.downloadTool(url, undefined, auth)
162+
return await common.download(url)
167163
})
168164

169165
const msys1Path = `${common.drive}:\\DevKit64`
@@ -199,8 +195,7 @@ async function installMSYS1(url) {
199195
async function installVCPKG(url) {
200196
const downloadPath = await common.measure('Downloading mswin vcpkg packages', async () => {
201197
console.log(url)
202-
const auth = common.inputs.token ? `token ${common.inputs.token}` : undefined
203-
return await tc.downloadTool(url, undefined, auth)
198+
return await common.download(url)
204199
})
205200

206201
const extractPath = process.env.VCPKG_INSTALLATION_ROOT

0 commit comments

Comments
 (0)