mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 18:36:46 +00:00
Add overwrite-settings
to disable overwriting settings.xml
Closes #79 Refs joschi/setup-jdk#11
This commit is contained in:
parent
d920b7da5f
commit
41b740659c
6 changed files with 60 additions and 13 deletions
19
src/auth.ts
19
src/auth.ts
|
@ -14,7 +14,8 @@ export const DEFAULT_PASSWORD = 'GITHUB_TOKEN';
|
|||
export async function configAuthentication(
|
||||
id = DEFAULT_ID,
|
||||
username = DEFAULT_USERNAME,
|
||||
password = DEFAULT_PASSWORD
|
||||
password = DEFAULT_PASSWORD,
|
||||
overwriteSettings = true
|
||||
) {
|
||||
console.log(
|
||||
`creating ${SETTINGS_FILE} with server-id: ${id};`,
|
||||
|
@ -28,7 +29,7 @@ export async function configAuthentication(
|
|||
);
|
||||
await io.mkdirP(directory);
|
||||
core.debug(`created directory ${directory}`);
|
||||
await write(directory, generate(id, username, password));
|
||||
await write(directory, generate(id, username, password), overwriteSettings);
|
||||
}
|
||||
|
||||
function escapeXML(value: string) {
|
||||
|
@ -59,12 +60,20 @@ export function generate(
|
|||
`;
|
||||
}
|
||||
|
||||
async function write(directory: string, settings: string) {
|
||||
async function write(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
const location = path.join(directory, SETTINGS_FILE);
|
||||
if (fs.existsSync(location)) {
|
||||
const exists = fs.existsSync(location);
|
||||
if (exists && overwriteSettings) {
|
||||
console.warn(`overwriting existing file ${location}`);
|
||||
} else {
|
||||
} else if (!exists) {
|
||||
console.log(`writing ${location}`);
|
||||
} else {
|
||||
console.log(`not overwriting existing file ${location}`);
|
||||
return;
|
||||
}
|
||||
|
||||
return fs.writeFileSync(location, settings, {
|
||||
|
|
|
@ -23,8 +23,15 @@ async function run() {
|
|||
core.getInput('server-username', {required: false}) || undefined;
|
||||
const password =
|
||||
core.getInput('server-password', {required: false}) || undefined;
|
||||
const overwriteSettings =
|
||||
core.getInput('overwrite-settings', {required: false}) || 'true';
|
||||
|
||||
await auth.configAuthentication(id, username, password);
|
||||
await auth.configAuthentication(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
overwriteSettings === 'true'
|
||||
);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue