ci.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.10"
  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. - name: Check for missing migrations
  114. run: python netbox/manage.py makemigrations --check
  115. # Copy frontend-generated files into STATIC_ROOT before SVG rendering
  116. # tests read their CSS directly.
  117. - name: Collect static files
  118. run: python netbox/manage.py collectstatic --no-input
  119. - name: Run tests
  120. if: ${{ ! matrix.coverage }}
  121. run: python netbox/manage.py test netbox/ --parallel
  122. - name: Run tests with coverage
  123. if: ${{ matrix.coverage }}
  124. run: coverage run netbox/manage.py test netbox/ --parallel
  125. - name: Combine coverage data
  126. if: ${{ matrix.coverage }}
  127. run: coverage combine
  128. - name: Show coverage report
  129. if: ${{ matrix.coverage }}
  130. run: coverage report
  131. frontend:
  132. name: Frontend
  133. needs: changes
  134. if: needs.changes.result == 'success' && needs.changes.outputs.frontend == 'true'
  135. runs-on: ubuntu-latest
  136. steps:
  137. - name: Check out repo
  138. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  139. - name: Use Node.js 20.x
  140. uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
  141. with:
  142. node-version: '20.x'
  143. - name: Install Yarn Package Manager
  144. run: npm install -g yarn
  145. - name: Setup Node.js with Yarn Caching
  146. uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
  147. with:
  148. node-version: '20.x'
  149. cache: yarn
  150. cache-dependency-path: netbox/project-static/yarn.lock
  151. - name: Install Frontend Dependencies
  152. run: yarn --cwd netbox/project-static
  153. - name: Validate TypeScript and run ESLint
  154. run: yarn --cwd netbox/project-static validate
  155. - name: Validate formatting
  156. run: yarn --cwd netbox/project-static validate:formatting
  157. - name: Validate Static Asset Integrity
  158. run: scripts/verify-bundles.sh
  159. docs:
  160. name: Documentation
  161. needs: changes
  162. if: needs.changes.result == 'success' && needs.changes.outputs.docs == 'true'
  163. runs-on: ubuntu-latest
  164. steps:
  165. - name: Check out repo
  166. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  167. - name: Set up Python 3.12
  168. uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
  169. with:
  170. python-version: '3.12'
  171. - name: Install dependencies
  172. run: |
  173. python -m pip install --upgrade pip
  174. pip install -r requirements.txt
  175. - name: Build documentation
  176. run: zensical build