Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error deleting keys with short key id #129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion __tests__/gpg.test.ts
Expand Up @@ -20,6 +20,7 @@ const userInfos = [
name: 'Joe Tester',
email: 'joe@foo.bar',
keyID: '7D851EB72D73BDA0',
primary_key_fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
fingerprints: ['27571A53B86AF0C799B38BA77D851EB72D73BDA0', '5A282E1460C0BC419615D34DD523BD50DD70B0BA'],
keygrips: ['3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627', 'BA83FC8947213477F28ADC019F6564A956456163']
Expand All @@ -41,6 +42,7 @@ const userInfos = [
name: 'Joe Bar',
email: 'joe@bar.foo',
keyID: '6071D218380FDCC8',
primary_key_fingerprint: '87F257B89CE462100BEC0FFE6071D218380FDCC8',
fingerprint: 'C17D11ADF199F12A30A0910F1F80449BE0B08CB8',
fingerprints: ['87F257B89CE462100BEC0FFE6071D218380FDCC8', 'C17D11ADF199F12A30A0910F1F80449BE0B08CB8'],
keygrips: ['F5C3ABFAAB36B427FD98C4EDD0387E08EA1E8092', 'DEE0FC98F441519CA5DE5D79773CB29009695FEB']
Expand Down Expand Up @@ -133,7 +135,7 @@ for (let userInfo of userInfos) {
describe('deleteKey', () => {
it('removes key from GnuPG', async () => {
await gpg.importKey(userInfo.pgp);
await gpg.deleteKey(userInfo.fingerprint);
await gpg.deleteKey(userInfo.primary_key_fingerprint);
});
});
});
Expand Down
16 changes: 5 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/main.ts
Expand Up @@ -33,12 +33,13 @@ async function run(): Promise<void> {
core.info(`CreationTime : ${privateKey.creationTime}`);
});

stateHelper.setFingerprint(privateKey.fingerprint);

let fingerprint = privateKey.fingerprint;
if (inputs.fingerprint) {
fingerprint = inputs.fingerprint;
}
stateHelper.setFingerprint(fingerprint);
stateHelper.setKeyID(privateKey.keyID);

await core.group(`Fingerprint to use`, async () => {
core.info(fingerprint);
});
Expand Down Expand Up @@ -127,12 +128,12 @@ async function run(): Promise<void> {

async function cleanup(): Promise<void> {
if (stateHelper.fingerprint.length <= 0) {
core.debug('Fingerprint is not defined. Skipping cleanup.');
core.debug('Primary key fingerprint is not defined. Skipping cleanup.');
return;
}
try {
core.info('Removing keys');
await gpg.deleteKey(stateHelper.keyId);
core.info(`Removing key ${stateHelper.fingerprint}`);
await gpg.deleteKey(stateHelper.fingerprint);

core.info('Killing GnuPG agent');
await gpg.killAgent();
Expand Down
5 changes: 0 additions & 5 deletions src/state-helper.ts
Expand Up @@ -2,16 +2,11 @@ import * as core from '@actions/core';

export const IsPost = !!process.env['STATE_isPost'];
export const fingerprint = process.env['STATE_fingerprint'] || '';
export const keyId = process.env['STATE_keyId'] || '';

export function setFingerprint(fingerprint: string) {
core.saveState('fingerprint', fingerprint);
}

export function setKeyID(keyID: string) {
core.saveState('keyId', keyID);
}

if (!IsPost) {
core.saveState('isPost', 'true');
}