Skip to content

Add conditional check so Verilator is skipped for documentation PR's #730

Add conditional check so Verilator is skipped for documentation PR's

Add conditional check so Verilator is skipped for documentation PR's #730

# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Verilator
on:
push:
branches: ["main", "dev-goog", "dev-msft"]
workflow_call:
workflow_dispatch:
env:
CARGO_INCREMENTAL: 0
SCCACHE_VERSION: 0.3.3
RISCV_VERSION: v12.1.0
VERILATOR_VERSION: v5.012
PKG_CONFIG_PATH: /opt/verilator/share/pkgconfig
SCCACHE_GHA_CACHE_TO: sccache-verilator-10000
SCCACHE_GHA_CACHE_FROM: sccache-verilator-
# Change this to a new random value if you suspect the cache is corrupted
SCCACHE_C_CUSTOM_CACHE_BUSTER: f3e6951f0c1e
jobs:
# always_run:
# # Verilator is always run outside of the Pull Request context.
# # For Pull Requests, conditionally run based on evaluation
# name: Force Verilator to Run
# runs-on: ubuntu-22.04
# if: ${{ (github.event_name != 'pull_request') }}
# outputs:
# run_flag: ${{ steps.set_output.flag }}
# steps:
# - name: Set Output
# id: set_output
# run: echo "flag=1" >> "${GITHUB_OUTPUT}"
#
# Verilator is always run outside of the Pull Request context.
# For Pull Requests, conditionally run based on evaluation
evaluate_if_run:
name: Evaluate if Verilator Will Run
runs-on: ubuntu-22.04
outputs:
run_vltr: ${{ steps.decide.outputs.run }}
env:
DO_EVAL: ${{ (github.event_name == 'pull_request') }}
# needs: always_run
# if: ${{ needs.always_run.result == "skipped" }}
steps:
- uses: actions/checkout@v3
if: ${{ env.DO_EVAL == true }}
with:
submodules: 'true'
# If any non-documentation files have been modified as part of a
# Pull Request, run the Verilator checks
# Otherwise, skip Verilator
steps:

Check failure on line 57 in .github/workflows/build-test-verilator.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-test-verilator.yml

Invalid workflow file

