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
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inputs:
required: false
default: 'false'
report:
description: 'Path to write JSON report file (batch mode)'
description: 'Path to write JSON report file'
required: false
default: ''
rate_limit:
Expand Down Expand Up @@ -110,7 +110,7 @@ outputs:
error_message:
description: 'First error message from failed config (truncated to 100 chars)'
report_json:
description: 'Raw JSON report content (batch mode only, from --report)'
description: 'Raw JSON report content (from --report)'

runs:
using: 'node20'
Expand Down
129 changes: 90 additions & 39 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40405,6 +40405,14 @@ const VALID_COMMANDS = [
const EXFIG_REPO = 'alexey1312/exfig';
const EXFIG_BINARY_NAME = 'ExFig'; // Capital letters
const PKL_VERSION = '0.30.2';
/** Commands that support --report for structured JSON output */
const REPORT_COMMANDS = [
'batch',
'colors',
'icons',
'images',
'typography',
];
// =============================================================================
// Input Parsing
// =============================================================================
Expand Down Expand Up @@ -40780,9 +40788,9 @@ function buildCommand(inputs) {
if (configPaths.length > 0) {
args.push(...configPaths);
}
// Auto-inject --report for batch mode (structured JSON parsing)
// Auto-inject --report for commands that support structured JSON output
let reportPath = '';
if (inputs.command === 'batch') {
if (REPORT_COMMANDS.includes(inputs.command)) {
reportPath = inputs.report || path.join(os.tmpdir(), 'exfig-report.json');
args.push('--report', reportPath);
}
Expand Down Expand Up @@ -40859,44 +40867,86 @@ function parseExFigOutput(output) {
function parseReportFile(reportPath) {
if (!fs.existsSync(reportPath))
return null;
let content;
try {
const content = fs.readFileSync(reportPath, 'utf-8');
const report = JSON.parse(content);
let assetsExported = 0;
let validatedCount = 0;
let exportedConfigs = 0;
let errorMessage = '';
let errorCategory = '';
for (const r of report.results) {
if (r.success && r.stats) {
const total = r.stats.colors + r.stats.icons + r.stats.images + r.stats.typography;
if (total > 0) {
assetsExported += total;
exportedConfigs++;
}
else {
validatedCount++;
}
content = fs.readFileSync(reportPath, 'utf-8');
}
catch (error) {
const msg = error instanceof Error ? error.message : String(error);
core.warning(`Failed to read report file ${reportPath}: ${msg}`);
return null;
}
let report;
try {
report = JSON.parse(content);
}
catch (error) {
const msg = error instanceof Error ? error.message : String(error);
core.warning(`Failed to parse report JSON from ${reportPath}: ${msg}`);
return null;
}
// Discriminate batch vs single export report by structure
if ('results' in report && Array.isArray(report.results)) {
return parseBatchReport(report);
}
if ('command' in report && typeof report.command === 'string' && report.stats != null) {
return parseSingleReport(report);
}
core.warning(`Unknown report format in ${reportPath}: expected 'results' (batch) or 'command' (single export) key`);
return null;
}
function parseBatchReport(report) {
let assetsExported = 0;
let validatedCount = 0;
let exportedConfigs = 0;
let errorMessage = '';
let errorCategory = '';
for (const r of report.results) {
if (r.success && r.stats) {
const total = r.stats.colors + r.stats.icons + r.stats.images + r.stats.typography;
if (total > 0) {
assetsExported += total;
exportedConfigs++;
}
else if (!r.success && r.error && !errorMessage) {
errorMessage = r.error.substring(0, 100);
if (r.error.length > 100)
errorMessage += '...';
errorCategory = categorizeError(r.error);
else {
validatedCount++;
}
}
return {
assetsExported,
validatedCount,
exportedConfigs,
failedCount: report.failureCount,
errorMessage,
errorCategory,
};
else if (!r.success && r.error && !errorMessage) {
errorMessage = r.error.substring(0, 100);
if (r.error.length > 100)
errorMessage += '...';
errorCategory = categorizeError(r.error);
}
}
catch {
return null;
return {
assetsExported,
validatedCount,
exportedConfigs,
failedCount: report.failureCount,
errorMessage,
errorCategory,
};
}
function parseSingleReport(report) {
const stats = report.stats ?? { colors: 0, icons: 0, images: 0, typography: 0 };
const assetsExported = stats.colors + stats.icons + stats.images + stats.typography;
let errorMessage = '';
let errorCategory = '';
if (!report.success && report.error) {
errorMessage = report.error.substring(0, 100);
if (report.error.length > 100)
errorMessage += '...';
errorCategory = categorizeError(report.error);
}
return {
assetsExported,
validatedCount: report.success && assetsExported === 0 ? 1 : 0,
exportedConfigs: assetsExported > 0 ? 1 : 0,
failedCount: report.success ? 0 : 1,
errorMessage,
errorCategory,
};
}
function categorizeError(error) {
const errorLower = error.toLowerCase();
Expand Down Expand Up @@ -41089,21 +41139,22 @@ async function run() {
}
const result = await runExFig(binaryPath, args, inputs.figmaToken);
outputs.duration = `${result.durationSeconds}s`;
// Parse output: prefer structured report for batch, fallback to regex
// Parse output: prefer structured report when available, fallback to regex
let metrics;
if (inputs.command === 'batch' && reportPath) {
if (REPORT_COMMANDS.includes(inputs.command) && reportPath) {
const reportMetrics = parseReportFile(reportPath);
if (reportMetrics) {
metrics = reportMetrics;
try {
outputs.reportJson = fs.readFileSync(reportPath, 'utf-8');
}
catch {
// Non-fatal: report file read failed after successful parse
catch (error) {
const msg = error instanceof Error ? error.message : String(error);
core.warning(`Failed to read report file for output: ${msg}`);
}
}
else {
core.warning('Report file not found, falling back to output parsing');
core.warning('Failed to parse report file, falling back to output parsing');
metrics = parseExFigOutput(result.stdout + result.stderr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading