test.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. name: Run tests
  2. on: [push]
  3. env:
  4. DOCKER_IMAGE: archivebox-ci
  5. PYTHONIOENCODING: utf-8
  6. PYTHONLEGACYWINDOWSSTDIO: utf-8
  7. USE_COLOR: False
  8. jobs:
  9. python_tests:
  10. runs-on: ${{ matrix.os }}
  11. strategy:
  12. matrix:
  13. os: [ubuntu-20.04, macos-latest, windows-latest]
  14. python: [3.7]
  15. steps:
  16. - uses: actions/checkout@v2
  17. with:
  18. submodules: true
  19. fetch-depth: 1
  20. ### Setup Python & JS Languages
  21. - name: Set up Python ${{ matrix.python }}
  22. uses: actions/setup-python@v1
  23. with:
  24. python-version: ${{ matrix.python }}
  25. architecture: x64
  26. - name: Set up Node JS 14.7.0
  27. uses: actions/setup-node@v1
  28. with:
  29. node-version: 14.7.0
  30. ### Install Python & JS Dependencies
  31. - name: Get pip cache dir
  32. id: pip-cache
  33. run: |
  34. echo "::set-output name=dir::$(pip cache dir)"
  35. - name: Cache pip
  36. uses: actions/cache@v2
  37. id: cache-pip
  38. with:
  39. path: ${{ steps.pip-cache.outputs.dir }}
  40. key: ${{ runner.os }}-${{ matrix.python }}-venv-${{ hashFiles('setup.py') }}
  41. restore-keys: |
  42. ${{ runner.os }}-${{ matrix.python }}-venv-
  43. - name: Install pip dependencies
  44. run: |
  45. python -m pip install --upgrade pip setuptools wheel pytest bottle
  46. ./bin/build_pip.sh
  47. python -m pip install .
  48. - name: Get npm cache dir
  49. id: npm-cache
  50. run: |
  51. echo "::set-output name=dir::$GITHUB_WORKSPACE/node_modules"
  52. - name: Cache npm
  53. uses: actions/cache@v2
  54. id: cache-npm
  55. with:
  56. path: ${{ steps.npm-cache.outputs.dir }}
  57. key: ${{ runner.os }}-node_modules-${{ hashFiles('package-lock.json') }}
  58. restore-keys: |
  59. ${{ runner.os }}-node_modules
  60. - name: Install npm requirements
  61. run: |
  62. npm install
  63. echo "SINGLEFILE_BINARY=$GITHUB_WORKSPACE/node_modules/.bin/single-file" >> $GITHUB_ENV
  64. echo "READABILITY_BINARY=$GITHUB_WORKSPACE/node_modules/.bin/readability-extractor" >> $GITHUB_ENV
  65. echo "MERCURY_BINARY=$GITHUB_WORKSPACE/node_modules/.bin/mercury-parser" >> $GITHUB_ENV
  66. ### Run the tests
  67. - name: Directory listing for debugging
  68. run: |
  69. pwd
  70. ls
  71. - name: Archivebox version
  72. run: |
  73. archivebox version
  74. - name: Test built package with pytest
  75. # TODO: remove this exception for windows once we get tests passing on that platform
  76. if: ${{ !contains(matrix.os, 'windows') }}
  77. run: |
  78. python -m pytest -s --ignore=archivebox/vendor
  79. docker_tests:
  80. runs-on: ubuntu-latest
  81. steps:
  82. - uses: actions/checkout@v2
  83. with:
  84. submodules: true
  85. fetch-depth: 1
  86. # TODO: as of 2020-11 this helper layer broke, upgrade and re-enable this once it's usable again
  87. # - uses: satackey/[email protected]
  88. - name: Build image
  89. run: |
  90. docker build . -t "$DOCKER_IMAGE"
  91. - name: Init data dir
  92. run: |
  93. mkdir "${{ github.workspace }}/data"
  94. docker run -v "${{ github.workspace }}/data":/data "$DOCKER_IMAGE" init
  95. - name: Run test server
  96. run: |
  97. sudo bash -c 'echo "127.0.0.1 www.test-nginx-1.local www.test-nginx-2.local" >> /etc/hosts'
  98. docker run --name www-nginx -p 80:80 -d nginx
  99. - name: Add link
  100. run: |
  101. docker run -v "$PWD"/data:/data --network host "$DOCKER_IMAGE" add http://www.test-nginx-1.local
  102. - name: Add stdin link
  103. run: |
  104. echo "http://www.test-nginx-2.local" | docker run -i --network host -v "$PWD"/data:/data "$DOCKER_IMAGE" add
  105. - name: List links
  106. run: |
  107. docker run -v "$PWD"/data:/data "$DOCKER_IMAGE" list | grep -q "www.test-nginx-1.local" || { echo "The site 1 isn't in the list"; exit 1; }
  108. docker run -v "$PWD"/data:/data "$DOCKER_IMAGE" list | grep -q "www.test-nginx-2.local" || { echo "The site 2 isn't in the list"; exit 1; }
  109. - name: Start docker-compose stack
  110. run: |
  111. docker-compose run archivebox init
  112. docker-compose up -d
  113. sleep 5
  114. curl --silent --location 'http://127.0.0.1:8000' | grep 'ArchiveBox'
  115. curl --silent --location 'http://127.0.0.1:8000/static/admin/js/jquery.init.js' | grep 'window.django'
  116. - name: Check added urls show up in index
  117. run: |
  118. docker-compose run archivebox add 'http://example.com/#test_docker' --index-only
  119. curl --silent --location 'http://127.0.0.1:8000' | grep 'http://example.com/#test_docker'
  120. docker-compose down || true