From 1d25bcb6a75132ef47d478d0ba711f1b6cea95ba Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 8 Mar 2021 18:31:01 +0300 Subject: [PATCH] minor refactoring --- .github/workflows/workflow.yml | 88 ---------------------------- .prettierrc.json | 20 +++---- dist/cleanup/index.js | 12 +++- dist/setup/index.js | 35 +++++++---- src/distributions/base-installer.ts | 4 +- src/distributions/local/installer.ts | 4 +- 6 files changed, 49 insertions(+), 114 deletions(-) delete mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index 1b7aa658..00000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -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 }}" diff --git a/.prettierrc.json b/.prettierrc.json index f6736bc7..a2f723bf 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,11 +1,11 @@ { - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "trailingComma": "none", - "bracketSpacing": false, - "arrowParens": "avoid", - "parser": "typescript" - } \ No newline at end of file + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "none", + "bracketSpacing": true, + "arrowParens": "avoid", + "parser": "typescript" +} diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index dbcef343..a533d265 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -1549,7 +1549,9 @@ exports.getVersionFromToolcachePath = getVersionFromToolcachePath; function extractJdkFile(toolPath, extension) { return __awaiter(this, void 0, void 0, function* () { 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('.')) { 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); const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX); return match && match[0]; diff --git a/dist/setup/index.js b/dist/setup/index.js index cee52dd1..7248575e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3988,7 +3988,7 @@ class JavaBase { return version; } 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 const availableVersions = tc .findAllVersions(this.toolcacheFolderName, this.architecture) @@ -4019,7 +4019,7 @@ class JavaBase { normalizeVersion(version) { let stable = true; if (version.endsWith('-ea')) { - version = version.replace('-ea', ''); + version = version.replace(/-ea$/, ''); stable = false; } 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 javaVersion = this.version.raw; 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' && 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); @@ -9383,12 +9384,12 @@ class LocalDistribution extends base_installer_1.JavaBase { } findPackageForDownload(version) { 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) { 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) { return __awaiter(this, void 0, void 0, function* () { 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('.')) { extension = extension.substring(1); } @@ -13227,7 +13230,8 @@ function configureAuthentication() { const id = core.getInput(constants.INPUT_SERVER_ID); const username = core.getInput(constants.INPUT_SERVER_USERNAME); 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) || (gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined); if (gpgPrivateKey) { @@ -13770,7 +13774,9 @@ class AdoptiumDistribution extends base_installer_1.JavaBase { }); const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; if (!resolvedFullVersion) { - const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', '); + const availableOptions = availableVersionsWithBinaries + .map(item => item.version) + .join(', '); const availableOptionsMessage = availableOptions ? `\nAvailable versions: ${availableOptions}` : ''; @@ -14097,7 +14103,9 @@ class ZuluDistribution extends base_installer_1.JavaBase { }); const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; if (!resolvedFullVersion) { - const availableOptions = availableVersions.map(item => item.version).join(', '); + const availableOptions = availableVersions + .map(item => item.version) + .join(', '); const availableOptionsMessage = availableOptions ? `\nAvailable versions: ${availableOptions}` : ''; @@ -14147,7 +14155,8 @@ class ZuluDistribution extends base_installer_1.JavaBase { if (core.isDebug()) { 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()) { core.startGroup('Print information about 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); const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX); return match && match[0]; diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 622e7e8b..3798c3e9 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -60,7 +60,7 @@ export abstract class JavaBase { } 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 const availableVersions = tc .findAllVersions(this.toolcacheFolderName, this.architecture) @@ -97,7 +97,7 @@ export abstract class JavaBase { let stable = true; if (version.endsWith('-ea')) { - version = version.replace('-ea', ''); + version = version.replace(/-ea$/, ''); stable = false; } diff --git a/src/distributions/local/installer.ts b/src/distributions/local/installer.ts index 8ccd080f..672564c3 100644 --- a/src/distributions/local/installer.ts +++ b/src/distributions/local/installer.ts @@ -69,10 +69,10 @@ export class LocalDistribution extends JavaBase { } protected async findPackageForDownload(version: semver.Range): Promise { - 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 { - throw new Error('Should not be implemented'); + throw new Error('This method should not be implemented in local file provider'); } }