Skip to content

Commit 183e0b2

Browse files
Merge pull request #2 from meshcloud/feature/output-support
feature/output support
2 parents ba26c47 + 8f0b18c commit 183e0b2

File tree

7 files changed

+124
-25
lines changed

7 files changed

+124
-25
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ Besides a status, meshStack can also show custom user messages consuming the ser
3939

4040
### inputs:
4141
- `step_id`: (required) The ID of the step
42-
- `status`: (required) The status of the step (SUCCEEDED or FAILED)
42+
- `step_status`: (required) The status of the step (SUCCEEDED or FAILED)
4343
- `user_message`: (optional) The user message for a failed step
4444
- `system_message`: (optional) The system message for a failed step
45-
- `is_final`: (optional) Indicates if this is the final status report (default: 'false')
46-
- `summary`: (optional) The summary message for the final status report
45+
- `outputs_json`: (optional) A JSON object with outputs of the step. All step outputs in a run will be merged by
46+
- `run_status`: (optional) Indicates if this is the final status report (default: 'false')
47+
meshStack to produce the run outputs. See the [API documentation](https://docs.meshcloud.io/api/index.html#_update_sources_and_steps) for more details on how to use this field.
4748

4849
## Example Usage
4950

@@ -74,3 +75,5 @@ Besides a status, meshStack can also show custom user messages consuming the ser
7475
user_message: ${{ steps.terraform-validate.outcome == 'success' && 'Successful plan Terraform configuration.' || 'Failed to plan Terraform configuration.' }}
7576
system_message: ${{ steps.terraform-validate.outcome == 'success' && 'Successful plan Terraform configuration.' || 'Failed to plan Terraform configuration.' }}
7677
```
78+
79+

action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ inputs:
44
step_id:
55
description: 'The ID of the step'
66
required: false
7-
status:
8-
description: 'The status of the step (SUCCEEDED or FAILED)'
7+
step_status:
8+
description: 'The status of the step (IN_PROGRESS, SUCCEEDED or FAILED)'
99
required: false
1010
user_message:
1111
description: 'The user message for a failed step'
1212
required: false
1313
system_message:
1414
description: 'The system message for a failed step'
1515
required: false
16-
final_status:
17-
description: 'The final status is the end-state of the run, combining all step outcomes into one status result based on your logic.'
16+
run_status:
17+
description: 'The final status of the run. Sending this to a terminate status like SUCCEEDED or FAILED signals to meshStack that the run is complete. Send this only once.'
1818
required: false
19-
summary:
20-
description: 'The summary message for the final status report'
19+
outputs_json:
20+
description: 'A json objects with outputs of the step. All outputs in a run will be merged by meshStack.'
2121
required: false
22+
default: '{}'
2223
runs:
2324
using: 'node20'
2425
main: 'dist/index.js'
25-

dist/index.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28013,16 +28013,38 @@ const axios_1 = __importDefault(__nccwpck_require__(8757));
2801328013
const fs = __importStar(__nccwpck_require__(7147));
2801428014
const path = __importStar(__nccwpck_require__(1017));
2801528015
const os = __importStar(__nccwpck_require__(2037));
28016+
function parseAndValidateOutputsJson(input) {
28017+
try {
28018+
const parsed = JSON.parse(input);
28019+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
28020+
throw new Error('outputs_json must be a valid JSON object');
28021+
}
28022+
return parsed;
28023+
}
28024+
catch (error) {
28025+
const errorMessage = `Invalid outputs_json provided: ${error instanceof Error ? error.message : 'Unknown parsing error'}. Input was: ${input}`;
28026+
core.error(errorMessage);
28027+
throw new Error(errorMessage);
28028+
}
28029+
}
2801628030
async function run() {
2801728031
try {
2801828032
let baseUrl;
2801928033
let bbRunUuid;
2802028034
const stepId = core.getInput('step_id');
28021-
const status = core.getInput('status');
28035+
const stepStatus = core.getInput('step_status');
2802228036
const userMessage = core.getInput('user_message');
2802328037
const systemMessage = core.getInput('system_message');
28024-
const summary = core.getInput('summary');
28025-
const finalStatus = core.getInput('final_status');
28038+
const runStatus = core.getInput('run_status');
28039+
const outputsJsonInput = core.getInput('outputs_json');
28040+
let outputsJson;
28041+
try {
28042+
outputsJson = parseAndValidateOutputsJson(outputsJsonInput);
28043+
}
28044+
catch (error) {
28045+
core.setFailed(error instanceof Error ? error.message : 'Unknown error occurred while parsing outputs_json');
28046+
return;
28047+
}
2802628048
const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
2802728049
core.debug(`Temporary directory: ${tempDir}`);
2802828050
console.log(`Temporary directory: ${tempDir}`); // This will also print the path to the console
@@ -28053,15 +28075,15 @@ async function run() {
2805328075
return;
2805428076
}
2805528077
const data = {
28056-
status: finalStatus ? finalStatus : "IN_PROGRESS",
28057-
summary: summary
28078+
status: runStatus ? runStatus : "IN_PROGRESS",
2805828079
};
2805928080
if (stepId) {
2806028081
data.steps = [{
2806128082
id: stepId,
28062-
status: status,
28083+
status: stepStatus,
2806328084
userMessage: userMessage,
28064-
systemMessage: systemMessage
28085+
systemMessage: systemMessage,
28086+
outputs: outputsJson
2806528087
}];
2806628088
}
2806728089
;
@@ -28079,6 +28101,10 @@ async function run() {
2807928101
catch (error) {
2808028102
if (error instanceof Error) {
2808128103
core.setFailed(error.message);
28104+
if (error.response) {
28105+
core.error(`API response status: ${error.response.status}`);
28106+
core.error(`API response data: ${JSON.stringify(error.response.data)}`);
28107+
}
2808228108
}
2808328109
else {
2808428110
core.setFailed('An unknown error occurred');

flake.lock

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

flake.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
description = "A flake that installs Node.js";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
system = "aarch64-darwin"; # Change to your system if needed
9+
pkgs = import nixpkgs { inherit system; };
10+
in {
11+
packages.${system}.default = pkgs.nodejs;
12+
devShells.${system}.default = pkgs.mkShell {
13+
buildInputs = [ pkgs.nodejs ];
14+
};
15+
};
16+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "actions-send-status",
3-
"version": "1.0.0",
3+
"version": "2.0.0-beta.1",
44
"main": "index.js",
55
"scripts": {
66
"build": "ncc build src/index.ts -o dist",

src/index.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,40 @@ import * as fs from 'fs';
44
import * as path from 'path';
55
import * as os from 'os';
66

7+
function parseAndValidateOutputsJson(input: string): object {
8+
try {
9+
const parsed = JSON.parse(input);
10+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
11+
throw new Error('outputs_json must be a valid JSON object');
12+
}
13+
14+
return parsed;
15+
} catch (error) {
16+
const errorMessage = `Invalid outputs_json provided: ${error instanceof Error ? error.message : 'Unknown parsing error'}. Input was: ${input}`;
17+
core.error(errorMessage);
18+
throw new Error(errorMessage);
19+
}
20+
}
21+
722
async function run() {
823
try {
924
let baseUrl: string;
1025
let bbRunUuid: string;
1126

1227
const stepId = core.getInput('step_id');
13-
const status = core.getInput('status');
28+
const stepStatus = core.getInput('step_status');
1429
const userMessage = core.getInput('user_message');
1530
const systemMessage = core.getInput('system_message');
16-
const summary = core.getInput('summary');
17-
const finalStatus = core.getInput('final_status');
31+
const runStatus = core.getInput('run_status');
32+
const outputsJsonInput = core.getInput('outputs_json')
33+
34+
let outputsJson: object;
35+
try {
36+
outputsJson = parseAndValidateOutputsJson(outputsJsonInput);
37+
} catch (error) {
38+
core.setFailed(error instanceof Error ? error.message : 'Unknown error occurred while parsing outputs_json');
39+
return;
40+
}
1841

1942
const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
2043
core.debug(`Temporary directory: ${tempDir}`);
@@ -49,16 +72,16 @@ async function run() {
4972
}
5073

5174
const data: any = {
52-
status: finalStatus ? finalStatus : "IN_PROGRESS",
53-
summary: summary
75+
status: runStatus ? runStatus : "IN_PROGRESS",
5476
};
5577

5678
if (stepId) {
5779
data.steps = [{
5880
id: stepId,
59-
status: status,
81+
status: stepStatus,
6082
userMessage: userMessage,
61-
systemMessage: systemMessage
83+
systemMessage: systemMessage,
84+
outputs: outputsJson
6285
}]
6386
};
6487

@@ -81,6 +104,10 @@ async function run() {
81104
} catch (error) {
82105
if (error instanceof Error) {
83106
core.setFailed(error.message);
107+
if ((error as any).response) {
108+
core.error(`API response status: ${(error as any).response.status}`);
109+
core.error(`API response data: ${JSON.stringify((error as any).response.data)}`);
110+
}
84111
} else {
85112
core.setFailed('An unknown error occurred');
86113
}

0 commit comments

Comments
 (0)