Skip to content

Commit 45315da

Browse files
committed
chore: changing pipeline
1 parent 091309b commit 45315da

File tree

3 files changed

+150
-68
lines changed

3 files changed

+150
-68
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
uses: ./
1313
with:
1414
base_url: 'https://federation.dev.meshcloud.io'
15-
bb_run_uuid: 'example-uuid'
15+
bb_run_uuid: 'b1c07bb0-10eb-4bbe-8eee-cf00664ca1ae'
1616
steps: |
1717
[
1818
{ "id": "terraform-validate", "displayName": "terraform validate" },

dist/index.js

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,82 @@ async function run() {
4646
const stepsInput = core.getInput('steps');
4747
const clientId = core.getInput('client_id');
4848
const keySecret = core.getInput('key_secret');
49-
// Parse the steps input
50-
const steps = JSON.parse(`[${stepsInput}]`);
49+
core.debug(`Base URL: ${baseUrl}`);
50+
core.debug(`BB Run UUID: ${bbRunUuid}`);
51+
core.debug(`Steps Input: ${stepsInput}`);
52+
core.debug(`Client ID: ${clientId}`);
53+
core.debug(`Key Secret: ${keySecret}`);
54+
// Decode and parse the steps input
55+
const decodedStepsInput = decodeURIComponent(stepsInput);
56+
const steps = JSON.parse(decodedStepsInput);
57+
core.debug(`Parsed Steps: ${JSON.stringify(steps)}`);
5158
// Authenticate and get the token
52-
const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
53-
headers: {
54-
'Content-Type': 'application/x-www-form-urlencoded'
59+
try {
60+
const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
61+
headers: {
62+
'Content-Type': 'application/x-www-form-urlencoded'
63+
},
64+
maxRedirects: 5 // Follow redirects
65+
});
66+
const token = authResponse.data.access_token;
67+
core.debug(`Token: ${token}`);
68+
// Write token to a temporary file
69+
const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
70+
const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
71+
fs.writeFileSync(tokenFilePath, JSON.stringify({ token }));
72+
core.debug(`Token file path: ${tokenFilePath}`);
73+
// Indicate successful login
74+
core.info('Login was successful.');
75+
// Register the source
76+
try {
77+
const response = await axios_1.default.post(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`, {
78+
source: {
79+
id: 'github',
80+
externalRunId: github.context.runId,
81+
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
82+
},
83+
steps: steps
84+
}, {
85+
headers: {
86+
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
87+
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
88+
'Authorization': `Bearer ${token}`
89+
}
90+
});
91+
core.setOutput('response', response.data);
92+
core.setOutput('token_file', tokenFilePath);
5593
}
56-
});
57-
const token = authResponse.data.access_token;
58-
// Write token to a temporary file
59-
const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
60-
const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
61-
fs.writeFileSync(tokenFilePath, JSON.stringify({ token }));
62-
core.info('meshStack auth successful.');
63-
// Register the source
64-
const response = await axios_1.default.post(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`, {
65-
source: {
66-
id: 'github',
67-
externalRunId: github.context.runId,
68-
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
69-
},
70-
steps: steps
71-
}, {
72-
headers: {
73-
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
74-
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
75-
'Authorization': `Bearer ${token}`
94+
catch (registerError) {
95+
if (axios_1.default.isAxiosError(registerError)) {
96+
if (registerError.response) {
97+
core.error(`Register source error response: ${registerError.response.data}`);
98+
core.error(`Status code: ${registerError.response.status}`);
99+
}
100+
else {
101+
core.error(`Register source error message: ${registerError.message}`);
102+
}
103+
}
104+
else {
105+
core.error(`Unexpected error: ${registerError}`);
106+
}
107+
throw registerError;
76108
}
77-
});
78-
core.setOutput('response', response.data);
79-
core.setOutput('token_file', tokenFilePath);
109+
}
110+
catch (authError) {
111+
if (axios_1.default.isAxiosError(authError)) {
112+
if (authError.response) {
113+
core.error(`Authentication error response: ${authError.response.data}`);
114+
core.error(`Status code: ${authError.response.status}`);
115+
}
116+
else {
117+
core.error(`Authentication error message: ${authError.message}`);
118+
}
119+
}
120+
else {
121+
core.error(`Unexpected error: ${authError}`);
122+
}
123+
throw authError;
124+
}
80125
}
81126
catch (error) {
82127
if (error instanceof Error) {
@@ -87,7 +132,6 @@ async function run() {
87132
}
88133
}
89134
}
90-
run();
91135

92136

93137
/***/ }),

src/index.ts

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,91 @@ async function run() {
1313
const clientId = core.getInput('client_id');
1414
const keySecret = core.getInput('key_secret');
1515

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)}`);
1826

1927
// 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
2637
}
27-
}
28-
);
38+
);
2939

30-
const token = authResponse.data.access_token;
40+
const token = authResponse.data.access_token;
41+
core.debug(`Token: ${token}`);
3142

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}`);
3748

49+
// Indicate successful login
50+
core.info('Login was successful.');
3851

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}`);
5585
}
86+
throw registerError;
5687
}
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+
}
61101
} catch (error) {
62102
if (error instanceof Error) {
63103
core.setFailed(error.message);
@@ -67,5 +107,3 @@ async function run() {
67107
}
68108
}
69109

70-
run();
71-

0 commit comments

Comments
 (0)