Create unit testing infra (#882) #2243
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: check | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
env: | |
# This is used in ci_proxy, do not remove. It is necessary so that | |
# we can test against non-production data | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
jobs: | |
lint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- uses: ./.github/actions/node_modules | |
- run: npx eslint . | |
working-directory: react | |
build-and-push-common-image: | |
runs-on: ubuntu-22.04 | |
outputs: | |
image: ${{ steps.image.outputs.image }} | |
permissions: | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: ./.github/actions/docker_image | |
with: | |
dockerfile: Dockerfile | |
token: ${{ secrets.GITHUB_TOKEN }} | |
id: image | |
build-and-push-e2e-image: | |
runs-on: ubuntu-22.04 | |
outputs: | |
image: ${{ steps.image.outputs.image }} | |
permissions: | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: ./.github/actions/docker_image | |
with: | |
dockerfile: react/test/Dockerfile | |
token: ${{ secrets.GITHUB_TOKEN }} | |
id: image | |
lint-python: | |
runs-on: ubuntu-22.04 | |
needs: build-and-push-common-image | |
container: | |
image: ${{ needs.build-and-push-common-image.outputs.image }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/python_environment | |
- name: Lint with pylint | |
run: python -m pylint --prefer-stubs=true urbanstats tests | |
- name: Check black | |
run: | | |
python -m isort urbanstats tests | |
python -m black urbanstats tests | |
# allow all directories. This is needed because git complains about git repositories outside the user directory | |
git config --global --add safe.directory '*' | |
# check if there are any changes | |
# if there are, print the diff and exit with an error | |
# this is needed because isort and black disagree on the formatting of some files, so we run both and check | |
# if there's a difference | |
bash -c '[ $(git status --porcelain --untracked-files=no | wc -c) -eq 0 ] || (git status; git diff; exit 1)' | |
test-python: | |
runs-on: ubuntu-22.04 | |
needs: build-and-push-common-image | |
container: | |
image: ${{ needs.build-and-push-common-image.outputs.image }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/python_environment | |
- name: Test python code | |
run: python -m pytest tests | |
build-frontend: | |
runs-on: ubuntu-22.04 | |
needs: build-and-push-common-image | |
container: | |
image: ${{ needs.build-and-push-common-image.outputs.image }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/python_environment | |
- uses: ./.github/actions/node_modules | |
- run: python3 create_website.py react/test/density-db --no-data --no-geo --no-juxta --mode=ci | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-build | |
path: react/test/density-db | |
list-e2e-tests: | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: set-matrix | |
run: echo "matrix=$(find . -name '*_test.ts' | jq -R -s -c 'gsub("\\./"; "") | gsub("\\.ts"; "") | split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
working-directory: react/test | |
run-e2e-tests: | |
runs-on: ubuntu-22.04 | |
needs: [build-and-push-e2e-image, build-frontend, list-e2e-tests] | |
container: | |
image: ${{ needs.build-and-push-e2e-image.outputs.image }} | |
strategy: | |
fail-fast: false | |
matrix: | |
test-file: ${{ fromJson(needs.list-e2e-tests.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/python_environment | |
- uses: ./.github/actions/node_modules | |
- uses: actions/download-artifact@v4 | |
with: | |
name: frontend-build | |
path: react/test/density-db | |
- name: Run tests | |
run: | | |
npm run test:e2e -- \ | |
--proxy=true \ | |
--browser=chromium \ | |
--test=test/${{ matrix.test-file }}.ts \ | |
--parallel=1 \ | |
--headless=true \ | |
--compare=true \ | |
--time-limit-seconds=300 | |
working-directory: react | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/upload-artifact@v4 | |
if: "!cancelled()" | |
with: | |
name: delta-${{ matrix.test-file }} | |
path: react/delta | |
- uses: actions/upload-artifact@v4 | |
if: "!cancelled()" | |
with: | |
name: changed_screenshots-${{ matrix.test-file }} | |
path: react/changed_screenshots | |
merge-screenshots: | |
runs-on: ubuntu-22.04 | |
needs: [run-e2e-tests] | |
if: "!cancelled()" | |
steps: | |
- uses: actions/upload-artifact/merge@v4 | |
with: | |
name: delta | |
pattern: "delta-*" | |
continue-on-error: true | |
- uses: actions/upload-artifact/merge@v4 | |
with: | |
name: changed_screenshots | |
pattern: "changed_screenshots-*" | |
continue-on-error: true | |
- uses: actions/upload-artifact/merge@v4 | |
with: | |
name: combined | |
pattern: "{delta,changed_screenshots}" | |
separate-directories: true | |
continue-on-error: true | |
run-unit-tests: | |
runs-on: ubuntu-22.04 | |
needs: [build-and-push-common-image, build-frontend] | |
container: | |
image: ${{ needs.build-and-push-common-image.outputs.image }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/node_modules | |
- uses: actions/download-artifact@v4 | |
with: | |
name: frontend-build | |
path: react/test/density-db | |
- name: Run tests | |
run: | | |
npm run test:unit -- \ | |
--proxy=true | |
working-directory: react | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |