ci.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ---
  2. name: CI
  3. on:
  4. push:
  5. branches:
  6. - main
  7. - feature
  8. paths-ignore:
  9. - '.github/ISSUE_TEMPLATE/**'
  10. - '.github/PULL_REQUEST_TEMPLATE.md'
  11. - 'contrib/**'
  12. - 'netbox/translations/**'
  13. pull_request:
  14. paths-ignore:
  15. - '.github/ISSUE_TEMPLATE/**'
  16. - '.github/PULL_REQUEST_TEMPLATE.md'
  17. - 'contrib/**'
  18. - 'netbox/translations/**'
  19. permissions:
  20. contents: read
  21. pull-requests: read
  22. # Add concurrency group to control job running
  23. concurrency:
  24. group: ${{ github.event_name }}-${{ github.ref }}-${{ github.actor }}
  25. cancel-in-progress: true
  26. jobs:
  27. # Detect which areas of the codebase changed so downstream jobs can be skipped
  28. # when their inputs haven't changed. Jobs that don't match any filter are shown
  29. # as "skipped" in GitHub's check list, which satisfies required-status-checks.
  30. changes:
  31. name: Detect changed files
  32. runs-on: ubuntu-latest
  33. outputs:
  34. python: ${{ steps.filter.outputs.python }}
  35. frontend: ${{ steps.filter.outputs.frontend }}
  36. docs: ${{ steps.filter.outputs.docs }}
  37. steps:
  38. - name: Check out repo
  39. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  40. - name: Detect changed files
  41. uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
  42. id: filter
  43. with:
  44. filters: |
  45. python:
  46. - 'netbox/**/*.py'
  47. - 'requirements*.txt'
  48. - 'pyproject.toml'
  49. frontend:
  50. - 'netbox/project-static/**'
  51. docs:
  52. - 'docs/**'
  53. - 'mkdocs.yml'
  54. lint:
  55. name: Lint (Python)
  56. needs: changes
  57. if: needs.changes.result == 'success' && needs.changes.outputs.python == 'true'
  58. runs-on: ubuntu-latest
  59. steps:
  60. - name: Check out repo
  61. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  62. - name: Check Python linting & PEP8 compliance
  63. uses: astral-sh/ruff-action@0ce1b0bf8b818ef400413f810f8a11cdbda0034b # v4.0.0
  64. with:
  65. version: "0.15.20"
  66. args: "check --output-format=github"
  67. src: "netbox/"
  68. test:
  69. name: >-
  70. Tests (Python ${{ matrix.python-version }}${{ matrix.coverage && ', coverage' || '' }})
  71. needs: changes
  72. if: needs.changes.result == 'success' && needs.changes.outputs.python == 'true'
  73. runs-on: ubuntu-latest
  74. env:
  75. NETBOX_CONFIGURATION: netbox.configuration_testing
  76. strategy:
  77. matrix:
  78. python-version: ['3.12', '3.13', '3.14']
  79. include:
  80. - coverage: false
  81. # Run coverage only once, using the Python 3.14 job.
  82. - python-version: '3.14'
  83. coverage: true
  84. services:
  85. redis:
  86. image: redis
  87. ports:
  88. - 6379:6379
  89. postgres:
  90. image: postgres
  91. env:
  92. POSTGRES_USER: netbox
  93. POSTGRES_PASSWORD: netbox
  94. options: >-
  95. --health-cmd pg_isready
  96. --health-interval 10s
  97. --health-timeout 5s
  98. --health-retries 5
  99. ports:
  100. - 5432:5432
  101. steps:
  102. - name: Check out repo
  103. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  104. - name: Set up Python ${{ matrix.python-version }}
  105. uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
  106. with:
  107. python-version: ${{ matrix.python-version }}
  108. - name: Install dependencies
  109. run: |
  110. python -m pip install --upgrade pip
  111. pip install -r requirements.txt
  112. pip install coverage tblib
  113. # dulwich is the optional 'git' extra, so it is absent from requirements.txt.
  114. # The Git data backend tests mock dulwich.porcelain.clone and only need the
  115. # module to be importable; without it they skip silently.
  116. pip install dulwich
  117. - name: Check for missing migrations
  118. run: python netbox/manage.py makemigrations --check
  119. # Copy frontend-generated files into STATIC_ROOT before SVG rendering
  120. # tests read their CSS directly.
  121. - name: Collect static files
  122. run: python netbox/manage.py collectstatic --no-input
  123. - name: Run tests
  124. if: ${{ ! matrix.coverage }}
  125. run: python netbox/manage.py test netbox/ --parallel
  126. - name: Run tests with coverage
  127. if: ${{ matrix.coverage }}
  128. run: coverage run netbox/manage.py test netbox/ --parallel
  129. - name: Combine coverage data
  130. if: ${{ matrix.coverage }}
  131. run: coverage combine
  132. - name: Show coverage report
  133. if: ${{ matrix.coverage }}
  134. run: coverage report
  135. frontend:
  136. name: Frontend
  137. needs: changes
  138. if: needs.changes.result == 'success' && needs.changes.outputs.frontend == 'true'
  139. runs-on: ubuntu-latest
  140. steps:
  141. - name: Check out repo
  142. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  143. - name: Use Node.js 20.x
  144. uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
  145. with:
  146. node-version: '20.x'
  147. - name: Install Yarn Package Manager
  148. run: npm install -g yarn
  149. - name: Setup Node.js with Yarn Caching
  150. uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
  151. with:
  152. node-version: '20.x'
  153. cache: yarn
  154. cache-dependency-path: netbox/project-static/yarn.lock
  155. - name: Install Frontend Dependencies
  156. run: yarn --cwd netbox/project-static
  157. - name: Validate TypeScript and run ESLint
  158. run: yarn --cwd netbox/project-static validate
  159. - name: Validate formatting
  160. run: yarn --cwd netbox/project-static validate:formatting
  161. - name: Validate Static Asset Integrity
  162. run: scripts/verify-bundles.sh
  163. docs:
  164. name: Documentation
  165. needs: changes
  166. if: needs.changes.result == 'success' && needs.changes.outputs.docs == 'true'
  167. runs-on: ubuntu-latest
  168. steps:
  169. - name: Check out repo
  170. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  171. - name: Set up Python 3.12
  172. uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
  173. with:
  174. python-version: '3.12'
  175. - name: Install dependencies
  176. run: |
  177. python -m pip install --upgrade pip
  178. pip install -r requirements.txt
  179. - name: Build documentation
  180. run: zensical build