From 152ff008a3ed2f2d14e70e851e4039845ae12138 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 5 Apr 2020 12:55:46 +0200 Subject: [PATCH] Extract utility methods to common.js --- common.js | 25 +++++++++++++++++++++ dist/index.js | 61 +++++++++++++++++++++++++++++++-------------------- index.js | 26 ++-------------------- 3 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 common.js diff --git a/common.js b/common.js new file mode 100644 index 0000000..a62a7a8 --- /dev/null +++ b/common.js @@ -0,0 +1,25 @@ +const os = require('os') +const fs = require('fs') + +export function getVirtualEnvironmentName() { + const platform = os.platform() + if (platform === 'linux') { + return `ubuntu-${findUbuntuVersion()}` + } else if (platform === 'darwin') { + return 'macos-latest' + } else if (platform === 'win32') { + return 'windows-latest' + } else { + throw new Error(`Unknown platform ${platform}`) + } +} + +function findUbuntuVersion() { + const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8') + const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m) + if (match) { + return match[1] + } else { + throw new Error('Could not find Ubuntu version') + } +} diff --git a/dist/index.js b/dist/index.js index d2dec9b..dd66826 100644 --- a/dist/index.js +++ b/dist/index.js @@ -961,10 +961,11 @@ const fs = __webpack_require__(747) const path = __webpack_require__(622) const core = __webpack_require__(470) const exec = __webpack_require__(986) +const common = __webpack_require__(239) async function run() { try { - const platform = getVirtualEnvironmentName() + const platform = common.getVirtualEnvironmentName() const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version')) let installer @@ -1129,29 +1130,6 @@ function isHeadVersion(rubyVersion) { return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin' } -function getVirtualEnvironmentName() { - const platform = os.platform() - if (platform === 'linux') { - return `ubuntu-${findUbuntuVersion()}` - } else if (platform === 'darwin') { - return 'macos-latest' - } else if (platform === 'win32') { - return 'windows-latest' - } else { - throw new Error(`Unknown platform ${platform}`) - } -} - -function findUbuntuVersion() { - const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8') - const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m) - if (match) { - return match[1] - } else { - throw new Error('Could not find Ubuntu version') - } -} - if (__filename.endsWith('index.js')) { run() } @@ -1497,6 +1475,41 @@ function getVersions(platform) { module.exports = require("https"); +/***/ }), + +/***/ 239: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVirtualEnvironmentName", function() { return getVirtualEnvironmentName; }); +const os = __webpack_require__(87) +const fs = __webpack_require__(747) + +function getVirtualEnvironmentName() { + const platform = os.platform() + if (platform === 'linux') { + return `ubuntu-${findUbuntuVersion()}` + } else if (platform === 'darwin') { + return 'macos-latest' + } else if (platform === 'win32') { + return 'windows-latest' + } else { + throw new Error(`Unknown platform ${platform}`) + } +} + +function findUbuntuVersion() { + const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8') + const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m) + if (match) { + return match[1] + } else { + throw new Error('Could not find Ubuntu version') + } +} + + /***/ }), /***/ 280: diff --git a/index.js b/index.js index 70f3b8d..f052449 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,11 @@ const fs = require('fs') const path = require('path') const core = require('@actions/core') const exec = require('@actions/exec') +const common = require('./common') export async function run() { try { - const platform = getVirtualEnvironmentName() + const platform = common.getVirtualEnvironmentName() const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version')) let installer @@ -171,27 +172,4 @@ function isHeadVersion(rubyVersion) { return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin' } -function getVirtualEnvironmentName() { - const platform = os.platform() - if (platform === 'linux') { - return `ubuntu-${findUbuntuVersion()}` - } else if (platform === 'darwin') { - return 'macos-latest' - } else if (platform === 'win32') { - return 'windows-latest' - } else { - throw new Error(`Unknown platform ${platform}`) - } -} - -function findUbuntuVersion() { - const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8') - const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m) - if (match) { - return match[1] - } else { - throw new Error('Could not find Ubuntu version') - } -} - if (__filename.endsWith('index.js')) { run() }