diff --git a/dist/index.js b/dist/index.js index f66c5a4..895674b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1792,6 +1792,9 @@ const io = __webpack_require__(1) const tc = __webpack_require__(533) const axios = __webpack_require__(53) +const releasesURL = 'https://github.com/eregon/ruby-install-builder/releases' +const metadataURL = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata' + async function run() { try { const ruby = await getRubyEngineAndVersion(core.getInput('ruby-version')) @@ -1800,7 +1803,8 @@ async function run() { await io.mkdirP(rubiesDir) const platform = getVirtualEnvironmentName() - const url = `https://github.com/eregon/ruby-install-builder/releases/download/builds/${ruby}-${platform}.tar.gz` + const tag = await getLatestReleaseTag() + const url = `${releasesURL}/download/${tag}/${ruby}-${platform}.tar.gz` console.log(url) const downloadPath = await tc.downloadTool(url) @@ -1814,13 +1818,17 @@ async function run() { } } +async function getLatestReleaseTag() { + const response = await axios.get(`${metadataURL}/latest_release.tag`) + return response.data.trim() +} + async function getRubyEngineAndVersion(rubyVersion) { if (rubyVersion.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z return 'ruby-' + rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion const engine = rubyVersion - const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' - const response = await axios.get(versionsUrl) + const response = await axios.get(`${metadataURL}/versions.json`) const stableVersions = response.data[engine] const latestStableVersion = stableVersions[stableVersions.length-1] return engine + '-' + latestStableVersion diff --git a/index.js b/index.js index 03b1831..71f1323 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,9 @@ const io = require('@actions/io') const tc = require('@actions/tool-cache') const axios = require('axios') +const releasesURL = 'https://github.com/eregon/ruby-install-builder/releases' +const metadataURL = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata' + async function run() { try { const ruby = await getRubyEngineAndVersion(core.getInput('ruby-version')) @@ -13,7 +16,8 @@ async function run() { await io.mkdirP(rubiesDir) const platform = getVirtualEnvironmentName() - const url = `https://github.com/eregon/ruby-install-builder/releases/download/builds/${ruby}-${platform}.tar.gz` + const tag = await getLatestReleaseTag() + const url = `${releasesURL}/download/${tag}/${ruby}-${platform}.tar.gz` console.log(url) const downloadPath = await tc.downloadTool(url) @@ -27,13 +31,17 @@ async function run() { } } +async function getLatestReleaseTag() { + const response = await axios.get(`${metadataURL}/latest_release.tag`) + return response.data.trim() +} + async function getRubyEngineAndVersion(rubyVersion) { if (rubyVersion.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z return 'ruby-' + rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion const engine = rubyVersion - const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' - const response = await axios.get(versionsUrl) + const response = await axios.get(`${metadataURL}/versions.json`) const stableVersions = response.data[engine] const latestStableVersion = stableVersions[stableVersions.length-1] return engine + '-' + latestStableVersion