Skip to content

Commit

Permalink
chore: update deps and use isEmptyDir from utils (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Jan 26, 2022
1 parent 983a037 commit 736e11d
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 275 deletions.
40 changes: 5 additions & 35 deletions dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

362 changes: 174 additions & 188 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.6.0",
"@google-github-actions/actions-utils": "^0.1.1"
"@google-github-actions/actions-utils": "^0.1.2"
},
"devDependencies": {
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@types/node": "^17.0.12",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"@vercel/ncc": "^0.33.1",
"chai": "^4.3.4",
"chai": "^4.3.6",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^9.1.4",
"mocha": "^9.2.0",
"prettier": "^2.5.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.5"
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
errorMessage,
exactlyOneOf,
isEmptyDir,
isPinnedToHead,
parseCSV,
parseDuration,
Expand All @@ -25,7 +26,7 @@ import { WorkloadIdentityClient } from './client/workload_identity_client';
import { CredentialsJSONClient } from './client/credentials_json_client';
import { AuthClient } from './client/auth_client';
import { BaseClient } from './base';
import { buildDomainWideDelegationJWT, isEmptyDir } from './utils';
import { buildDomainWideDelegationJWT } from './utils';

const secretsWarning =
`If you are specifying input values via GitHub secrets, ensure the secret ` +
Expand Down
19 changes: 0 additions & 19 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { promises as fs } from 'fs';

/**
* buildDomainWideDelegationJWT constructs an _unsigned_ JWT to be used for a
* DWD exchange. The JWT must be signed and then exchanged with the OAuth
Expand Down Expand Up @@ -37,20 +35,3 @@ export function buildDomainWideDelegationJWT(

return JSON.stringify(body);
}

/**
* isEmptyDir returns true if the given directory does not exist, or exists but
* contains no files. It also returns true if the current user does not have
* permission to read the directory, since it is effectively empty from the
* viewpoint of the caller.
*
* @param dir Path to a directory.
*/
export async function isEmptyDir(dir: string): Promise<boolean> {
try {
const files = await fs.readdir(dir);
return files.length <= 0;
} catch (e) {
return true;
}
}
26 changes: 1 addition & 25 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import 'mocha';
import { expect } from 'chai';

import { tmpdir } from 'os';

import { buildDomainWideDelegationJWT, isEmptyDir } from '../src/utils';
import { buildDomainWideDelegationJWT } from '../src/utils';

describe('Utils', () => {
describe('#buildDomainWideDelegationJWT', () => {
Expand Down Expand Up @@ -56,26 +54,4 @@ describe('Utils', () => {
});
});
});

describe('#isEmptyDir', async () => {
const cases = [
{
name: 'non-existent dir',
dir: '/this/path/definitely/does/not/exist',
exp: true,
},
{
name: 'exists',
dir: tmpdir(),
exp: false,
},
];

cases.forEach((tc) => {
it(tc.name, async () => {
const isEmpty = await isEmptyDir(tc.dir);
expect(isEmpty).to.eq(tc.exp);
});
});
});
});

0 comments on commit 736e11d

Please sign in to comment.