bug: only cleanup credentials if credentials were created (#96)

This commit is contained in:
Seth Vargo 2021-12-23 11:39:54 -05:00 committed by GitHub
parent 8c15757ad6
commit 443ae925ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View File

@ -193,8 +193,8 @@ regardless of the authentication mechanism.
delegates.
- `cleanup_credentials`: (Optional) If true, the action will remove any
generated credentials from the filesystem upon completion. The default is
true.
created credentials from the filesystem upon completion. This only applies
if "create_credentials_file" is true. The default is true.
## Outputs

View File

@ -73,8 +73,9 @@ inputs:
required: false
cleanup_credentials:
description: |-
If true, the action will remove any generated credentials from the
filesystem upon completion.
If true, the action will remove any created credentials from the
filesystem upon completion. This only applies if "create_credentials_file"
is true.
default: true
required: false

11
dist/post/index.js vendored
View File

@ -1587,8 +1587,14 @@ const actions_utils_1 = __nccwpck_require__(308);
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const createCredentials = (0, core_1.getBooleanInput)('create_credentials_file');
if (!createCredentials) {
(0, core_1.info)(`Skipping credential cleanup - "create_credentials_file" is false.`);
return;
}
const cleanupCredentials = (0, core_1.getBooleanInput)('cleanup_credentials');
if (!cleanupCredentials) {
(0, core_1.info)(`Skipping credential cleanup - "cleanup_credentials" is false.`);
return;
}
// Look up the credentials path, if one exists. Note that we only check the
@ -1597,15 +1603,16 @@ function run() {
// another environment variable manually.
const credentialsPath = process.env['GOOGLE_GHA_CREDS_PATH'];
if (!credentialsPath) {
(0, core_1.info)(`Skipping credential cleanup - $GOOGLE_GHA_CREDS_PATH is not set.`);
return;
}
// Remove the file.
const removed = yield (0, actions_utils_1.removeFile)(credentialsPath);
if (removed) {
(0, core_1.info)(`Removed exported credentials at ${credentialsPath}`);
(0, core_1.info)(`Removed exported credentials at "${credentialsPath}".`);
}
else {
(0, core_1.info)('No exported credentials found');
(0, core_1.info)(`No exported credentials were found at "${credentialsPath}".`);
}
}
catch (err) {

View File

@ -8,8 +8,15 @@ import { errorMessage, removeFile } from '@google-github-actions/actions-utils';
*/
export async function run(): Promise<void> {
try {
const cleanupCredentials: boolean = getBooleanInput('cleanup_credentials');
const createCredentials = getBooleanInput('create_credentials_file');
if (!createCredentials) {
logInfo(`Skipping credential cleanup - "create_credentials_file" is false.`);
return;
}
const cleanupCredentials = getBooleanInput('cleanup_credentials');
if (!cleanupCredentials) {
logInfo(`Skipping credential cleanup - "cleanup_credentials" is false.`);
return;
}
@ -19,15 +26,16 @@ export async function run(): Promise<void> {
// another environment variable manually.
const credentialsPath = process.env['GOOGLE_GHA_CREDS_PATH'];
if (!credentialsPath) {
logInfo(`Skipping credential cleanup - $GOOGLE_GHA_CREDS_PATH is not set.`);
return;
}
// Remove the file.
const removed = await removeFile(credentialsPath);
if (removed) {
logInfo(`Removed exported credentials at ${credentialsPath}`);
logInfo(`Removed exported credentials at "${credentialsPath}".`);
} else {
logInfo('No exported credentials found');
logInfo(`No exported credentials were found at "${credentialsPath}".`);
}
} catch (err) {
const msg = errorMessage(err);