@@ -13,51 +13,91 @@ async function run() {
13
13
const clientId = core . getInput ( 'client_id' ) ;
14
14
const keySecret = core . getInput ( 'key_secret' ) ;
15
15
16
- // Parse the steps input
17
- const steps = JSON . parse ( `[${ stepsInput } ]` ) ;
16
+ core . debug ( `Base URL: ${ baseUrl } ` ) ;
17
+ core . debug ( `BB Run UUID: ${ bbRunUuid } ` ) ;
18
+ core . debug ( `Steps Input: ${ stepsInput } ` ) ;
19
+ core . debug ( `Client ID: ${ clientId } ` ) ;
20
+ core . debug ( `Key Secret: ${ keySecret } ` ) ;
21
+
22
+ // Decode and parse the steps input
23
+ const decodedStepsInput = decodeURIComponent ( stepsInput ) ;
24
+ const steps = JSON . parse ( decodedStepsInput ) ;
25
+ core . debug ( `Parsed Steps: ${ JSON . stringify ( steps ) } ` ) ;
18
26
19
27
// Authenticate and get the token
20
- const authResponse = await axios . post (
21
- `${ baseUrl } /api/login` ,
22
- `grant_type=client_credentials&client_id=${ clientId } &client_secret=${ keySecret } ` ,
23
- {
24
- headers : {
25
- 'Content-Type' : 'application/x-www-form-urlencoded'
28
+ try {
29
+ const authResponse = await axios . post (
30
+ `${ baseUrl } /api/login` ,
31
+ `grant_type=client_credentials&client_id=${ clientId } &client_secret=${ keySecret } ` ,
32
+ {
33
+ headers : {
34
+ 'Content-Type' : 'application/x-www-form-urlencoded'
35
+ } ,
36
+ maxRedirects : 5 // Follow redirects
26
37
}
27
- }
28
- ) ;
38
+ ) ;
29
39
30
- const token = authResponse . data . access_token ;
40
+ const token = authResponse . data . access_token ;
41
+ core . debug ( `Token: ${ token } ` ) ;
31
42
32
- // Write token to a temporary file
33
- const tempDir = process . env . RUNNER_TEMP || os . tmpdir ( ) ;
34
- const tokenFilePath = path . join ( tempDir , 'meshstack_token.json' ) ;
35
- fs . writeFileSync ( tokenFilePath , JSON . stringify ( { token } ) ) ;
36
- core . info ( 'meshStack auth successful.' ) ;
43
+ // Write token to a temporary file
44
+ const tempDir = process . env . RUNNER_TEMP || os . tmpdir ( ) ;
45
+ const tokenFilePath = path . join ( tempDir , 'meshstack_token.json' ) ;
46
+ fs . writeFileSync ( tokenFilePath , JSON . stringify ( { token } ) ) ;
47
+ core . debug ( `Token file path: ${ tokenFilePath } ` ) ;
37
48
49
+ // Indicate successful login
50
+ core . info ( 'Login was successful.' ) ;
38
51
39
- // Register the source
40
- const response = await axios . post (
41
- `${ baseUrl } /api/meshobjects/meshbuildingblockruns/${ bbRunUuid } /status/source` ,
42
- {
43
- source : {
44
- id : 'github' ,
45
- externalRunId : github . context . runId ,
46
- externalRunUrl : `https://github.com/${ github . context . repo . owner } /${ github . context . repo . repo } /actions/runs/${ github . context . runId } `
47
- } ,
48
- steps : steps
49
- } ,
50
- {
51
- headers : {
52
- 'Content-Type' : 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json' ,
53
- 'Accept' : 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json' ,
54
- 'Authorization' : `Bearer ${ token } `
52
+ // Register the source
53
+ try {
54
+ const response = await axios . post (
55
+ `${ baseUrl } /api/meshobjects/meshbuildingblockruns/${ bbRunUuid } /status/source` ,
56
+ {
57
+ source : {
58
+ id : 'github' ,
59
+ externalRunId : github . context . runId ,
60
+ externalRunUrl : `https://github.com/${ github . context . repo . owner } /${ github . context . repo . repo } /actions/runs/${ github . context . runId } `
61
+ } ,
62
+ steps : steps
63
+ } ,
64
+ {
65
+ headers : {
66
+ 'Content-Type' : 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json' ,
67
+ 'Accept' : 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json' ,
68
+ 'Authorization' : `Bearer ${ token } `
69
+ }
70
+ }
71
+ ) ;
72
+
73
+ core . setOutput ( 'response' , response . data ) ;
74
+ core . setOutput ( 'token_file' , tokenFilePath ) ;
75
+ } catch ( registerError ) {
76
+ if ( axios . isAxiosError ( registerError ) ) {
77
+ if ( registerError . response ) {
78
+ core . error ( `Register source error response: ${ registerError . response . data } ` ) ;
79
+ core . error ( `Status code: ${ registerError . response . status } ` ) ;
80
+ } else {
81
+ core . error ( `Register source error message: ${ registerError . message } ` ) ;
82
+ }
83
+ } else {
84
+ core . error ( `Unexpected error: ${ registerError } ` ) ;
55
85
}
86
+ throw registerError ;
56
87
}
57
- ) ;
58
-
59
- core . setOutput ( 'response' , response . data ) ;
60
- core . setOutput ( 'token_file' , tokenFilePath ) ;
88
+ } catch ( authError ) {
89
+ if ( axios . isAxiosError ( authError ) ) {
90
+ if ( authError . response ) {
91
+ core . error ( `Authentication error response: ${ authError . response . data } ` ) ;
92
+ core . error ( `Status code: ${ authError . response . status } ` ) ;
93
+ } else {
94
+ core . error ( `Authentication error message: ${ authError . message } ` ) ;
95
+ }
96
+ } else {
97
+ core . error ( `Unexpected error: ${ authError } ` ) ;
98
+ }
99
+ throw authError ;
100
+ }
61
101
} catch ( error ) {
62
102
if ( error instanceof Error ) {
63
103
core . setFailed ( error . message ) ;
@@ -67,5 +107,3 @@ async function run() {
67
107
}
68
108
}
69
109
70
- run ( ) ;
71
-
0 commit comments