-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: implement energy consumption check (WIP)
- Loading branch information
Showing
3 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: store energy baseline | ||
|
||
on: | ||
# push: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
|
||
jobs: | ||
call-ci: | ||
uses: ./.github/workflows/ci.yaml | ||
with: | ||
upload: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import fs from "fs"; | ||
import core from "@actions/core"; | ||
|
||
function compareEnergy() { | ||
try { | ||
// Read the energy values | ||
const currentData = JSON.parse(fs.readFileSync('/tmp/eco-ci/total-data.json', 'utf8')); | ||
const baselineData = JSON.parse(fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/baseline-data/energy-data.json`, 'utf8')); | ||
|
||
const currentEnergy = currentData.energy_joules; | ||
const baselineEnergy = baselineData.energy_joules; | ||
|
||
// Calculate percentage difference | ||
const percentDiff = ((currentEnergy - baselineEnergy) / baselineEnergy) * 100; | ||
const threshold = 10; | ||
|
||
// Create summary table | ||
const summary = [ | ||
'### Energy Consumption Comparison 🔋\n', | ||
'| Metric | Value | Unit |', | ||
'| --- | --- | --- |', | ||
`| Current Consumption | ${currentEnergy.toFixed(2)} | joules |`, | ||
`| Baseline Consumption | ${baselineEnergy.toFixed(2)} | joules |`, | ||
`| Difference | ${percentDiff.toFixed(2)} | % |`, | ||
'\n' | ||
].join('\n'); | ||
|
||
core.summary.addRaw(summary).write(); | ||
|
||
// Log results | ||
console.log('Energy Consumption Analysis:'); | ||
console.log(`Current: ${currentEnergy.toFixed(2)} joules`); | ||
console.log(`Baseline: ${baselineEnergy.toFixed(2)} joules`); | ||
console.log(`Difference: ${percentDiff.toFixed(2)}%`); | ||
|
||
// Evaluate results | ||
if (percentDiff > threshold) { | ||
const message = `Energy consumption increased by ${percentDiff.toFixed(2)}% (above ${threshold}% threshold)`; | ||
core.setFailed(message); | ||
core.summary.addRaw(`🔴 **Result**: Failed - ${message}`).write(); | ||
} else if (percentDiff < 0) { | ||
const message = `Energy consumption decreased by ${Math.abs(percentDiff).toFixed(2)}%`; | ||
core.notice(message); | ||
core.summary.addRaw(`🟢 **Result**: Passed - ${message}`).write(); | ||
} else { | ||
const message = `Energy consumption increased by ${percentDiff.toFixed(2)}% (within ${threshold}% threshold)`; | ||
core.notice(message); | ||
core.summary.addRaw(`🟡 **Result**: Passed - ${message}`).write(); | ||
} | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
compareEnergy(); |