File: coverage.yml

package info (click to toggle)
verilator 5.042-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 61,876 kB
  • sloc: cpp: 149,079; python: 21,943; ansic: 10,559; yacc: 6,019; lex: 1,971; makefile: 1,384; sh: 603; perl: 302; fortran: 22
file content (213 lines) | stat: -rw-r--r-- 7,942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
# DESCRIPTION: Github actions config
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0

name: Code coverage

on:
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * 0'  # weekly
  pull_request:
    types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
  contents: read

defaults:
  run:
    shell: bash

concurrency:
  # At most 1 job per branch. Auto cancel all but scheduled jobs
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name != 'schedule' }}

jobs:

  build:
    name: Build
    # Only run scheduled jobs if explicitly enabled for that repo (e.g.: not on forks)
    # Only run pull request jobs if labelled as needing an coverage run
    # Always run workflow dispatch jobs
    if: |
      (github.event_name == 'schedule'
        && vars.ENABLE_SCHEDULED_JOBS == 'true') ||
      (github.event_name == 'pull_request'
        && contains(github.event.pull_request.labels.*.name, 'pr: dev-coverage')) ||
      (github.event_name == 'workflow_dispatch')
    uses: ./.github/workflows/reusable-build.yml
    with:
      # For pull requests, build the head of the pull request branch, not the
      # merge commit, otherwise patch coverage would include the changes
      # between the root of the pull request and the target branch
      sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
      os: ubuntu-24.04
      os-name: linux
      cc: gcc
      dev-asan: 0
      dev-gcov: 1

  test:
    name: Test | ${{ matrix.test }}${{ matrix.num }}
    needs: build
    uses: ./.github/workflows/reusable-test.yml
    with:
      archive: ${{ needs.build.outputs.archive }}
      os: ubuntu-24.04
      cc: gcc
      reloc: 0
      suite: ${{ matrix.test }}${{ matrix.num }}
      dev-gcov: 1
    strategy:
      fail-fast: false
      matrix:
        test: [coverage-vlt-, coverage-vltmt-]
        num: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        include:
          - {test: coverage-dist, num: ''}

  publish-codecov:
    name: Publish results to codecov.io
    needs: test
    if: ${{ contains(needs.*.result, 'success') && !cancelled() }}
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Download code coverage data
        uses: actions/download-artifact@v6
        with:
          pattern: code-coverage-*
          path: obj_coverage
          merge-multiple: true

      - name: List files
        id: list-files
        run: |
          ls -lsha obj_coverage
          find obj_coverage -type f | paste -sd, | sed "s/^/files=/" >> "$GITHUB_OUTPUT"

      - name: Upload to codecov.io
        uses: codecov/codecov-action@v5
        with:
          disable_file_fixes: true
          disable_search: true
          fail_ci_if_error: true
          files: ${{ steps.list-files.outputs.files }}
          plugins: noop
          token: ${{ secrets.CODECOV_TOKEN }}
          verbose: true

  prepare-report:
    name: Prepare HTML report
    needs: [build, test]
    if: ${{ contains(needs.*.result, 'success') && !cancelled() }}
    runs-on: ubuntu-24.04
    steps:
      - name: Install dependencies
        run: |
          echo 'set man-db/auto-update false' | sudo debconf-communicate >/dev/null
          sudo dpkg-reconfigure man-db
          sudo apt install lcov

      - name: Download repository archive
        uses: actions/download-artifact@v6
        with:
          name: ${{ needs.build.outputs.archive }}
          path: ${{ github.workspace }}

      - name: Unpack repository archive
        run: |
          tar -x -z -f ${{ needs.build.outputs.archive }}
          ls -lsha

      - name: Download code coverage data
        uses: actions/download-artifact@v6
        with:
          pattern: code-coverage-*
          path: repo/obj_coverage
          merge-multiple: true

      - name: Create report
        working-directory: repo
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          ls -lsha obj_coverage
          # Combine reports from test jobs
          nodist/fastcov.py -C obj_coverage/verilator-*.info --lcov -o obj_coverage/verilator.info
          # For a PR, report patch coverage against the merge-base between the head of the PR and the target branch
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            COVERAGE_BASE=$(git rev-parse --short $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}))
            make coverage-report COVERAGE_BASE=${COVERAGE_BASE} |& tee ${{ github.workspace }}/make-coverage-report.log
          else
            make coverage-report
          fi
          # Remove data files
          rm -f obj_coverage/verilator*.info
          # Some extra work for PRs only
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # Save PR number in report
            echo ${{ github.event.number }} > obj_coverage/pr-number.txt
            # Generate notification comment content
            mkdir -p notification
            echo ${{ github.event.number }} > notification/pr-number.txt
            NUM=$(gh run view ${{ github.run_id }} --json number --jq ".number")
            URL=$(gh run view ${{ github.run_id }} --json url    --jq ".url")
            echo "Patch coverage from PR workflow [#$NUM]($URL) (code coverage of lines changed relative to ${COVERAGE_BASE}):" > notification/body.txt
            if [[ ! -f obj_coverage/empty-patch ]]; then
              echo "<pre>" >> notification/body.txt
              grep -E "(lines|branches)\.*:" ${{ github.workspace }}/make-coverage-report.log | sed "s/\.*:/:/" >> notification/body.txt || true
              echo "</pre>" >> notification/body.txt
              echo "Report: [${{ github.run_id }}](https://${{ github.repository_owner }}.github.io/verilator/coverage-reports/${{ github.run_id }}/index.html)" >> notification/body.txt
            else
              echo "Patch contains no code changes" >> notification/body.txt
            fi
            cat notification/body.txt
          fi

      - name: Upload report
        uses: actions/upload-artifact@v5
        with:
          path: repo/obj_coverage
          name: coverage-report

      - name: Upload notification
        if: ${{ github.event_name == 'pull_request' }}
        uses: actions/upload-artifact@v5
        with:
          path: repo/notification
          name: coverage-pr-notification

  # Create GitHub issue for failed scheduled jobs
  # This should always be the last job (we want an issue if anything breaks)
  create-issue:
    name: Create issue on failure
    needs: [publish-codecov, prepare-report]
    if: ${{ github.event_name == 'schedule' && github.repository == 'verilator/verilator' && github.run_attempt == 1 && failure() && !cancelled() }}
    runs-on: ubuntu-24.04
    steps:
      # Creating issues requires elevated privilege
      - name: Generate access token
        id: generate-token
        uses: actions/create-github-app-token@v2.1.4
        with:
          app-id: ${{ vars.VERILATOR_CI_ID }}
          private-key: ${{ secrets.VERILATOR_CI_KEY }}
          owner: verilator
          repositories: verilator
          permission-issues: write
      - name: Create issue
        env:
          GH_TOKEN: ${{ steps.generate-token.outputs.token }}
        run: |-
          echo "This issue was created automatically by the GitHub Actions CI due to the failure of a scheduled Code coverage run." >> body.txt
          echo "" >> body.txt
          echo "Workflow status: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> body.txt
          gh issue --repo ${{ github.repository }} create \
            --title "Code coverage run #${{ github.run_number }} Failed" \
            --body-file body.txt \
            --label new \
            --assignee gezalore,wsnyder