minor refactoring

This commit is contained in:
Maxim Lobanov 2021-03-08 18:31:01 +03:00
parent cfdcd6827b
commit 1d25bcb6a7
6 changed files with 49 additions and 114 deletions

View file

@ -1,88 +0,0 @@
name: Main workflow
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: npm install
run: npm install
- name: Lint
run: npm run format-check
- name: npm test
run: npm test
test:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Clear tool cache
if: runner.os != 'windows'
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
- name: Clear tool cache (Windows)
if: runner.os == 'windows'
run: move "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
- name: Setup Java 13
id: setup-java
uses: ./
with:
java-version: 13.0.2
- name: Verify Java 13
if: runner.os != 'windows'
run: __tests__/verify-java.sh 13.0.2 "${{ steps.setup-java.outputs.path }}" "${{ steps.setup-java.outputs.version }}"
- name: Verify Java 13 (Windows)
if: runner.os == 'windows'
run: __tests__/verify-java.ps1 13.0.2 "${{ steps.setup-java.outputs.path }}" "${{ steps.setup-java.outputs.version }}"
test-proxy:
runs-on: ubuntu-latest
container:
image: ubuntu:latest
options: --dns 127.0.0.1
services:
squid-proxy:
image: datadog/squid:latest
ports:
- 3128:3128
env:
https_proxy: http://squid-proxy:3128
steps:
- uses: actions/checkout@v2
- name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup Java 13
id: setup-java
uses: ./
with:
java-version: 13.0.2
- name: Verify Java 13
run: __tests__/verify-java.sh 13.0.2 "${{ steps.setup-java.outputs.path }}" "${{ steps.setup-java.outputs.version }}"
test-bypass-proxy:
runs-on: ubuntu-latest
env:
https_proxy: http://no-such-proxy:3128
no_proxy: github.com,static.azul.com
steps:
- uses: actions/checkout@v2
- name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup Java 13
id: setup-java
uses: ./
with:
java-version: 13.0.2
- name: Verify Java 13
run: __tests__/verify-java.sh 13.0.2 "${{ steps.setup-java.outputs.path }}" "${{ steps.setup-java.outputs.version }}"

View file

@ -1,11 +1,11 @@
{ {
"printWidth": 80, "printWidth": 100,
"tabWidth": 2, "tabWidth": 2,
"useTabs": false, "useTabs": false,
"semi": true, "semi": true,
"singleQuote": true, "singleQuote": true,
"trailingComma": "none", "trailingComma": "none",
"bracketSpacing": false, "bracketSpacing": true,
"arrowParens": "avoid", "arrowParens": "avoid",
"parser": "typescript" "parser": "typescript"
} }

12
dist/cleanup/index.js vendored
View file

@ -1549,7 +1549,9 @@ exports.getVersionFromToolcachePath = getVersionFromToolcachePath;
function extractJdkFile(toolPath, extension) { function extractJdkFile(toolPath, extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!extension) { if (!extension) {
extension = toolPath.endsWith('.tar.gz') ? 'tar.gz' : path_1.default.extname(toolPath); extension = toolPath.endsWith('.tar.gz')
? 'tar.gz'
: path_1.default.extname(toolPath);
if (extension.startsWith('.')) { if (extension.startsWith('.')) {
extension = extension.substring(1); extension = extension.substring(1);
} }
@ -5089,7 +5091,13 @@ function importKey(privateKey) {
} }
} }
}; };
yield exec.exec('gpg', ['--batch', '--import-options', 'import-show', '--import', exports.PRIVATE_KEY_FILE], options); yield exec.exec('gpg', [
'--batch',
'--import-options',
'import-show',
'--import',
exports.PRIVATE_KEY_FILE
], options);
yield io.rmRF(exports.PRIVATE_KEY_FILE); yield io.rmRF(exports.PRIVATE_KEY_FILE);
const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX); const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX);
return match && match[0]; return match && match[0];

35
dist/setup/index.js vendored
View file

