setup-node/src/main.ts
Dmitry Shibanov 3d0d4edb10
Add node's caching implementation (#2)
* first iteration for implementation of caching

* add logs

* add debug line

* fix build command

* fix path

* add possible post-if

* remove braces

* test new action post-if variant

* work on built-in caching

* remove post-if

* pass version

* work on yarn support

* fix return value

* change names and remove logs

* worked on resolving comments

* check post-if for null

* add success() condition

* remove primary key field

* work on resolving comments

* remove logs

* resolving comments

* resolving comments

* resolving comments

* resolving comments

* fix getpackageManagerVersion

* run clean for unstaged changes

* fix falling version tests

* work on resolving comments

* resolving comments

* fix comment

* resolve comments

* Add tests to cover node's caching (#3)

* add tests to cover node's caching

* work on fixing tests

* fix e2e tests

* rebuild and fix test

* fixing tests

* change name of describes, it and fix test

* add names for jobs

* fix issue
2021-06-16 09:52:44 +03:00

76 lines
2.4 KiB
TypeScript

import * as core from '@actions/core';
import * as installer from './installer';
import * as auth from './authutil';
import * as path from 'path';
import {restoreCache} from './cache-restore';
import {URL} from 'url';
import os = require('os');
export async function run() {
try {
//
// Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc...
//
let version = core.getInput('node-version');
if (!version) {
version = core.getInput('version');
}
let arch = core.getInput('architecture');
const cache = core.getInput('cache');
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
core.warning(
'`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
);
}
if (!arch) {
arch = os.arch();
}
if (version) {
let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`;
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const checkLatest =
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
await installer.getNode(version, stable, checkLatest, auth, arch);
}
const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
}
if (cache) {
if (isGhes()) {
throw new Error('Caching is not supported on GHES');
}
await restoreCache(cache);
}
const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
core.info(
`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`
);
core.info(
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
);
} catch (error) {
core.setFailed(error.message);
}
}
function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
}