Skip to content

Commit

Permalink
need add package github
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Sep 27, 2024
1 parent fce790f commit a64cfbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/extractResultsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
// This file extracts the results of the tests from the file results.json

import fs from 'fs';
// import path from 'path';
import {exec} from 'child_process';
import path from 'path';
import {core}from '@actions/core';

// Path to the file containing the results of the tests
const filePath = './test/results/results.json';

fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
console.error('Reading file failed:', err);
process.exit(1); // out with an error
core.setFailed(`Reading file failed with error: ${err}`);
}

try {
Expand All @@ -27,16 +27,23 @@ fs.readFile(filePath, 'utf-8', (err, data) => {
const todoTests = results.numTodoTests;
const successTests = results.success=='true' ? 1 : 0;

// Print the outputs for GitHub Actions
exec(`echo "{totalTests}=${totalTests}" >> "$GITHUB_OUT"`);
exec(`echo "{passedTests}=${passedTests}" >> "$GITHUB_OUT"`);
exec(`echo "{failedTests}=${failedTests}" >> "$GITHUB_OUT"`);
exec(`echo "{pendingTests}=${pendingTests}" >> "$GITHUB_OUT"`);
exec(`echo "{todoTests}=${todoTests}" >> "$GITHUB_OUT"`);
exec(`echo "{successTests}=${successTests}" >> "$GITHUB_OUT"`);

} catch (parseError) {
console.error('Analyse of json failed', parseError);
process.exit(1); // out with an error
// Sauvegarde l'état dans le fichier GitHub state
fs.appendFileSync(
path.join(process.env.GITHUB_OUTPUT),
`\ntotalTest=${totalTests}\npassedTests=${passedTests}\nfailedTests=${failedTests}\npendingTests=${pendingTests}\ntodoTests=${todoTests}\nsuccessTests=${successTests}\n`
);

// Définir l'output
core.setOutput("todoTests", todoTests);
core.setOutput("successTests", successTests);
core.setOutput("totalTests", totalTests);
core.setOutput("passedTests", passedTests);
core.setOutput("failedTests", failedTests);
core.setOutput("pendingTests", pendingTests);


} catch (error) {
console.error('Analyse of json failed', error);
core.setFailed(`Action failed with error: ${error}`);
}
});
1 change: 1 addition & 0 deletions .github/workflows/test_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
- name: Extract test results
id: extract_results
run: |
npm install @actions/core
node .github/workflows/extractResultsTest.js
- name: Generate Badges fail result global tests
if: steps.extract_results.outputs.successTests == 0
Expand Down

0 comments on commit a64cfbb

Please sign in to comment.