build.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. name: Build, Lint & Coverage
  2. on:
  3. push:
  4. branches: [ "master" ]
  5. pull_request:
  6. branches: [ "master" ]
  7. env:
  8. BUILD_TYPE: Release
  9. jobs:
  10. # Linting job with MegaLinter
  11. megalinter:
  12. name: MegaLinter
  13. runs-on: ubuntu-latest
  14. permissions:
  15. contents: read
  16. issues: write
  17. pull-requests: write
  18. steps:
  19. - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
  20. with:
  21. fetch-depth: 0
  22. - name: MegaLinter
  23. uses: oxsecurity/megalinter/flavors/c_cpp@v9.1.0
  24. env:
  25. VALIDATE_ALL_CODEBASE: true
  26. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  27. # Disable specific linters
  28. DISABLE_LINTERS: SPELL_CSPELL
  29. # Fail on errors (set to false if you want warnings only)
  30. DISABLE_ERRORS: false
  31. - name: Archive MegaLinter reports
  32. if: always()
  33. uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
  34. with:
  35. name: megalinter-reports
  36. path: |
  37. megalinter-reports
  38. mega-linter.log
  39. # Build, test and coverage job
  40. build-and-test:
  41. name: Build, Test & Coverage
  42. runs-on: ubuntu-latest
  43. needs: megalinter
  44. if: success() || failure()
  45. steps:
  46. - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
  47. with:
  48. fetch-depth: 0
  49. - name: Install dependencies
  50. run: |
  51. sudo apt-get update
  52. sudo apt-get install -y \
  53. libcap-dev \
  54. lcov \
  55. cpputest
  56. - name: Set up Python for gcovr
  57. uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
  58. with:
  59. python-version: '3.11'
  60. - name: Install gcovr
  61. run: pip install gcovr
  62. - name: Configure CMake
  63. run: |
  64. cmake -S ${{github.workspace}}/source \
  65. -B ${{github.workspace}}/build \
  66. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
  67. -DOpENer_PLATFORM:STRING="POSIX" \
  68. -DBUILD_SHARED_LIBS:BOOL=OFF \
  69. -DOpENer_TRACES:BOOL=OFF \
  70. -DOpENer_TESTS:BOOL=ON \
  71. -DCPPUTEST_HOME:PATH=/usr
  72. - name: Build
  73. run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
  74. - name: Test
  75. working-directory: ${{github.workspace}}/build
  76. run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
  77. - name: Generate coverage reports
  78. run: |
  79. # Generate HTML report for human viewing
  80. gcovr --html-details --output coverage-report.html
  81. # Generate Cobertura XML for tools/badges
  82. gcovr --cobertura --output coverage.xml
  83. # Generate text summary for console
  84. gcovr --print-summary > coverage-summary.txt
  85. # Print summary to console
  86. echo "Coverage Summary:"
  87. cat coverage-summary.txt
  88. - name: Upload coverage reports
  89. uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
  90. with:
  91. name: coverage-report
  92. path: |
  93. coverage-report.html
  94. coverage-report.*.html
  95. coverage.xml
  96. coverage-summary.txt
  97. - name: Create coverage summary comment
  98. if: github.event_name == 'pull_request'
  99. uses: actions/github-script@v7
  100. with:
  101. script: |
  102. const fs = require('fs');
  103. const summary = fs.readFileSync('coverage-summary.txt', 'utf8');
  104. const comment = `## 📊 Coverage Report\n\n\`\`\`\n${summary}\n\`\`\`\n\nDownload the [detailed HTML report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) from the artifacts.`;
  105. github.rest.issues.createComment({
  106. issue_number: context.issue.number,
  107. owner: context.repo.owner,
  108. repo: context.repo.repo,
  109. body: comment
  110. });
  111. - name: Generate coverage badge
  112. if: github.ref == 'refs/heads/master'
  113. run: |
  114. # Extract coverage percentage
  115. COVERAGE=$(gcovr --print-summary | grep 'lines:' | awk '{print $2}')
  116. echo "COVERAGE_PERCENTAGE=$COVERAGE" >> $GITHUB_ENV
  117. echo "Coverage: $COVERAGE"
  118. - name: Upload build artifacts
  119. uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
  120. with:
  121. name: build-artifacts
  122. path: ${{github.workspace}}/build