-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexecute.js
More file actions
101 lines (76 loc) · 3.13 KB
/
execute.js
File metadata and controls
101 lines (76 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const path = require('path');
const { AmazonQCLIExecutor } = require('./executors/amazonq-cli-executor');
const { OutputCleaner } = require('./utils/output-cleaner');
/**
* Main entry point for Application observability for AWS investigation
*/
async function run() {
try {
core.info('Starting Application observability for AWS investigation...');
const context = github.context;
// Read the prompt file
const promptFile = process.env.INPUT_PROMPT_FILE;
if (!promptFile || !fs.existsSync(promptFile)) {
throw new Error('Prompt file not found');
}
const promptContent = fs.readFileSync(promptFile, 'utf8');
// Print the full prompt content for debugging
core.debug(promptContent);
// Create output directory
const outputDir = path.join(process.env.RUNNER_TEMP || '/tmp', 'awsapm-output');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Run Amazon Q Developer CLI investigation
let investigationResult = '';
let rawOutput = '';
try {
core.info('Running Amazon Q Developer CLI investigation...');
const executor = new AmazonQCLIExecutor(null);
executor.onRawOutput = (output) => {
rawOutput = output;
};
investigationResult = await executor.execute(promptContent);
core.info('Amazon Q Developer CLI investigation completed');
} catch (error) {
core.error(`Amazon Q Developer CLI failed: ${error.message}`);
// Return the actual error message
investigationResult = `❌ **Amazon Q Investigation Failed**
**Error:** ${error.message}
**User Request:** ${promptContent}
Please check the workflow logs for more details and ensure proper authentication is configured.`;
}
// Clean the output to ensure proper markdown formatting for GitHub
const cleaner = new OutputCleaner();
const cleanedResult = cleaner.clean(investigationResult);
// Save the cleaned response with unique run ID to avoid conflicts on self-hosted runners
const runId = process.env.GITHUB_RUN_ID || Date.now();
const responseFile = path.join(outputDir, `awsapm-response-${runId}.txt`);
fs.writeFileSync(responseFile, cleanedResult);
// Save raw output for integration test validation
if (rawOutput) {
const rawOutputFile = path.join(outputDir, 'awsapm-raw-output.txt');
fs.writeFileSync(rawOutputFile, rawOutput);
}
// Set outputs
core.setOutput('execution_file', responseFile);
core.setOutput('conclusion', 'success');
core.info('Investigation completed');
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
core.error(`Investigation failed: ${errorMessage}`);
core.setFailed(`Investigation failed with error: ${errorMessage}`);
// Still try to set some outputs for error handling
core.setOutput('conclusion', 'failure');
core.setOutput('error_message', errorMessage);
process.exit(1);
}
}
if (require.main === module) {
run();
}
module.exports = { run };