pytest.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. name: Test
  2. on:
  3. push:
  4. pull_request:
  5. schedule:
  6. - cron: '0 0 * * *'
  7. workflow_dispatch:
  8. inputs:
  9. pytest_tests:
  10. description: 'Run only specified suites or test modules delimited by space, for example "basic/basic_test.py replication"'
  11. required: false
  12. default: false
  13. debug_enabled:
  14. description: 'Set to "true" to enable debugging with tmate (https://github.com/marketplace/actions/debugging-with-tmate)'
  15. required: false
  16. default: false
  17. concurrency:
  18. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  19. cancel-in-progress: ${{ github.event_name == 'pull_request' }}
  20. permissions:
  21. actions: read
  22. packages: read
  23. contents: read
  24. jobs:
  25. build:
  26. name: Build
  27. runs-on: ubuntu-22.04
  28. timeout-minutes: 30
  29. container:
  30. image: quay.io/389ds/ci-images:test
  31. outputs:
  32. matrix: ${{ steps.set-matrix.outputs.matrix }}
  33. steps:
  34. - name: Checkout
  35. uses: actions/checkout@v6
  36. - name: Add GITHUB_WORKSPACE as a safe directory
  37. run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
  38. - name: Get a list of all test suites
  39. id: set-matrix
  40. run: echo "matrix=$(python3 .github/scripts/generate_matrix.py ${{ github.event.inputs.pytest_tests }})" >>$GITHUB_OUTPUT
  41. - name: Build RPMs
  42. run: SKIP_AUDIT_CI=1 make -f rpm.mk dist-bz2 rpms
  43. - name: Tar build artifacts
  44. run: tar -cvf dist.tar dist/
  45. - name: Upload RPMs
  46. uses: actions/upload-artifact@v7
  47. with:
  48. name: rpms
  49. path: dist.tar
  50. test:
  51. name: BDB Test
  52. runs-on: ubuntu-22.04
  53. timeout-minutes: 90
  54. needs: build
  55. strategy:
  56. fail-fast: false
  57. matrix: ${{ fromJson(needs.build.outputs.matrix) }}
  58. steps:
  59. - name: Checkout
  60. uses: actions/checkout@v6
  61. - name: Setup tmate session
  62. uses: mxschmitt/action-tmate@v3
  63. with:
  64. limit-access-to-actor: true
  65. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  66. - name: Install dependencies
  67. run: |
  68. sudo apt update -y
  69. sudo apt install -y docker.io containerd runc
  70. sudo cp .github/daemon.json /etc/docker/daemon.json
  71. sudo systemctl unmask docker
  72. sudo systemctl start docker
  73. - name: Free disk space
  74. run: |
  75. echo "Disk space before cleanup:"
  76. df -h
  77. sudo rm -rf /usr/local/.ghcup
  78. sudo rm -rf /opt/hostedtoolcache/CodeQL
  79. sudo rm -rf /usr/local/lib/android/sdk/ndk
  80. sudo rm -rf /usr/share/dotnet
  81. sudo rm -rf /opt/ghc
  82. sudo rm -rf /usr/local/share/boost
  83. sudo docker image prune --all --force
  84. sudo apt-get clean
  85. echo "Disk space after cleanup:"
  86. df -h
  87. - name: Download RPMs
  88. uses: actions/download-artifact@v8
  89. with:
  90. name: rpms
  91. - name: Extract RPMs
  92. run: tar xvf dist.tar
  93. - name: Run pytest in a container
  94. run: |
  95. set -x
  96. CID=$(sudo docker run -d -h server.example.com --ulimit core=-1 --cap-add=SYS_PTRACE --privileged --rm --shm-size=4gb -v ${PWD}:/workspace quay.io/389ds/ci-images:test)
  97. until sudo docker exec $CID sh -c "systemctl is-system-running"
  98. do
  99. echo "Waiting for container to be ready..."
  100. done
  101. sudo docker exec $CID sh -c "dnf install -y dist/rpms/*rpm"
  102. export PASSWD=$(openssl rand -base64 32)
  103. sudo docker exec $CID sh -c "echo \"${PASSWD}\" | passwd --stdin root"
  104. sudo docker exec $CID sh -c "systemctl start dbus.service"
  105. sudo docker exec $CID sh -c "systemctl enable --now cockpit.socket"
  106. sudo docker exec $CID sh -c "mkdir -p /workspace/assets/cores && chmod 777 /workspace{,/assets{,/cores}}"
  107. sudo docker exec $CID sh -c "echo '/workspace/assets/cores/core.%e.%P' > /proc/sys/kernel/core_pattern"
  108. if sudo docker exec $CID sh -c "test -f /usr/lib64/dirsrv/librobdb.so"
  109. then
  110. echo "Tests skipped because read-only Berkeley Database is installed." > pytest.html
  111. echo "<?xml version="1.0" encoding="utf-8"?>'Tests skipped because read-only Berkeley Database is installed.'" > pytest.xml
  112. else
  113. sudo docker exec -e WEBUI=1 -e NSSLAPD_DB_LIB=bdb -e DEBUG=pw:api -e PASSWD="${PASSWD}" -e GSSAPI_ACK=1 $CID py.test --suppress-no-test-exit-code -m "not flaky" --junit-xml=pytest.xml --html=pytest.html --browser=firefox --browser=chromium -v dirsrvtests/tests/suites/${{ matrix.suite }}
  114. fi
  115. - name: Make the results file readable by all
  116. if: always()
  117. run: |
  118. sudo chmod -f -v -R a+r pytest.*ml assets
  119. sudo chmod -f -v a+x assets
  120. - name: Sanitize filename
  121. if: always()
  122. run: echo "PYTEST_SUITE=$(echo ${{ matrix.suite }} | sed -e 's#\/#-#g')" >> $GITHUB_ENV
  123. - name: Upload pytest test results
  124. if: always()
  125. uses: actions/upload-artifact@v7
  126. with:
  127. name: pytest-${{ env.PYTEST_SUITE }}
  128. path: |
  129. pytest.xml
  130. pytest.html
  131. assets