@@ -11,16 +11,56 @@ import ComponentDetection from './componentDetection';
1111import { PlatformProviderFactory , Platform } from './src/providers' ;
1212
1313async 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
115187run ( ) ;
0 commit comments