ci: implement energy consumption check (WIP) #62
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
name: lpt-application-ui CI | |
on: | |
push: | |
workflow_call: | |
inputs: | |
upload: | |
default: false | |
required: false | |
type: boolean | |
permissions: | |
actions: read | |
contents: read | |
jobs: | |
build: | |
timeout-minutes: 2 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Eco-CI Init | |
uses: green-coding-berlin/eco-ci-energy-estimation@main | |
with: | |
task: start-measurement | |
json-output: true | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Checkout Repo Measurement | |
uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
with: | |
task: get-measurement | |
label: 'repo checkout' | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
shell: bash | |
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} | |
- name: Cache node modules | |
id: cache-npm | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Npm Cache Measurement | |
uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
with: | |
task: get-measurement | |
label: 'cache npm dependencies' | |
- name: Install dependencies | |
if: steps.cache-npm.outputs.cache-hit != 'true' | |
run: npm ci --prefer-offline --no-audit --no-progress --no-fund | |
- name: Install Dependencies Measurement | |
uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
with: | |
task: get-measurement | |
label: 'install dependencies' | |
# - name: Check linting across the board | |
# shell: bash | |
# run: npm run lint:ci | |
# - name: Lint Measurement | |
# uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
# with: | |
# task: get-measurement | |
# label: 'lint app' | |
# - name: Build application | |
# shell: bash | |
# run: npm run build:gcp | |
# - name: Build Measurement | |
# uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
# with: | |
# task: get-measurement | |
# label: 'build:gcp app' | |
# - name: Run unit tests | |
# shell: bash | |
# run: | | |
# # no tests to run: | |
# npm run test:cover || echo 0 | |
# - name: Unit Tests Measurement | |
# uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
# with: | |
# task: get-measurement | |
# label: 'unit tests' | |
- name: Show Energy Result | |
id: data-total | |
uses: green-coding-solutions/eco-ci-energy-estimation@v4 | |
with: | |
task: display-results | |
- name: Get last successful baseline run ID | |
id: get-baseline | |
run: | | |
BASELINE_RUN_ID=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"repos/${{ github.repository }}/actions/workflows/energy-consumption-baseline.yaml/runs?per_page=1&status=success" \ | |
--jq '.workflow_runs[0].id') | |
echo "baseline_run_id=${BASELINE_RUN_ID}" >> $GITHUB_OUTPUT | |
echo "used runId of the energy baseline run: ${BASELINE_RUN_ID}" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: test | |
run: | | |
echo "runId: ${{steps.get-baseline.outputs.baseline_run_id}}" | |
- name: Download Baseline Energy Consumption | |
uses: actions/download-artifact@v4 | |
with: | |
name: energy-data | |
path: ${{ github.workspace }}/energy-data.json | |
github-token: ${{ github.token }} | |
repository: ${{ github.repository }} | |
run-id: ${{ steps.get-baseline.outputs.baseline_run_id }} | |
- name: Compare energy consumption | |
run: | | |
echo "Comparing energy consumption with baseline" | |
CURRENT_ENERGY=$(jq '.energy_joules' /tmp/eco-ci/total-data.json) | |
BASELINE_ENERGY=$(jq '.energy_joules' ${{ github.workspace }}/energy-data.json) | |
echo "Current energy consumption: ${CURRENT_ENERGY} joules" | |
echo "Baseline energy consumption: ${BASELINE_ENERGY} joules" | |
- name: Upload energy data | |
if: inputs.upload == true | |
uses: actions/upload-artifact@v4 | |
with: | |
name: energy-data | |
path: /tmp/eco-ci/total-data.json | |
retention-days: 10 |