Skip to content

CI/CD: Add badge generation and upload for test results #28

CI/CD: Add badge generation and upload for test results

CI/CD: Add badge generation and upload for test results #28

Workflow file for this run

name: VUnit Tests
on:
push:
paths:
- 'ip/**'
- '.github/workflows/vunit.yml'
pull_request:
permissions:
contents: read
actions: read
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30 # Prevent runaway jobs
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
with:
python-version: '3.9'
- name: Set up NVC simulator
uses: nickg/setup-nvc@420b0bca758e7ebdca50d1b58771b67f719189ef # v1
with:
version: latest
- name: Install and configure NVC
run: |
nvc --version # NVC binary added to path
- name: Install VUnit
run: |
pip install vunit-hdl
- name: Verify installations
run: |
nvc --version
python -c "import vunit; print('VUnit version:', vunit.__version__)"
- name: Create test reports directory
run: mkdir -p test-reports
- name: Run VUnit tests
run: |
python ./ip/test_runner_ci_cd.py --xunit-xml=test-reports/vunit_results.xml
env:
VUNIT_CI_MODE: "true"
timeout-minutes: 15 # Test execution timeout
- name: Test Report
uses: dorny/test-reporter@c8370352934b730bc7f9acc17180a1f5f3964ffd # v2
if: ${{ !cancelled() }}
with:
name: VUnit Test Results
path: test-reports/vunit_results.xml
reporter: java-junit
fail-on-error: false
- name: Generate XUnit Viewer Report
uses: AutoModality/action-xunit-viewer@7cb0d0fc8cc104017ac5ebd7d9082213a311d4a2 # v1
if: always()
with:
results: test-reports/vunit_results.xml
title: HDL Core Library Test Results
- name: Publish Test Results
id: test-results
uses: EnricoMi/publish-unit-test-result-action@12fa20e14d449d310778f2d0af1e3b2f57dde2a7 # v2
if: always()
with:
files: test-reports/vunit_results.xml
check_name: VUnit Test Results
- name: Set badge color
shell: bash
run: |
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
success)
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
;;
failure)
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
;;
neutral)
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
;;
esac
- name: Create badge
uses: emibcn/badge-action@808173dd03e2f30c980d03ee49e181626088eee8
with:
label: Tests
status: '${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests }} tests, ${{ env.BADGE_COLOR }}'
color: ${{ env.BADGE_COLOR }}
path: badge.svg
- name: Upload badge to Gist
if: >
github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main' ||
github.event_name != 'workflow_run' && github.ref == 'refs/heads/main'
uses: andymckay/append-gist-action@6e8d64427fe47cbacf4ab6b890411f1d67c07f3e
with:
token: ${{ secrets.GIST_TOKEN }}
gistURL: https://gist.githubusercontent.com/nselvara/cc050d27587b0722b2e41f143fa9e2d5
file: badge.svg
- name: Upload test results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: always()
with:
name: test-results
path: test-reports/