actions/setup-java@v2 - Support different distributions (#132)

* Implement support for custom vendors in setup-java

* minor improvements

* minor refactoring

* Add unit tests and e2e tests

* Update documentation for setup-java@v2 release

* minor improvements

* regenerate dist

* fix comments

* resolve comments

* resolve comments

* fix tests

* Update README.md

Co-authored-by: George Adams <george.adams@microsoft.com>

* Apply suggestions from code review

Co-authored-by: Konrad Pabjan <konradpabjan@github.com>

* fix minor nitpicks

* handle 4th digit

* pull latest main

* Update README.md

* rename adoptium to adopt

* rename adoptium to adopt

* rename adoptium to adopt

* Update README.md

* make java-version and distribution required for action

* update readme

* fix tests

* fix e2e tests

Co-authored-by: George Adams <george.adams@microsoft.com>
Co-authored-by: Konrad Pabjan <konradpabjan@github.com>
This commit is contained in:
Maxim Lobanov 2021-03-15 13:39:46 +03:00 committed by GitHub
parent e73e96a93b
commit 7c88894700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 40141 additions and 22003 deletions

View file

@ -1,14 +1,7 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');
// make the os.homedir() call be local to the tests
jest.doMock('os', () => {
return {
homedir: jest.fn(() => __dirname)
};
});
import os from 'os';
import * as auth from '../src/auth';
@ -16,8 +9,12 @@ const m2Dir = path.join(__dirname, auth.M2_DIR);
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
describe('auth tests', () => {
let spyOSHomedir: jest.SpyInstance;
beforeEach(async () => {
await io.rmRF(m2Dir);
spyOSHomedir = jest.spyOn(os, 'homedir');
spyOSHomedir.mockReturnValue(__dirname);
}, 300000);
afterAll(async () => {
@ -26,6 +23,9 @@ describe('auth tests', () => {
} catch {
console.log('Failed to remove test directories');
}
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
}, 100000);
it('creates settings.xml in alternate locations', async () => {
@ -38,7 +38,7 @@ describe('auth tests', () => {
process.env[`INPUT_SETTINGS-PATH`] = altHome;
await io.rmRF(altHome); // ensure it doesn't already exist
await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);
expect(fs.existsSync(m2Dir)).toBe(false);
expect(fs.existsSync(settingsFile)).toBe(false);
@ -58,13 +58,11 @@ describe('auth tests', () => {
const username = 'UNAME';
const password = 'TOKEN';
await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(auth.generate(id, username, password));
}, 100000);
it('creates settings.xml with additional configuration', async () => {
@ -73,7 +71,7 @@ describe('auth tests', () => {
const password = 'TOKEN';
const gpgPassphrase = 'GPG';
await auth.configAuthentication(id, username, password, gpgPassphrase);
await auth.createAuthenticationSettings(id, username, password, gpgPassphrase);
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
@ -87,18 +85,16 @@ describe('auth tests', () => {
const username = 'USERNAME';
const password = 'PASSWORD';
fs.mkdirSync(m2Dir, {recursive: true});
fs.mkdirSync(m2Dir, { recursive: true });
fs.writeFileSync(settingsFile, 'FAKE FILE');
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(auth.generate(id, username, password));
}, 100000);
it('generates valid settings.xml with minimal configuration', () => {
@ -143,8 +139,6 @@ describe('auth tests', () => {
</servers>
</settings>`;
expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
expectedSettings
);
expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(expectedSettings);
});
});