3
0
Fork 0
mirror of https://gitea.com/actions/setup-node.git synced 2024-11-28 13:09:32 +01:00
setup-node/node_modules/windows-release/index.js
Danny McCormick 78148dae50
Add auth support (#21)
* Updates

* Update

* Update

* Update

* Update

* Yarn sometimes prefers npmrc, so use same token

* Description

* Update readme

* Feedback

* Add type

* new toolkit and scoped registries

* npmrc in RUNNER_TEMP

* Dont always auth

* Try exporting blank token

* Get auth working for now pending runner changes

* Fix string interpolation for auth token.

* Don't export both userconfigs

* Update authutil.js

* Add single quotes for authString

* Fix the registry string.

* Use userconfig and append trailing slash

* Keep in root of repo

* Try just adding auth token

* Remove auth token

* Try changes again

* Add tests

* Npm and GPR samples

* Add types
2019-08-06 18:26:04 -04:00

44 lines
1.3 KiB
JavaScript

'use strict';
const os = require('os');
const execa = require('execa');
// Reference: https://www.gaijin.at/en/lstwinver.php
const names = new Map([
['10.0', '10'],
['6.3', '8.1'],
['6.2', '8'],
['6.1', '7'],
['6.0', 'Vista'],
['5.2', 'Server 2003'],
['5.1', 'XP'],
['5.0', '2000'],
['4.9', 'ME'],
['4.1', '98'],
['4.0', '95']
]);
const windowsRelease = release => {
const version = /\d+\.\d/.exec(release || os.release());
if (release && !version) {
throw new Error('`release` argument doesn\'t match `n.n`');
}
const ver = (version || [])[0];
// Server 2008, 2012 and 2016 versions are ambiguous with desktop versions and must be detected at runtime.
// If `release` is omitted or we're on a Windows system, and the version number is an ambiguous version
// then use `wmic` to get the OS caption: https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx
// If the resulting caption contains the year 2008, 2012 or 2016, it is a server version, so return a server OS name.
if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) {
const stdout = execa.sync('wmic', ['os', 'get', 'Caption']).stdout || '';
const year = (stdout.match(/2008|2012|2016/) || [])[0];
if (year) {
return `Server ${year}`;
}
}
return names.get(ver);
};
module.exports = windowsRelease;