Skip to content

Commit cfb7ca1

Browse files
pelikhanCopilot
andauthored
Refactor inline JavaScript snippet into separate embedded file for setup_agent_output (#18) (#208)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 8c6af8c commit cfb7ca1

11 files changed

Lines changed: 264 additions & 97 deletions

.github/workflows/issue-triage.lock.yml

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

.github/workflows/test-claude.lock.yml

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

.github/workflows/test-codex.lock.yml

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

.github/workflows/test-proxy.lock.yml

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

.github/workflows/weekly-research.lock.yml

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

pkg/workflow/compiler.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,23 +2683,9 @@ func (c *Compiler) generateOutputFileSetup(yaml *strings.Builder, data *Workflow
26832683
yaml.WriteString(" uses: actions/github-script@v7\n")
26842684
yaml.WriteString(" with:\n")
26852685
yaml.WriteString(" script: |\n")
2686-
yaml.WriteString(" const fs = require('fs');\n")
2687-
yaml.WriteString(" const crypto = require('crypto');\n")
2688-
yaml.WriteString(" // Generate a random filename for the output file\n")
2689-
yaml.WriteString(" const randomId = crypto.randomBytes(8).toString('hex');\n")
2690-
yaml.WriteString(" const outputFile = `/tmp/aw_output_${randomId}.txt`;\n")
2691-
yaml.WriteString(" // Ensure the /tmp directory exists and create empty output file\n")
2692-
yaml.WriteString(" fs.mkdirSync('/tmp', { recursive: true });\n")
2693-
yaml.WriteString(" fs.writeFileSync(outputFile, '', { mode: 0o644 });\n")
2694-
yaml.WriteString(" // Verify the file was created and is writable\n")
2695-
yaml.WriteString(" if (!fs.existsSync(outputFile)) {\n")
2696-
yaml.WriteString(" throw new Error(`Failed to create output file: ${outputFile}`);\n")
2697-
yaml.WriteString(" }\n")
2698-
yaml.WriteString(" // Set the environment variable for subsequent steps\n")
2699-
yaml.WriteString(" core.exportVariable('GITHUB_AW_OUTPUT', outputFile);\n")
2700-
yaml.WriteString(" console.log('Created agentic output file:', outputFile);\n")
2701-
yaml.WriteString(" // Also set as step output for reference\n")
2702-
yaml.WriteString(" core.setOutput('output_file', outputFile);\n")
2686+
2687+
// Use the embedded setup agent output script
2688+
WriteJavaScriptToYAML(yaml, setupAgentOutputScript)
27032689
}
27042690

27052691
// generateOutputCollectionStep generates a step that reads the output file and sets it as a GitHub Actions output

pkg/workflow/js.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ var sanitizeOutputScript string
2121
//go:embed js/add_labels.cjs
2222
var addLabelsScript string
2323

24+
//go:embed js/setup_agent_output.cjs
25+
var setupAgentOutputScript string
26+
2427
// FormatJavaScriptForYAML formats a JavaScript script with proper indentation for embedding in YAML
2528
func FormatJavaScriptForYAML(script string) []string {
2629
var formattedLines []string
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function main() {
2+
const fs = require('fs');
3+
const crypto = require('crypto');
4+
5+
// Generate a random filename for the output file
6+
const randomId = crypto.randomBytes(8).toString('hex');
7+
const outputFile = `/tmp/aw_output_${randomId}.txt`;
8+
9+
// Ensure the /tmp directory exists and create empty output file
10+
fs.mkdirSync('/tmp', { recursive: true });
11+
fs.writeFileSync(outputFile, '', { mode: 0o644 });
12+
13+
// Verify the file was created and is writable
14+
if (!fs.existsSync(outputFile)) {
15+
throw new Error(`Failed to create output file: ${outputFile}`);
16+
}
17+
18+
// Set the environment variable for subsequent steps
19+
core.exportVariable('GITHUB_AW_OUTPUT', outputFile);
20+
console.log('Created agentic output file:', outputFile);
21+
22+
// Also set as step output for reference
23+
core.setOutput('output_file', outputFile);
24+
}
25+
26+
main();

0 commit comments

Comments
 (0)