Skip to content

Evaluate agent

Evaluate agent #439

Workflow file for this run

name: Evaluate agent
on:
workflow_run:
workflows: ["Build and push image"]
types:
- completed
jobs:
drive:
runs-on: [self-hosted, drive]
env:
AGENT_VERSION: latest
COMPOSE_FILE: ./build/docker-compose.cicd.yaml
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print environment variables (DEBUG)
run: |
echo "AGENT_VERSION=${AGENT_VERSION}"
echo "COMPOSE_FILE=${COMPOSE_FILE}"
- name: Download artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "artifact"
})[0];
if (!matchArtifact) {
core.setFailed('No artifact found from the build workflow');
return;
}
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data));
- name: Unzip artifact
run: unzip artifact.zip
- name: Return artifact JSON
id: return-artifact-json
uses: actions/github-script@v6
with:
script: |
let fs = require('fs');
let data = JSON.parse(fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.json`));
return data;
- name: Run docker-compose
run: |
xhost +local:
USERNAME=$(whoami) USER_UID=$(id -u) USER_GID=$(id -g) RENDER_OFFSCREEN=-RenderOffScreen docker compose up --quiet-pull --exit-code-from agent
- name: Copy results
run: docker compose cp agent:/tmp/simulation_results.json .
- name: Stop docker-compose
# always run this step, to clean up even on error
if: always()
run: docker compose down -v
# add rendered JSON as comment to the pull request
- name: Create simulation results table
id: simulation-results
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
// read the simulation results
const results = fs.readFileSync('./simulation_results.json', 'utf8');
let resultsJson = JSON.parse(results);
// create a markdown table of the results
let resultsTable = resultsJson.values.map((values, i) => {
return `| ${resultsJson.labels[i]} | ${values} |`;
});
// create a markdown table header
let resultsTableHeader = `| Metric | Value |`;
// create a markdown table divider
let resultsTableDivider = `| --- | --- |`;
// add everything to the resultsTable
resultsTable = resultsTableHeader + '\n' + resultsTableDivider + '\n' + resultsTable.join('\n');
return resultsTable;
result-encoding: string
- name: Print simulation results
run: |
echo "Simulation results\n"
echo "${{ steps.simulation-results.outputs.result }}"
- name: Add simulation results as comment
if: ${{ steps.return-artifact-json.outputs.result.is_pr }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# this script reads the simulation_results.json and creates a comment on the pull request with the results.
script: |
let issue_number = Number(${{ steps.return-artifact-json.outputs.pr_id }});
// add the results as a comment to the pull request
github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "## Simulation results\n" + ${{ steps.simulation-results.outputs.result }}
});
- name: Prune all images older than 1 days from self-hosted runner
run: docker image prune -a --filter "until=24h"