Skip to content

Commit 8ab6675

Browse files
authored
chore: add more debug logging (#264)
1 parent 37557f0 commit 8ab6675

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

dist/index.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export interface ClientUploadOptions {
111111
* FOnUploadObject is the function interface for the upload callback signature.
112112
*/
113113
interface FOnUploadObject {
114-
(source: string, destination: string, opts?: Record<string, unknown>): void;
114+
(source: string, destination: string, opts: Record<string, unknown>): void;
115115
}
116116

117117
/**

src/main.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as path from 'path';
2828

2929
import { Client } from './client';
3030
import { parseHeadersInput } from './headers';
31-
import { absoluteRootAndComputedGlob, expandGlob } from './util';
31+
import { absoluteRootAndComputedGlob, deepClone, expandGlob } from './util';
3232

3333
const NO_FILES_WARNING =
3434
`There are no files to upload! Make sure the workflow uses the "checkout"` +
@@ -76,12 +76,12 @@ export async function run(): Promise<void> {
7676

7777
// Compute the absolute root and compute the glob.
7878
const [absoluteRoot, computedGlob] = await absoluteRootAndComputedGlob(root, glob);
79-
core.debug(`computed absoluteRoot from "${root}" to "${absoluteRoot}"`);
80-
core.debug(`computed computedGlob from "${glob}" to "${computedGlob}"`);
79+
core.debug(`Computed absoluteRoot from "${root}" to "${absoluteRoot}"`);
80+
core.debug(`Computed computedGlob from "${glob}" to "${computedGlob}"`);
8181

8282
// Build complete file list.
8383
const files = await expandGlob(absoluteRoot, computedGlob);
84-
core.debug(`found ${files.length} files: ${JSON.stringify(files)}`);
84+
core.debug(`Found ${files.length} files: ${JSON.stringify(files)}`);
8585

8686
// Process ignores:
8787
//
@@ -129,6 +129,7 @@ export async function run(): Promise<void> {
129129
}
130130

131131
// Create the client and upload files.
132+
core.startGroup('Upload files');
132133
const client = new Client({
133134
credentials: credentials,
134135
projectID: projectID,
@@ -144,10 +145,19 @@ export async function run(): Promise<void> {
144145
resumable: resumable,
145146
predefinedAcl: predefinedAcl,
146147

147-
onUploadObject: (source: string, destination: string) => {
148+
onUploadObject: (source: string, destination: string, opts: Record<string, unknown>) => {
148149
core.info(`Uploading ${source} to gs://${destination}`);
150+
151+
if (core.isDebug()) {
152+
const data = deepClone(opts);
153+
data['ts'] = Date.now();
154+
data['source'] = source;
155+
data['destination'] = destination;
156+
core.debug(`Uploading: ${JSON.stringify(data)}`);
157+
}
149158
},
150159
});
160+
core.endGroup();
151161

152162
core.setOutput('uploaded', uploadResponses.join(','));
153163
} catch (err) {

tests/main.int.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ describe('main (integration)', () => {
6161
/** do nothing */
6262
};
6363
sinon.stub(core, 'debug').callsFake(doNothing);
64+
sinon.stub(core, 'endGroup').callsFake(doNothing);
6465
sinon.stub(core, 'info').callsFake(doNothing);
65-
sinon.stub(core, 'warning').callsFake(doNothing);
6666
sinon.stub(core, 'setOutput').callsFake(doNothing);
67+
sinon.stub(core, 'startGroup').callsFake(doNothing);
68+
sinon.stub(core, 'warning').callsFake(doNothing);
6769
});
6870

6971
afterEach(async function () {

tests/main.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ describe('#run', () => {
4949
/** do nothing */
5050
};
5151
sinon.stub(core, 'debug').callsFake(doNothing);
52+
sinon.stub(core, 'endGroup').callsFake(doNothing);
5253
sinon.stub(core, 'info').callsFake(doNothing);
53-
sinon.stub(core, 'warning').callsFake(doNothing);
5454
sinon.stub(core, 'setOutput').callsFake(doNothing);
55+
sinon.stub(core, 'startGroup').callsFake(doNothing);
56+
sinon.stub(core, 'warning').callsFake(doNothing);
5557
});
5658

5759
afterEach(async function () {

0 commit comments

Comments
 (0)