ci.yml 5.9 KB

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