You have an error in your yaml syntax on line 57
- name: Compare
id: compare
if: ${{ env.DO_EVAL == true }}
run: |
if [[ -n "$(git diff --name-only --merge-base \"${{ github.event.pull_request.base_ref }}\" | grep -v '\.md\|\.png\|\.github\/workflows')" ]]; then
echo "src_mods=true" >> "${GITHUB_OUTPUT}"
else
echo "src_mods=false" >> "${GITHUB_OUTPUT}"
fi
steps:
- name: Decide
id: decide
run: |
if [[ "${{ env.DO_EVAL }}" == "false" ]]; then
echo "run=true" >> "${GITHUB_OUTPUT}"
elif [[ ${{ steps.compare.outputs.src_mods }} == "true" ]]
echo "run=true" >> "${GITHUB_OUTPUT}"
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
build_tools:
name: Build Tools
runs-on: ubuntu-22.04
needs: evaluate_if_run
if: ${{ needs.evaluate_if_run.outputs.run_vltr }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- name: Restore Cargo index
uses: actions/cache/restore@v3
id: cargo_index_restore
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}-${{ hashFiles('Cargo.lock') }}
- name: Restore sccache binary
uses: actions/cache/restore@v3
id: sccache_bin_restore
with:
path: ~/.cargo/bin/sccache
key: sccache-bin-${{ env.SCCACHE_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Install sccache
if: steps.sccache_bin_restore.outputs.cache-hit != 'true'
run: |
cargo install sccache --locked --version ${SCCACHE_VERSION} --no-default-features --features=gha
- name: Save sccache binary
uses: actions/cache/save@v3
if: steps.sccache_bin_restore.outputs.cache-hit != 'true'
with:
path: ~/.cargo/bin/sccache
key: sccache-bin-${{ env.SCCACHE_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Configure sccache
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Restore verilator dir
uses: actions/cache/restore@v3
id: verilator_restore
with:
path: /opt/verilator
key: verilator-${{ env.VERILATOR_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Install verilator
if: steps.verilator_restore.outputs.cache-hit != 'true'
run: |
sudo apt-get install flex bison libfl2 libfl-dev help2man
cd /tmp/
git clone -b "${VERILATOR_VERSION}" https://github.com/verilator/verilator
cd verilator
autoconf
./configure --prefix=/opt/verilator CXX="sccache g++"
make -j6
sudo make install
- name: Save verilator dir
uses: actions/cache/save@v3
if: steps.verilator_restore.outputs.cache-hit != 'true'
with:
path: /opt/verilator
key: verilator-${{ env.VERILATOR_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Setup verilator path
run: |
echo /opt/verilator/bin >> $GITHUB_PATH
- name: Restore Risc V Toolchain
uses: actions/cache/restore@v3
id: riscv_restore
with:
path: /opt/riscv
key: riscv-${{ env.RISCV_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Install Risc V Toolchain
if: steps.riscv_restore.outputs.cache-hit != 'true'
run: |
# Building from source takes around 6.65 GB of disk and download size
wget -O toolchain.tar.gz https://github.com/chipsalliance/caliptra-tools/releases/download/gcc-v12.1.0/riscv64-unknown-elf.gcc-12.1.0.tar.gz
tar -xzf toolchain.tar.gz -C /opt/
- name: Save riscv dir
uses: actions/cache/save@v3
if: steps.riscv_restore.outputs.cache-hit != 'true'
with:
path: /opt/riscv
key: riscv-${{ env.RISCV_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Setup riscv path
run: |
echo /opt/riscv/bin >> $GITHUB_PATH
build_matrix:
name: Build Smoke Test matrix
runs-on: ubuntu-22.04
needs:
- build_tools
- evaluate_if_run
if: ${{ needs.evaluate_if_run.outputs.run_vltr }}
outputs:
test_names: ${{ steps.output-matrix.outputs.test_names }}
env:
EXCLUDE_TESTS: "smoke_test_clk_gating, smoke_test_cg_wdt, smoke_test_mbox_cg, smoke_test_kv_cg, smoke_test_doe_cg"
steps:
- uses: actions/checkout@v3
- name: Install deps
run: |
sudo apt-get update -qy && sudo apt-get install -qy --no-install-recommends \
python3-minimal python3-yaml
- name: Build matrix
id: output-matrix
run: |
echo "test_names=$(python3 .github/scripts/build_tests_matrix.py)" >> $GITHUB_OUTPUT
build_and_test:
name: Verilator
runs-on: ubuntu-22.04
needs:
- build_matrix
- evaluate_if_run
if: ${{ needs.evaluate_if_run.outputs.run_vltr }}
strategy:
fail-fast: false
matrix:
test_name: ${{fromJSON(needs.build_matrix.outputs.test_names)}}
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- name: Restore Cargo index
uses: actions/cache/restore@v3
id: cargo_index_restore
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}-${{ hashFiles('Cargo.lock') }}
- name: Restore sccache binary
uses: actions/cache/restore@v3
id: sccache_bin_restore
with:
path: ~/.cargo/bin/sccache
key: sccache-bin-${{ env.SCCACHE_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Restore verilator dir
uses: actions/cache/restore@v3
id: verilator_restore
with:
path: /opt/verilator
key: verilator-${{ env.VERILATOR_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Restore Risc V Toolchain
uses: actions/cache/restore@v3
id: riscv_restore
with:
path: /opt/riscv
key: riscv-${{ env.RISCV_VERSION }}-${{ env.SCCACHE_C_CUSTOM_CACHE_BUSTER }}
- name: Setup verilator path
run: |
echo /opt/verilator/bin >> $GITHUB_PATH
- name: Setup riscv path
run: |
echo /opt/riscv/bin >> $GITHUB_PATH
- name: Run Caliptra Verilator Smoke Test
run: |
CALIPTRA_ROOT=$(pwd)
ADAMSBRIDGE_ROOT=$CALIPTRA_ROOT/submodules/adams-bridge
cd tools/scripts
make verilator CALIPTRA_ROOT=$CALIPTRA_ROOT ADAMSBRIDGE_ROOT=$ADAMSBRIDGE_ROOT TESTNAME=${{ matrix.test_name }} | tee output.log
# Search the last 30 lines of the output for "TESTCASE PASSED"
tail -n 30 output.log | grep "TESTCASE PASSED"
# grep will return 0 if the search term is found, and 1 otherwise
# A non-zero value will cause the github action to fail.
exit $?
verify_test_results:
name: Verify Verilator Test Results
runs-on: ubuntu-22.04
needs:
- build_and_test
- evaluate_if_run
# Force to run even if the build_and_test job is skipped for any reason
if: ${{ !cancelled() }}
steps:
- name: Print Verilator Aggregated Result
run: |
echo "Run Verilator check has a result of ${{ needs.evaluate_if_run.outputs.run_vltr }}"
if [[ "${{ needs.evaluate_if_run.outputs.run_vltr }}" != "true" ]]; then
exit 0
fi
echo "build_and_test has a result of [${{ needs.build_and_test.result }}]"
if [[ "${{ needs.build_and_test.result }}" != "success" ]]; then
exit 1
fi