Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81364,13 +81364,13 @@ const yaml = __nccwpck_require__(24852);

/**
* Upload artifacts when DEBUG mode is enabled
* @param {string} outputFilePath - Path to the output file
* @param {string[]} files - Path to the output file
* @param {object} [options] - Optional dependencies for testing
* @param {object} [options.artifactClient] - Artifact client instance (defaults to DefaultArtifactClient)
* @param {function} [options.fileExists] - Function to check if file exists (defaults to fs.access)
* @returns {Promise<{uploaded: boolean, id?: number, size?: number, error?: string, reason?: string}>}
*/
async function uploadArtifacts(outputFilePath, options = {}) {
async function uploadArtifacts(files, options = {}) {
const debugMode = process.env.DEBUG === 'true';

if (!debugMode) {
Expand All @@ -81388,19 +81388,14 @@ async function uploadArtifacts(outputFilePath, options = {}) {

const filesToUpload = [];

// Check which files exist and add them to upload list
try {
await fileExists(outputFilePath);
filesToUpload.push(outputFilePath);
} catch {
core.warning(`${outputFilePath} not found, skipping artifact upload for this file`);
}

try {
await fileExists('streetrace.log');
filesToUpload.push('streetrace.log');
} catch {
core.warning('streetrace.log not found, skipping artifact upload for this file');
for (const file of files) {
// Check which files exist and add them to upload list
try {
await fileExists(file);
filesToUpload.push(file);
} catch {
core.warning(`${file} not found, skipping artifact upload for this file`);
}
}

if (filesToUpload.length > 0) {
Expand All @@ -81424,6 +81419,7 @@ async function uploadArtifacts(outputFilePath, options = {}) {
}

async function run() {
const outputFilePath = 'OUTPUT.md';
try {
// Get environment variables
const apiUrl = process.env.STREETRACE_API_URL || 'https://api.streetrace.ai/';
Expand Down Expand Up @@ -81517,7 +81513,6 @@ async function run() {
},
};

const outputFilePath = 'OUTPUT.md';
// Build streetrace command arguments - pass agent URL instead of file path
const streetraceArgs = [`--agent=${agentUrl}`, `--out=${outputFilePath}`];

Expand Down Expand Up @@ -81551,12 +81546,12 @@ async function run() {
core.info(`Final output saved to ${outputFilePath} and action output variable "result"`);
core.info(`Log is in streetrace.log`);

// Step 4: Upload artifacts (only when DEBUG is enabled)
await uploadArtifacts(outputFilePath);

core.info('Streetrace action completed successfully');
} catch (error) {
core.setFailed(`Action failed: ${error.message}`);
} finally {
// Step 4: Upload artifacts (only when DEBUG is enabled)
await uploadArtifacts([outputFilePath, 'streetrace.log']);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

33 changes: 14 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const yaml = require('js-yaml');

/**
* Upload artifacts when DEBUG mode is enabled
* @param {string} outputFilePath - Path to the output file
* @param {string[]} files - Path to the output file
* @param {object} [options] - Optional dependencies for testing
* @param {object} [options.artifactClient] - Artifact client instance (defaults to DefaultArtifactClient)
* @param {function} [options.fileExists] - Function to check if file exists (defaults to fs.access)
* @returns {Promise<{uploaded: boolean, id?: number, size?: number, error?: string, reason?: string}>}
*/
async function uploadArtifacts(outputFilePath, options = {}) {
async function uploadArtifacts(files, options = {}) {
const debugMode = process.env.DEBUG === 'true';

if (!debugMode) {
Expand All @@ -30,19 +30,14 @@ async function uploadArtifacts(outputFilePath, options = {}) {

const filesToUpload = [];

// Check which files exist and add them to upload list
try {
await fileExists(outputFilePath);
filesToUpload.push(outputFilePath);
} catch {
core.warning(`${outputFilePath} not found, skipping artifact upload for this file`);
}

try {
await fileExists('streetrace.log');
filesToUpload.push('streetrace.log');
} catch {
core.warning('streetrace.log not found, skipping artifact upload for this file');
for (const file of files) {
// Check which files exist and add them to upload list
try {
await fileExists(file);
filesToUpload.push(file);
} catch {
core.warning(`${file} not found, skipping artifact upload for this file`);
}
}

if (filesToUpload.length > 0) {
Expand All @@ -66,6 +61,7 @@ async function uploadArtifacts(outputFilePath, options = {}) {
}

async function run() {
const outputFilePath = 'OUTPUT.md';
try {
// Get environment variables
const apiUrl = process.env.STREETRACE_API_URL || 'https://api.streetrace.ai/';
Expand Down Expand Up @@ -159,7 +155,6 @@ async function run() {
},
};

const outputFilePath = 'OUTPUT.md';
// Build streetrace command arguments - pass agent URL instead of file path
const streetraceArgs = [`--agent=${agentUrl}`, `--out=${outputFilePath}`];

Expand Down Expand Up @@ -193,12 +188,12 @@ async function run() {
core.info(`Final output saved to ${outputFilePath} and action output variable "result"`);
core.info(`Log is in streetrace.log`);

// Step 4: Upload artifacts (only when DEBUG is enabled)
await uploadArtifacts(outputFilePath);

core.info('Streetrace action completed successfully');
} catch (error) {
core.setFailed(`Action failed: ${error.message}`);
} finally {
// Step 4: Upload artifacts (only when DEBUG is enabled)
await uploadArtifacts([outputFilePath, 'streetrace.log']);
}
}

Expand Down
26 changes: 13 additions & 13 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ describe('prompt handling logic', () => {
});

// Mock other core functions
core.info.mockImplementation(() => {});
core.warning.mockImplementation(() => {});
core.setOutput.mockImplementation(() => {});
core.setFailed.mockImplementation(() => {});
core.info.mockImplementation(() => { });
core.warning.mockImplementation(() => { });
core.setOutput.mockImplementation(() => { });
core.setFailed.mockImplementation(() => { });
});

it('should use action input prompt when provided', () => {
Expand Down Expand Up @@ -352,9 +352,9 @@ describe('artifact upload logic', () => {
delete process.env.DEBUG;

// Mock core functions
core.info.mockImplementation(() => {});
core.warning.mockImplementation(() => {});
core.setOutput.mockImplementation(() => {});
core.info.mockImplementation(() => { });
core.warning.mockImplementation(() => { });
core.setOutput.mockImplementation(() => { });

// Create mock artifact client
mockArtifactClient = {
Expand Down Expand Up @@ -395,7 +395,7 @@ describe('artifact upload logic', () => {
it('should skip artifact upload when DEBUG is empty string', async () => {
process.env.DEBUG = '';

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand All @@ -414,7 +414,7 @@ describe('artifact upload logic', () => {
mockFileExists.mockResolvedValue(true);
mockArtifactClient.uploadArtifact.mockResolvedValue({ id: 123, size: 1024 });

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md', 'streetrace.log'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand All @@ -436,7 +436,7 @@ describe('artifact upload logic', () => {
.mockRejectedValueOnce(new Error('ENOENT')); // streetrace.log does not exist
mockArtifactClient.uploadArtifact.mockResolvedValue({ id: 456, size: 512 });

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand All @@ -455,7 +455,7 @@ describe('artifact upload logic', () => {
.mockResolvedValueOnce(true); // streetrace.log exists
mockArtifactClient.uploadArtifact.mockResolvedValue({ id: 789, size: 256 });

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md', 'streetrace.log'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand All @@ -471,7 +471,7 @@ describe('artifact upload logic', () => {
it('should return no_files reason when no files exist to upload', async () => {
mockFileExists.mockRejectedValue(new Error('ENOENT'));

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand All @@ -484,7 +484,7 @@ describe('artifact upload logic', () => {
mockFileExists.mockResolvedValue(true);
mockArtifactClient.uploadArtifact.mockRejectedValue(new Error('Network error'));

const result = await uploadArtifacts('OUTPUT.md', {
const result = await uploadArtifacts(['OUTPUT.md'], {
artifactClient: mockArtifactClient,
fileExists: mockFileExists,
});
Expand Down
Loading