ci.yml 5.8 KB

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