Skip to content

Commit 2c2e953

Browse files
committed
GH only - add logging
1 parent 84e50e9 commit 2c2e953

File tree

5 files changed

+229
-89
lines changed

5 files changed

+229
-89
lines changed

dist/index.js

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

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default [
1818
'output.json',
1919
'*.d.ts',
2020
'node_modules/',
21+
'component-detection-github-submission-task/'
2122
],
2223
},
2324
];

index.ts

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,56 @@ import ComponentDetection from './componentDetection';
1111
import { PlatformProviderFactory, Platform } from './src/providers';
1212

1313
async function run() {
14-
const platform = PlatformProviderFactory.create(Platform.GitHubActions);
15-
16-
let manifests = await ComponentDetection.scanAndGetManifests(
14+
try {
15+
console.log('Creating platform provider...');
16+
const platform = PlatformProviderFactory.create();
17+
console.log(`Platform created: ${typeof platform}`);
18+
19+
if (!platform) {
20+
throw new Error('Failed to create platform provider');
21+
}
22+
23+
if (!platform.context) {
24+
throw new Error('Platform provider created but context is undefined');
25+
}
26+
27+
if (!platform.input) {
28+
throw new Error('Platform provider created but input is undefined');
29+
}
30+
31+
if (!platform.logger) {
32+
throw new Error('Platform provider created but logger is undefined');
33+
}
34+
35+
console.log(`Platform has context: ${!!platform.context}`);
36+
console.log(`Platform has input: ${!!platform.input}`);
37+
console.log(`Platform has logger: ${!!platform.logger}`);
38+
39+
// Test the context methods
40+
try {
41+
const repo = platform.context.getRepository();
42+
console.log(`Repository: ${JSON.stringify(repo)}`);
43+
} catch (error) {
44+
console.error(`Failed to get repository from context: ${error}`);
45+
throw new Error(`Invalid platform context - cannot get repository: ${error}`);
46+
}
47+
48+
let manifests = await ComponentDetection.scanAndGetManifests(
1749
platform.input.getInput("filePath"),
1850
platform
19-
);
20-
const correlatorInput =
21-
platform.input.getInput("correlator")?.trim() || platform.context.getJobId();
51+
);
2252

23-
// Get detector configuration inputs
53+
let correlatorInput: string;
54+
try {
55+
correlatorInput = platform.input.getInput("correlator")?.trim() || platform.context.getJobId();
56+
console.log(`Correlator input: ${correlatorInput}`);
57+
if (!correlatorInput) {
58+
throw new Error('Could not obtain correlator input or job ID');
59+
}
60+
} catch (error) {
61+
console.error(`Failed to get correlator input: ${error}`);
62+
throw new Error(`Cannot proceed without correlator input: ${error}`);
63+
} // Get detector configuration inputs
2464
const detectorName = platform.input.getInput("detector-name")?.trim();
2565
const detectorVersion = platform.input.getInput("detector-version")?.trim();
2666
const detectorUrl = platform.input.getInput("detector-url")?.trim();
@@ -54,11 +94,39 @@ async function run() {
5494

5595
if (process.env.GITHUB_ACTIONS === 'true') {
5696
// We're in GitHub Actions, use the actual github context
57-
const { default: github } = await import('@actions/github');
58-
snapshot = new Snapshot(detector, github.context, {
59-
correlator: correlatorInput,
60-
id: platform.context.getRunId().toString(),
61-
});
97+
try {
98+
platform.logger.debug('Attempting to import @actions/github');
99+
const githubModule = await import('@actions/github');
100+
platform.logger.debug(`GitHub module imported: ${typeof githubModule}`);
101+
platform.logger.debug(`GitHub module keys: ${Object.keys(githubModule)}`);
102+
103+
const { default: github } = githubModule;
104+
platform.logger.debug(`GitHub default export: ${typeof github}`);
105+
106+
if (!github) {
107+
throw new Error('GitHub module default export is undefined');
108+
}
109+
110+
if (!github.context) {
111+
throw new Error('GitHub context is undefined');
112+
}
113+
114+
platform.logger.debug(`GitHub context keys: ${Object.keys(github.context)}`);
115+
platform.logger.debug(`GitHub context repo: ${JSON.stringify(github.context.repo)}`);
116+
platform.logger.debug(`GitHub context job: ${github.context.job}`);
117+
platform.logger.debug(`GitHub context runId: ${github.context.runId}`);
118+
platform.logger.debug(`GitHub context sha: ${github.context.sha}`);
119+
platform.logger.debug(`GitHub context ref: ${github.context.ref}`);
120+
121+
snapshot = new Snapshot(detector, github.context, {
122+
correlator: correlatorInput,
123+
id: platform.context.getRunId().toString(),
124+
});
125+
} catch (error) {
126+
platform.logger.error(`Failed to use GitHub Actions context: ${error}`);
127+
platform.logger.setFailed(`Cannot proceed without valid GitHub Actions context: ${error}`);
128+
return;
129+
}
62130
} else {
63131
// For ADO, we need to construct a minimal context object
64132
// The dependency-submission-toolkit uses GitHub API, so we need GitHub org/repo
@@ -110,6 +178,10 @@ async function run() {
110178
}
111179

112180
submitSnapshot(snapshot);
181+
} catch (error) {
182+
console.error('Error in run function:', error);
183+
throw error;
184+
}
113185
}
114186

115187
run();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"ado:build": "ncc build ado-index.ts -o ado-dist --license licenses.txt --target es2020 && node -e \"require('fs').copyFileSync('ado-dist/index.js', 'component-detection-github-submission-task/index.mjs');",
1313
"ado:debugbuild": "ncc build ado-index.ts -o ado-dist --source-map --license licenses.txt --target es2020 && node -e \"require('fs').copyFileSync('ado-dist/index.js', 'component-detection-github-submission-task/index.mjs'); require('fs').copyFileSync('ado-dist/sourcemap-register.cjs', 'component-detection-github-submission-task/sourcemap-register.cjs')\"",
1414
"ado:package": "tfx extension create --manifest-globs vss-extension.json",
15-
"ado:all": "npm run ado:build && npm run ado:package"
15+
"ado:all": "npm run lint && npm run ado:build && npm run test && npm run ado:package",
16+
"everything": "npm run all && npm run ado:all"
1617
},
1718
"repository": {
1819
"type": "git",

0 commit comments

Comments
 (0)