name: chipyard-ci-process

on:
  # run ci on pull requests targeting following branches (runs on the merge commit)
  pull_request:
    branches:
      - main
      - '1.[0-9]*.x'

defaults:
  run:
    shell: bash -leo pipefail {0}

env:
  tools-cache-version: v17
  JVM_OPTS: -Xmx3200m # Customize the JVM maximum heap limit
  conda-env-name-no-time: cy-${{ github.run_id }}
  workflow-timestamp: ${{ github.event.pull_request.updated_at }}

jobs:
  cancel-prior-workflows:
    name: cancel-prior-workflows
    runs-on: ubuntu-latest
    steps:
      - name: Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.12.1
        with:
          access_token: ${{ github.token }}

  start-workflow:
    name: start-workflow
    # unable to access env context in job.if thus have to put gh-a context expression directly here.
    # note that the check is using a boolean true instead of string 'true' since it's directly using
    # the expression not a variable like if checking against the env context string.
    if: ${{ contains(github.event.pull_request.labels.*.name, 'ci:disable') != true }}
    runs-on: ubuntu-22.04
    steps:
      - run: true

  # Set up a set of boolean conditions to control which branches of the CI
  # workflow will execute This is based off the conditional job execution
  # example here: https://github.com/dorny/paths-filter#examples
  change-filters:
    name: filter-jobs-on-changes
    runs-on: ubuntu-latest
    needs: start-workflow
    # Queried by downstream jobs to determine if they should run.
    outputs:
      needs-rtl: ${{ steps.filter.outputs.all_count != steps.filter.outputs.skip-rtl_count }}
    steps:
      - uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - uses: dorny/paths-filter@v3
        id: filter
        with:
          filters: |
            all:
              - '**'

            # If any of the files changed match, do a doc build
            docs: &docs-filter
              - 'docs/**'
              - '.readthedocs.yml'

            # If all files match to this filter, skip the main ci pipeline
            skip-rtl:
              - *docs-filter
              - '**/*.md'
              - '**/.gitignore'
              - '.github/ISSUE_TEMPLATE/**'
              - '.github/PULL_REQUEST_TEMPLATE.md'
              - '.github/dependabot.yml'
              - '.mergify.yml'

  create-conda-env-as4:
    name: create-conda-env-as4
    needs: [change-filters, cancel-prior-workflows]
    if: needs.change-filters.outputs.needs-rtl == 'true'
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Cleanup conda
        uses: ./.github/actions/cleanup-conda
      - name: Create conda env
        uses: ./.github/actions/create-conda-env

  # Sentinel job to simplify how we specify which that basic setup is complete
  #
  # When adding new prep jobs, please add them to `needs` below
  setup-complete:
    name: setup-complete
    needs: [create-conda-env-as4]
    runs-on: ubuntu-latest
    steps:
      - name: Set up complete
        run: echo Set up is complete!

  ##########################################################################

  commit-on-master-check:
    name: commit-on-master-check
    needs: [setup-complete]
    if: needs.change-filters.outputs.needs-rtl == 'true'
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Check commits of each submodule
        run: |
            conda activate ${{ env.conda-env-name-no-time }}-$(date --date "${{ env.workflow-timestamp }}" +%Y%m%d)
            .github/scripts/check-commit.sh

  documentation-check:
    name: documentation-check
    needs: [setup-complete]
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Check that documentation builds with no warnings/errors
        run: |
          conda activate ${{ env.conda-env-name-no-time }}-$(date --date "${{ env.workflow-timestamp }}" +%Y%m%d)
          make -C docs html
      - name: Show error log from sphinx if failed
        if: ${{ failure() }}
        run: cat /tmp/sphinx-err*.log

  build-extra-tests:
    name: build-extra-tests
    needs: [setup-complete]
    if: needs.change-filters.outputs.needs-rtl == 'true'
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Generate keys
        id: genkey
        run: |
          echo "extra-tests-cache-key=extra-tests-${{ github.sha }}" >> $GITHUB_OUTPUT
      - uses: actions/cache@v4
        id: build-extra-tools-cache
        with:
          path: extra-tests-install
          key: ${{ steps.genkey.outputs.extra-tests-cache-key }}
          restore-keys: ${{ steps.genkey.outputs.extra-tests-cache-key }}
      - name: Build extra tests
        run: |
            conda activate ${{ env.conda-env-name-no-time }}-$(date --date "${{ env.workflow-timestamp }}" +%Y%m%d)
            .github/scripts/build-extra-tests.sh

  prepare-chipyard-cores:
    name: prepare-chipyard-cores
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-cores"

  prepare-chipyard-constellation:
    name: prepare-chipyard-constellation
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-constellation"

  prepare-chipyard-peripherals:
    name: prepare-chipyard-peripherals
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-peripherals"

  prepare-chipyard-accels:
    name: prepare-chipyard-accels
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-accels"

  prepare-chipyard-tracegen:
    name: prepare-chipyard-tracegen
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-tracegen"

  prepare-chipyard-other:
    name: prepare-chipyard-other
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-other"

  prepare-chipyard-fpga:
    name: prepare-chipyard-fpga
    needs: setup-complete
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build RTL on self-hosted
        uses: ./.github/actions/prepare-rtl
        with:
          group-key: "group-fpga"
          build-type: "fpga"

  ##########################################################################

  chipyard-spike-gemmini-run-tests:
    name: chipyard-spike-gemmini-run-tests
    needs: prepare-chipyard-accels # technically doesn't depend on RTL but should be after the build.sh for Gemmini
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Build Gemmini FireMarshal
        run: |
          conda activate ${{ env.conda-env-name-no-time }}-$(date --date "${{ env.workflow-timestamp }}" +%Y%m%d)
          cd ${{ github.workspace }} && ./scripts/init-submodules-no-riscv-tools.sh
          cd ${{ github.workspace }} && source ./scripts/fix-open-files.sh
          git submodule update --init software/firemarshal && cd software/firemarshal && ./init-submodules.sh
          cd ${{ github.workspace }}/generators/gemmini/software && ${{ github.workspace }}/software/firemarshal/marshal -v -d build gemmini-smoke.json
      - name: Running Gemmini FireMarshal smoke test
        run: |
          conda activate ${{ env.conda-env-name-no-time }}-$(date --date "${{ env.workflow-timestamp }}" +%Y%m%d)
          cd ${{ github.workspace }}/generators/gemmini/software && ${{ github.workspace }}/software/firemarshal/marshal -v -d launch -s gemmini-smoke.json

  chipyard-rocket-run-tests:
    name: chipyard-rocket-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-rocket"

  chipyard-prefetchers-run-tests:
    name: chipyard-prefetchers-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-prefetchers"

  chipyard-hetero-run-tests:
    name: chipyard-hetero-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-hetero"

  chipyard-boomv3-run-tests:
    name: chipyard-boomv3-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-boomv3"

  chipyard-boomv4-run-tests:
    name: chipyard-boomv4-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-boomv4"

  chipyard-shuttle-run-tests:
    name: chipyard-shuttle-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-shuttle"

  chipyard-cva6-run-tests:
    name: chipyard-cva6-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-cva6"

  chipyard-ibex-run-tests:
    name: chipyard-ibex-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-ibex"

  chipyard-vexiiriscv-run-tests:
    name: chipyard-vexiiriscv-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-vexiiriscv"

  chipyard-sodor-run-tests:
    name: chipyard-sodor-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-sodor"

  chipyard-spike-run-tests:
    name: chipyard-spike-run-tests
    needs: prepare-chipyard-cores
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-cores"
          project-key: "chipyard-spike"

  chipyard-dmirocket-run-tests:
    name: chipyard-dmirocket-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-dmirocket"

  chipyard-dmiboomv3-run-tests:
    name: chipyard-dmiboomv3-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-dmiboomv3"

  chipyard-dmiboomv4-run-tests:
    name: chipyard-dmiboomv4-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-dmiboomv4"

  chipyard-spiflashwrite-run-tests:
    name: chipyard-spiflashwrite-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
          ls -alh .
          rm -rf ${{ github.workspace }}/* || true
          rm -rf ${{ github.workspace }}/.* || true
          ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-spiflashwrite"

  chipyard-manyperipherals-run-tests:
    name: chipyard-manyperipherals-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-manyperipherals"

  chipyard-tethered-run-tests:
    name: chipyard-tethered-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-tethered"

  chipyard-symmetric-run-tests:
    name: chipyard-symmetric-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-symmetric"

  chipyard-llcchiplet-run-tests:
    name: chipyard-llcchiplet-run-tests
    needs: prepare-chipyard-peripherals
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-peripherals"
          project-key: "chipyard-llcchiplet"

  chipyard-rerocc-run-tests:
    name: chipyard-rerocc-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-rerocc"

  chipyard-rocketvector-run-tests:
    name: chipyard-rocketvector-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-rocketvector"

  chipyard-shuttlevector-run-tests:
    name: chipyard-shuttlevector-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-shuttlevector"

  chipyard-gemmini-run-tests:
    name: chipyard-gemmini-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-gemmini"

  chipyard-manymmioaccels-run-tests:
    name: chipyard-manymmioaccels-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-manymmioaccels"

  # chipyard-nvdla-run-tests:
  #   name: chipyard-nvdla-run-tests
  #   needs: prepare-chipyard-accels
  #   runs-on: as4
  #   steps:
  #     - name: Delete old checkout
  #       run: |
  #           ls -alh .
  #           rm -rf ${{ github.workspace }}/* || true
  #           rm -rf ${{ github.workspace }}/.* || true
  #           ls -alh .
  #     - name: Checkout
  #       uses: actions/checkout@v4
  #     - name: Git workaround
  #       uses: ./.github/actions/git-workaround
  #     - name: Create conda env
  #       uses: ./.github/actions/create-conda-env
  #     - name: Run tests
  #       uses: ./.github/actions/run-tests
  #       with:
  #         group-key: "group-accels"
  #         project-key: "chipyard-nvdla"

  chipyard-mempress-run-tests:
    name: chipyard-mempress-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-mempress"

  chipyard-compressacc-run-tests:
    name: chipyard-compressacc-run-tests
    needs: prepare-chipyard-accels
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-accels"
          project-key: "chipyard-compressacc"


  tracegen-boomv3-run-tests:
    name: tracegen-boomv3-run-tests
    needs: prepare-chipyard-tracegen
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-tracegen"
          project-key: "tracegen-boomv3"

  tracegen-boomv4-run-tests:
    name: tracegen-boomv4-run-tests
    needs: prepare-chipyard-tracegen
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-tracegen"
          project-key: "tracegen-boomv4"

  tracegen-run-tests:
    name: tracegen-run-tests
    needs: prepare-chipyard-tracegen
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-tracegen"
          project-key: "tracegen"

  icenet-run-tests:
    name: icenet-run-tests
    needs: prepare-chipyard-other
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-other"
          project-key: "icenet"

  testchipip-run-tests:
    name: testchipip-run-tests
    needs: prepare-chipyard-other
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-other"
          project-key: "testchipip"

  rocketchip-run-tests:
    name: rocketchip-run-tests
    needs: prepare-chipyard-other
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run amba tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-other"
          project-key: "rocketchip-amba"
      # Below tests segfault with verilator, work fine in VCS
      # - name: Run tlsimple tests
      #   uses: ./.github/actions/run-tests
      #   with:
      #     group-key: "group-other"
      #     project-key: "rocketchip-tlsimple"
      # - name: Run tlwidth tests
      #   uses: ./.github/actions/run-tests
      #   with:
      #     group-key: "group-other"
      #     project-key: "rocketchip-tlwidth"
      # - name: Run tlxbar tests
      #   uses: ./.github/actions/run-tests
      #   with:
      #     group-key: "group-other"
      #     project-key: "rocketchip-tlxbar"

  constellation-run-tests:
    name: constellation-run-tests
    needs: prepare-chipyard-other
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-other"
          project-key: "constellation"

  chipyard-constellation-run-tests:
    name: chipyard-constellation-run-tests
    needs: prepare-chipyard-constellation
    runs-on: as4
    steps:
      - name: Delete old checkout
        run: |
            ls -alh .
            rm -rf ${{ github.workspace }}/* || true
            rm -rf ${{ github.workspace }}/.* || true
            ls -alh .
      - name: Checkout
        uses: actions/checkout@v4
      - name: Git workaround
        uses: ./.github/actions/git-workaround
      - name: Create conda env
        uses: ./.github/actions/create-conda-env
      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          group-key: "group-constellation"
          project-key: "chipyard-constellation"

  # Sentinel job to simplify how we specify which checks need to pass in branch
  # protection and in Mergify
  #
  # When adding new top level jobs, please add them to `needs` below
  all_tests_passed:
    name: "all tests passed"
    needs: [commit-on-master-check,
            documentation-check,
            chipyard-rocket-run-tests,
            chipyard-hetero-run-tests,
            chipyard-boomv3-run-tests,
            chipyard-boomv4-run-tests,
            chipyard-shuttle-run-tests,
            chipyard-cva6-run-tests,
            chipyard-ibex-run-tests,
            chipyard-vexiiriscv-run-tests,
            chipyard-sodor-run-tests,
            chipyard-dmiboomv3-run-tests,
            chipyard-dmiboomv4-run-tests,
            chipyard-dmirocket-run-tests,
            chipyard-spiflashwrite-run-tests,
            chipyard-manyperipherals-run-tests,
            chipyard-tethered-run-tests,
            chipyard-symmetric-run-tests,
            chipyard-llcchiplet-run-tests,
            chipyard-rerocc-run-tests,
            chipyard-rocketvector-run-tests,
            chipyard-shuttlevector-run-tests,
            chipyard-gemmini-run-tests,
            chipyard-manymmioaccels-run-tests, # chipyard-nvdla-run-tests,
            chipyard-prefetchers-run-tests,
            chipyard-mempress-run-tests,
            chipyard-compressacc-run-tests,
            chipyard-constellation-run-tests,
            tracegen-boomv3-run-tests,
            tracegen-boomv4-run-tests,
            tracegen-run-tests,
            icenet-run-tests,
            testchipip-run-tests,
            rocketchip-run-tests,
            constellation-run-tests,
            prepare-chipyard-fpga]
    runs-on: ubuntu-latest
    steps:
      - run: echo Success!