@ -3988,7 +3988,7 @@ class JavaBase {
return version; return version;
} }
findInToolcache() { findInToolcache() {
// we can't use tc.find directly because firstly, we need to filter versions by stability // we can't use tc.find directly because firstly, we need to filter versions by stability flag
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions // if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
const availableVersions = tc const availableVersions = tc
.findAllVersions(this.toolcacheFolderName, this.architecture) .findAllVersions(this.toolcacheFolderName, this.architecture)
@ -4019,7 +4019,7 @@ class JavaBase {
normalizeVersion(version) { normalizeVersion(version) {
let stable = true; let stable = true;
if (version.endsWith('-ea')) { if (version.endsWith('-ea')) {
version = version.replace('-ea', ''); version = version.replace(/-ea$/, '');
stable = false; stable = false;
} }
if (!semver_1.default.validRange(version)) { if (!semver_1.default.validRange(version)) {
@ -9367,6 +9367,7 @@ class LocalDistribution extends base_installer_1.JavaBase {
const archivePath = path_1.default.join(extractedJavaPath, archiveName); const archivePath = path_1.default.join(extractedJavaPath, archiveName);
const javaVersion = this.version.raw; const javaVersion = this.version.raw;
let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture);
// for different Java distributions, postfix can exist or not so need to check both cases
if (process.platform === 'darwin' && if (process.platform === 'darwin' &&
fs_1.default.existsSync(path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX))) { fs_1.default.existsSync(path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX))) {
javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX); javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
@ -9383,12 +9384,12 @@ class LocalDistribution extends base_installer_1.JavaBase {
} }
findPackageForDownload(version) { findPackageForDownload(version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
throw new Error('Should not be implemented'); throw new Error('This method should not be implemented in local file provider');
}); });
} }
downloadTool(javaRelease) { downloadTool(javaRelease) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
throw new Error('Should not be implemented'); throw new Error('This method should not be implemented in local file provider');
}); });
} }
} }
@ -12943,7 +12944,9 @@ exports.getVersionFromToolcachePath = getVersionFromToolcachePath;
function extractJdkFile(toolPath, extension) { function extractJdkFile(toolPath, extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!extension) { if (!extension) {
extension = toolPath.endsWith('.tar.gz') ? 'tar.gz' : path_1.default.extname(toolPath); extension = toolPath.endsWith('.tar.gz')
? 'tar.gz'
: path_1.default.extname(toolPath);
if (extension.startsWith('.')) { if (extension.startsWith('.')) {
extension = extension.substring(1); extension = extension.substring(1);
} }
@ -13227,7 +13230,8 @@ function configureAuthentication() {
const id = core.getInput(constants.INPUT_SERVER_ID); const id = core.getInput(constants.INPUT_SERVER_ID);
const username = core.getInput(constants.INPUT_SERVER_USERNAME); const username = core.getInput(constants.INPUT_SERVER_USERNAME);
const password = core.getInput(constants.INPUT_SERVER_PASSWORD); const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY) || constants.INPUT_DEFAULT_GPG_PRIVATE_KEY; const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
const gpgPassphrase = core.getInput(constants.INPUT_GPG_PASSPHRASE) || const gpgPassphrase = core.getInput(constants.INPUT_GPG_PASSPHRASE) ||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined); (gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
if (gpgPrivateKey) { if (gpgPrivateKey) {
@ -13770,7 +13774,9 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
}); });
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
if (!resolvedFullVersion) { if (!resolvedFullVersion) {
const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', '); const availableOptions = availableVersionsWithBinaries
.map(item => item.version)
.join(', ');
const availableOptionsMessage = availableOptions const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
@ -14097,7 +14103,9 @@ class ZuluDistribution extends base_installer_1.JavaBase {
}); });
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
if (!resolvedFullVersion) { if (!resolvedFullVersion) {
const availableOptions = availableVersions.map(item => item.version).join(', '); const availableOptions = availableVersions
.map(item => item.version)
.join(', ');
const availableOptionsMessage = availableOptions const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
@ -14147,7 +14155,8 @@ class ZuluDistribution extends base_installer_1.JavaBase {
if (core.isDebug()) { if (core.isDebug()) {
core.debug(`Gathering available versions from '${availableVersionsUrl}'`); core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
} }
const availableVersions = (_b = (yield this.http.getJson(availableVersionsUrl)).result) !== null && _b !== void 0 ? _b : []; const availableVersions = (_b = (yield this.http.getJson(availableVersionsUrl))
.result) !== null && _b !== void 0 ? _b : [];
if (core.isDebug()) { if (core.isDebug()) {
core.startGroup('Print information about available versions'); core.startGroup('Print information about available versions');
console.timeEnd('azul-retrieve-available-versions'); console.timeEnd('azul-retrieve-available-versions');
@ -41109,7 +41118,13 @@ function importKey(privateKey) {
} }
} }
}; };
yield exec.exec('gpg', ['--batch', '--import-options', 'import-show', '--import', exports.PRIVATE_KEY_FILE], options); yield exec.exec('gpg', [
'--batch',
'--import-options',
'import-show',
'--import',
exports.PRIVATE_KEY_FILE
], options);
yield io.rmRF(exports.PRIVATE_KEY_FILE); yield io.rmRF(exports.PRIVATE_KEY_FILE);
const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX); const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX);
return match && match[0]; return match && match[0];

View file

@ -60,7 +60,7 @@ export abstract class JavaBase {
} }
protected findInToolcache(): JavaInstallerResults | null { protected findInToolcache(): JavaInstallerResults | null {
// we can't use tc.find directly because firstly, we need to filter versions by stability // we can't use tc.find directly because firstly, we need to filter versions by stability flag
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions // if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
const availableVersions = tc const availableVersions = tc
.findAllVersions(this.toolcacheFolderName, this.architecture) .findAllVersions(this.toolcacheFolderName, this.architecture)
@ -97,7 +97,7 @@ export abstract class JavaBase {
let stable = true; let stable = true;
if (version.endsWith('-ea')) { if (version.endsWith('-ea')) {
version = version.replace('-ea', ''); version = version.replace(/-ea$/, '');
stable = false; stable = false;
} }

View file

@ -69,10 +69,10 @@ export class LocalDistribution extends JavaBase {
} }
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> { protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> {
throw new Error('Should not be implemented'); throw new Error('This method should not be implemented in local file provider');
} }
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> { protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
throw new Error('Should not be implemented'); throw new Error('This method should not be implemented in local file provider');
} }
} }