mirror of
https://github.com/actions/setup-java.git
synced 2025-06-29 04:24:14 +00:00
Add support for maven/gradle versions
- Essentially use same concepts as jdk install to switch maven and gradle versions if those are defined with config. - Bump to tool-cache 1.3.0 as 1.0.0 tries to use node_modules/@actions/tool-cache/scripts/externals/unzip which doesn't have execute flag so you'd get `Permission denied` - `extractZipNix` in toolkit no longer support relative path so needs to resolve absolute path before passing file to these methods. - Commit has my local build for `index.js` which probably should get recreated but makes it easier to test this from a PR branch. - Fixes #40
This commit is contained in:
parent
b52cd69bd2
commit
7b8939ae83
11 changed files with 5380 additions and 2890 deletions
127
__tests__/gradle-installer.test.ts
Normal file
127
__tests__/gradle-installer.test.ts
Normal file
|
@ -0,0 +1,127 @@
|
|||
import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import child_process = require('child_process');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runnerg', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runnerg', 'temp');
|
||||
const gradleDir = path.join(__dirname, 'runnerg', 'gradle');
|
||||
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
import * as installer from '../src/gradle-installer';
|
||||
|
||||
let gradleFilePath = '';
|
||||
let gradleUrl = '';
|
||||
if (process.platform === 'win32') {
|
||||
gradleFilePath = path.join(gradleDir, 'gradle_win.zip');
|
||||
gradleUrl = 'https://services.gradle.org/distributions/gradle-6.0.1-bin.zip';
|
||||
} else if (process.platform === 'darwin') {
|
||||
gradleFilePath = path.join(gradleDir, 'gradle_mac.zip');
|
||||
gradleUrl = 'https://services.gradle.org/distributions/gradle-6.0.1-bin.zip';
|
||||
} else {
|
||||
gradleFilePath = path.join(gradleDir, 'gradle_linux.zip');
|
||||
gradleUrl = 'https://services.gradle.org/distributions/gradle-6.0.1-bin.zip';
|
||||
}
|
||||
|
||||
describe('gradle installer tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
await io.rmRF(gradleDir);
|
||||
if (!fs.existsSync(`${gradleFilePath}.complete`)) {
|
||||
// Download gradle
|
||||
await io.mkdirP(gradleDir);
|
||||
|
||||
console.log('Downloading gradle');
|
||||
child_process.execSync(`curl -L "${gradleUrl}" > "${gradleFilePath}"`);
|
||||
// Write complete file so we know it was successful
|
||||
fs.writeFileSync(`${gradleFilePath}.complete`, 'content');
|
||||
}
|
||||
}, 300000);
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
await io.rmRF(gradleDir);
|
||||
} catch {
|
||||
console.log('Failed to remove test directories');
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
it('Installs version of Gradle from gradleFile if no matching version is installed', async () => {
|
||||
await installer.getGradle('6.0.1', gradleFilePath);
|
||||
const gradleDir = path.join(toolDir, 'gradle', '6.0.1', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${gradleDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(gradleDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Throws if invalid directory to gradle', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await installer.getGradle('1000', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
it('Downloads gradle if no file given', async () => {
|
||||
await installer.getGradle('5.6.3', '');
|
||||
const gradleDir = path.join(toolDir, 'gradle', '5.6.3', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${gradleDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(gradleDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Downloads gradle with 1.x syntax', async () => {
|
||||
await installer.getGradle('4.10', '');
|
||||
const gradleDir = path.join(toolDir, 'gradle', '4.10.3', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${gradleDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(gradleDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Downloads gradle with normal semver syntax', async () => {
|
||||
await installer.getGradle('4.8.x', '');
|
||||
const gradleDir = path.join(toolDir, 'gradle', '4.8.1', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${gradleDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(gradleDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Throws if invalid directory to gradle', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await installer.getGradle('1000', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
it('Uses version of gradle installed in cache', async () => {
|
||||
const gradleDir: string = path.join(toolDir, 'gradle', '250.0.0', 'x64');
|
||||
await io.mkdirP(gradleDir);
|
||||
fs.writeFileSync(`${gradleDir}.complete`, 'hello');
|
||||
// This will throw if it doesn't find it in the cache (because no such version exists)
|
||||
await installer.getGradle('250', 'path shouldnt matter, found in cache');
|
||||
return;
|
||||
});
|
||||
|
||||
it('Doesnt use version of gradle that was only partially installed in cache', async () => {
|
||||
const gradleDir: string = path.join(toolDir, 'gradle', '251.0.0', 'x64');
|
||||
await io.mkdirP(gradleDir);
|
||||
let thrown = false;
|
||||
try {
|
||||
// This will throw if it doesn't find it in the cache (because no such version exists)
|
||||
await installer.getGradle('251', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
return;
|
||||
});
|
||||
});
|
134
__tests__/maven-installer.test.ts
Normal file
134
__tests__/maven-installer.test.ts
Normal file
|
@ -0,0 +1,134 @@
|
|||
import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import child_process = require('child_process');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runnerm', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runnerm', 'temp');
|
||||
const mavenDir = path.join(__dirname, 'runnerm', 'maven');
|
||||
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
import * as installer from '../src/maven-installer';
|
||||
|
||||
let mavenFilePath = '';
|
||||
let mavenUrl = '';
|
||||
if (process.platform === 'win32') {
|
||||
mavenFilePath = path.join(mavenDir, 'maven_win.zip');
|
||||
mavenUrl =
|
||||
'https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip';
|
||||
} else if (process.platform === 'darwin') {
|
||||
mavenFilePath = path.join(mavenDir, 'maven_mac.tar.gz');
|
||||
mavenUrl =
|
||||
'https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz';
|
||||
} else {
|
||||
mavenFilePath = path.join(mavenDir, 'maven_linux.tar.gz');
|
||||
mavenUrl =
|
||||
'https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz';
|
||||
}
|
||||
|
||||
describe('maven installer tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
await io.rmRF(mavenDir);
|
||||
if (!fs.existsSync(`${mavenFilePath}.complete`)) {
|
||||
// Download maven
|
||||
await io.mkdirP(mavenDir);
|
||||
|
||||
console.log('Downloading maven');
|
||||
child_process.execSync(`curl "${mavenUrl}" > "${mavenFilePath}"`);
|
||||
// Write complete file so we know it was successful
|
||||
fs.writeFileSync(`${mavenFilePath}.complete`, 'content');
|
||||
}
|
||||
}, 300000);
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
await io.rmRF(mavenDir);
|
||||
} catch {
|
||||
console.log('Failed to remove test directories');
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
it('Installs version of Maven from maven-file if no matching version is installed', async () => {
|
||||
await installer.getMaven(
|
||||
'3.6.3',
|
||||
mavenFilePath,
|
||||
'https://archive.apache.org/dist/maven/maven-3/'
|
||||
);
|
||||
const mavenDir = path.join(toolDir, 'maven', '3.6.3', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${mavenDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(mavenDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Throws if invalid directory to maven', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await installer.getMaven('1000', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
it('Downloads maven if no file given', async () => {
|
||||
await installer.getMaven('3.6.2', '');
|
||||
const mavenDir = path.join(toolDir, 'maven', '3.6.2', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${mavenDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(mavenDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Downloads maven with 1.x syntax', async () => {
|
||||
await installer.getMaven('3.1', '');
|
||||
const mavenDir = path.join(toolDir, 'maven', '3.1.1', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${mavenDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(mavenDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Downloads maven with normal semver syntax', async () => {
|
||||
await installer.getMaven('3.5.x', '');
|
||||
const mavenDir = path.join(toolDir, 'maven', '3.5.4', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${mavenDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(mavenDir, 'bin'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Throws if invalid directory to maven', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await installer.getMaven('1000', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
it('Uses version of Maven installed in cache', async () => {
|
||||
const mavenDir: string = path.join(toolDir, 'maven', '250.0.0', 'x64');
|
||||
await io.mkdirP(mavenDir);
|
||||
fs.writeFileSync(`${mavenDir}.complete`, 'hello');
|
||||
// This will throw if it doesn't find it in the cache (because no such version exists)
|
||||
await installer.getMaven('250', 'path shouldnt matter, found in cache');
|
||||
return;
|
||||
});
|
||||
|
||||
it('Doesnt use version of Maven that was only partially installed in cache', async () => {
|
||||
const mavenDir: string = path.join(toolDir, 'maven', '251.0.0', 'x64');
|
||||
await io.mkdirP(mavenDir);
|
||||
let thrown = false;
|
||||
try {
|
||||
// This will throw if it doesn't find it in the cache (because no such version exists)
|
||||
await installer.getMaven('251', 'bad path');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
return;
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue