|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by |
| 3 | +# separate terms of service, privacy policy, and support |
| 4 | +# documentation. |
| 5 | + |
| 6 | +name: CI Coverity Scan |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [ "master", "stable", "patch-ci-coverity" ] |
| 11 | + pull_request: |
| 12 | + # The branches below must be a subset of the branches above |
| 13 | + branches: [ "**" ] |
| 14 | + schedule: |
| 15 | + - cron: '18 0 * * 4' |
| 16 | + |
| 17 | +jobs: |
| 18 | + coverity-scan: |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v5 |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: '3.13' # Specify the Python version you need |
| 32 | + |
| 33 | + - name: Download and Verify Coverity Tools |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + if [[ "${{ runner.os }}" == "Linux" ]]; then |
| 37 | + curl -X POST "https://scan.coverity.com/download/other/linux64" \ |
| 38 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}&md5=1" \ |
| 39 | + -o coverity_tool.tgz.md5 |
| 40 | + curl -X POST "https://scan.coverity.com/download/other/linux64" \ |
| 41 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}" \ |
| 42 | + -o coverity_tool.tgz |
| 43 | + md5sum -c coverity_tool.tgz.md5 |
| 44 | + elif [[ "${{ runner.os }}" == "macOS" ]]; then |
| 45 | + curl -X POST "https://scan.coverity.com/download/other/macOS" \ |
| 46 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}&md5=1" \ |
| 47 | + -o coverity_tool.dmg.md5 |
| 48 | + curl -X POST "https://scan.coverity.com/download/other/macOS" \ |
| 49 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}" \ |
| 50 | + -o coverity_tool.dmg |
| 51 | + md5 -r coverity_tool.dmg | awk '{print $1}' > coverity_tool.dmg.md5 |
| 52 | + diff coverity_tool.dmg.md5 coverity_tool.dmg.md5 |
| 53 | + elif [[ "${{ runner.os }}" == "Windows" ]]; then |
| 54 | + curl -X POST "https://scan.coverity.com/download/other/windows" \ |
| 55 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}&md5=1" \ |
| 56 | + -o coverity_tool.zip.md5 |
| 57 | + curl -X POST "https://scan.coverity.com/download/other/windows" \ |
| 58 | + -d "token=${{ secrets.COVERITY_TOKEN }}&project=${{ github.repository }}" \ |
| 59 | + -o coverity_tool.zip |
| 60 | + certutil -hashfile coverity_tool.zip MD5 |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Build and Scan Python Repository |
| 64 | + run: | |
| 65 | + cd path/to/python/repo |
| 66 | + /path/to/cov-build --dir cov-int -- python setup.py build |
| 67 | + coverity capture --dir cov-int --scm-branch ${{ github.ref }} --scm-revision ${{ github.sha }} --scm-url ${{ github.repository }} --project-dir ${{ github.workspace }} -- python setup.py build |
| 68 | +
|
| 69 | + - name: Create Metadata and Archive Results |
| 70 | + run: | |
| 71 | + echo "Name: $(git config user.name)" > README |
| 72 | + echo "Email: $(git config user.email)" >> README |
| 73 | + echo "Description: $(git log -1 --pretty=%B)" >> README |
| 74 | + echo "Submitted-by: coverity-ci-auto-submit" >> README |
| 75 | + ARCHIVE_NAME="${{ github.actor }}-${{ github.repository }}.tgz" |
| 76 | + tar -czf "$ARCHIVE_NAME" cov-int README |
| 77 | +
|
| 78 | + - name: Submit the Archive to Coverity |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + BUILD_SIZE=$(du -b "$ARCHIVE_NAME" | cut -f1) |
| 82 | + if [ "$BUILD_SIZE" -gt 500000000 ]; then |
| 83 | + # Step 1: Initialize a build |
| 84 | + curl -X POST \ |
| 85 | + -d version="1.0" \ |
| 86 | + -d project=${{ github.repository }} \ |
| 87 | + -d name=${{ github.actor }} \ |
| 88 | + -d description="Coverity scan submission" \ |
| 89 | + -d email=${{ secrets.COVERITY_EMAIL }} \ |
| 90 | + -d token=${{ secrets.COVERITY_TOKEN }} \ |
| 91 | + -d file_name="$ARCHIVE_NAME" \ |
| 92 | + "https://scan.coverity.com/projects/${{ secrets.COVERITY_PROJECT_ID }}/builds/init" \ |
| 93 | + | tee response |
| 94 | +
|
| 95 | + # Step 2: Store response data |
| 96 | + upload_url=$(jq -r '.url' response) |
| 97 | + build_id=$(jq -r '.build_id' response) |
| 98 | +
|
| 99 | + # Step 3: Upload the tarball to the Cloud |
| 100 | + curl -X PUT \ |
| 101 | + --header 'Content-Type: application/json' \ |
| 102 | + --upload-file "$ARCHIVE_NAME" \ |
| 103 | + "${upload_url}" |
| 104 | +
|
| 105 | + # Step 4: Trigger the build on Scan |
| 106 | + curl -X PUT \ |
| 107 | + -d token=${{ secrets.COVERITY_TOKEN }} \ |
| 108 | + "https://scan.coverity.com/projects/${{ secrets.COVERITY_PROJECT_ID }}/builds/${build_id}/enqueue" |
| 109 | + else |
| 110 | + # If the build size is within limits, submit directly |
| 111 | + curl -X POST -F "file=@$ARCHIVE_NAME" \ |
| 112 | + -F "description='Coverity scan submission'" \ |
| 113 | + -F "project=${{ github.repository }}" \ |
| 114 | + -F "token=${{ secrets.COVERITY_TOKEN }}" \ |
| 115 | + -F "email=${{ secrets.COVERITY_EMAIL }}" \ |
| 116 | + "https://scan.coverity.com/builds" |
| 117 | + fi |
0 commit comments