mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
fixed a problem where key cleanup happened before import
This commit is contained in:
parent
e09c5c7b0c
commit
1a5aa64e84
4 changed files with 43 additions and 30 deletions
1
__tests__/.gpgtmp/private.asc
Normal file
1
__tests__/.gpgtmp/private.asc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
KEY CONTENTS
|
|
@ -22,8 +22,8 @@ import * as auth from '../src/auth';
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
const m2Dir = path.join(__dirname, auth.M2_DIR);
|
const m2Dir = path.join(__dirname, auth.M2_DIR);
|
||||||
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
|
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
|
||||||
const gpgDir = path.join(__dirname, auth.GPG_DIR);
|
const privateKeyDir = path.join(__dirname, auth.PRIVATE_KEY_DIR);
|
||||||
const gpgFile = auth.GPG_FILE;
|
const privateKeyFile = auth.PRIVATE_KEY_FILE;
|
||||||
|
|
||||||
describe('auth tests', () => {
|
describe('auth tests', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -33,7 +33,7 @@ describe('auth tests', () => {
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
try {
|
try {
|
||||||
await io.rmRF(m2Dir);
|
await io.rmRF(m2Dir);
|
||||||
await io.rmRF(gpgDir);
|
await io.rmRF(privateKeyDir);
|
||||||
} catch {
|
} catch {
|
||||||
console.log('Failed to remove test directories');
|
console.log('Failed to remove test directories');
|
||||||
}
|
}
|
||||||
|
@ -182,11 +182,11 @@ describe('auth tests', () => {
|
||||||
|
|
||||||
expect(exec.exec).toHaveBeenCalledWith(
|
expect(exec.exec).toHaveBeenCalledWith(
|
||||||
'gpg',
|
'gpg',
|
||||||
['--import', '--batch', gpgFile],
|
['--import', '--batch', privateKeyFile],
|
||||||
{cwd: gpgDir}
|
{cwd: privateKeyDir}
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.existsSync(gpgDir)).toBe(false);
|
expect(fs.existsSync(privateKeyDir)).toBe(false);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
it('does not import gpg private key when private key is not set', async () => {
|
it('does not import gpg private key when private key is not set', async () => {
|
||||||
|
@ -198,10 +198,10 @@ describe('auth tests', () => {
|
||||||
|
|
||||||
expect(exec.exec).not.toHaveBeenCalledWith(
|
expect(exec.exec).not.toHaveBeenCalledWith(
|
||||||
'gpg',
|
'gpg',
|
||||||
['--import', '--batch', gpgFile],
|
['--import', '--batch', privateKeyFile],
|
||||||
{cwd: gpgDir}
|
{cwd: privateKeyDir}
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.existsSync(gpgDir)).toBe(false);
|
expect(fs.existsSync(privateKeyDir)).toBe(false);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
|
|
25
dist/index.js
generated
vendored
25
dist/index.js
generated
vendored
|
@ -2882,8 +2882,8 @@ const io = __importStar(__webpack_require__(1));
|
||||||
const exec = __importStar(__webpack_require__(986));
|
const exec = __importStar(__webpack_require__(986));
|
||||||
exports.M2_DIR = '.m2';
|
exports.M2_DIR = '.m2';
|
||||||
exports.SETTINGS_FILE = 'settings.xml';
|
exports.SETTINGS_FILE = 'settings.xml';
|
||||||
exports.GPG_DIR = '.gpgtmp';
|
exports.PRIVATE_KEY_DIR = '.keys';
|
||||||
exports.GPG_FILE = 'private.asc';
|
exports.PRIVATE_KEY_FILE = 'private-key.asc';
|
||||||
exports.DEFAULT_ID = 'github';
|
exports.DEFAULT_ID = 'github';
|
||||||
exports.DEFAULT_USERNAME = 'GITHUB_ACTOR';
|
exports.DEFAULT_USERNAME = 'GITHUB_ACTOR';
|
||||||
exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN';
|
exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN';
|
||||||
|
@ -2900,13 +2900,12 @@ function configAuthentication(id = exports.DEFAULT_ID, username = exports.DEFAUL
|
||||||
yield write(settingsDirectory, exports.SETTINGS_FILE, generate(id, username, password, gpgPassphrase));
|
yield write(settingsDirectory, exports.SETTINGS_FILE, generate(id, username, password, gpgPassphrase));
|
||||||
if (gpgPrivateKey !== exports.DEFAULT_GPG_PRIVATE_KEY) {
|
if (gpgPrivateKey !== exports.DEFAULT_GPG_PRIVATE_KEY) {
|
||||||
console.log('importing gpg key');
|
console.log('importing gpg key');
|
||||||
const gpgDirectory = path.join(os.homedir(), exports.GPG_DIR);
|
const privateKeyDirectory = path.join(os.homedir(), exports.PRIVATE_KEY_DIR);
|
||||||
yield io.mkdirP(gpgDirectory);
|
yield io.mkdirP(privateKeyDirectory);
|
||||||
core.debug(`created directory ${gpgDirectory}`);
|
core.debug(`created directory ${privateKeyDirectory}`);
|
||||||
yield write(gpgDirectory, exports.GPG_FILE, gpgPrivateKey);
|
yield write(privateKeyDirectory, exports.PRIVATE_KEY_FILE, gpgPrivateKey);
|
||||||
yield importGpgKey(gpgDirectory, exports.GPG_FILE);
|
yield importGpgKey(privateKeyDirectory, exports.PRIVATE_KEY_FILE);
|
||||||
yield io.rmRF(gpgDirectory);
|
yield remove(privateKeyDirectory);
|
||||||
core.debug(`removed directory ${gpgDirectory}`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2959,9 +2958,15 @@ function write(directory, file, contents) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function remove(path) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
console.log(`removing ${path}`);
|
||||||
|
return io.rmRF(path);
|
||||||
|
});
|
||||||
|
}
|
||||||
function importGpgKey(directory, file) {
|
function importGpgKey(directory, file) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
exec.exec('gpg', ['--import', '--batch', file], { cwd: directory });
|
return exec.exec('gpg', ['--import', '--batch', file], { cwd: directory });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
src/auth.ts
29
src/auth.ts
|
@ -7,8 +7,8 @@ import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export const M2_DIR = '.m2';
|
export const M2_DIR = '.m2';
|
||||||
export const SETTINGS_FILE = 'settings.xml';
|
export const SETTINGS_FILE = 'settings.xml';
|
||||||
export const GPG_DIR = '.gpgtmp';
|
export const PRIVATE_KEY_DIR = '.keys';
|
||||||
export const GPG_FILE = 'private.asc';
|
export const PRIVATE_KEY_FILE = 'private-key.asc';
|
||||||
|
|
||||||
export const DEFAULT_ID = 'github';
|
export const DEFAULT_ID = 'github';
|
||||||
export const DEFAULT_USERNAME = 'GITHUB_ACTOR';
|
export const DEFAULT_USERNAME = 'GITHUB_ACTOR';
|
||||||
|
@ -46,13 +46,15 @@ export async function configAuthentication(
|
||||||
|
|
||||||
if (gpgPrivateKey !== DEFAULT_GPG_PRIVATE_KEY) {
|
if (gpgPrivateKey !== DEFAULT_GPG_PRIVATE_KEY) {
|
||||||
console.log('importing gpg key');
|
console.log('importing gpg key');
|
||||||
const gpgDirectory: string = path.join(os.homedir(), GPG_DIR);
|
const privateKeyDirectory: string = path.join(
|
||||||
await io.mkdirP(gpgDirectory);
|
os.homedir(),
|
||||||
core.debug(`created directory ${gpgDirectory}`);
|
PRIVATE_KEY_DIR
|
||||||
await write(gpgDirectory, GPG_FILE, gpgPrivateKey);
|
);
|
||||||
await importGpgKey(gpgDirectory, GPG_FILE);
|
await io.mkdirP(privateKeyDirectory);
|
||||||
await io.rmRF(gpgDirectory);
|
core.debug(`created directory ${privateKeyDirectory}`);
|
||||||
core.debug(`removed directory ${gpgDirectory}`);
|
await write(privateKeyDirectory, PRIVATE_KEY_FILE, gpgPrivateKey);
|
||||||
|
await importGpgKey(privateKeyDirectory, PRIVATE_KEY_FILE);
|
||||||
|
await remove(privateKeyDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +111,11 @@ async function write(directory: string, file: string, contents: string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function importGpgKey(directory: string, file: string) {
|
async function remove(path: string) {
|
||||||
exec.exec('gpg', ['--import', '--batch', file], {cwd: directory});
|
console.log(`removing ${path}`);
|
||||||
|
return io.rmRF(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function importGpgKey(directory: string, file: string) {
|
||||||
|
return exec.exec('gpg', ['--import', '--batch', file], {cwd: directory});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue