From a4d2fbadfa9d6dfb08cbee567db80e645f3007e0 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Sun, 10 Sep 2023 23:21:33 +0200 Subject: [PATCH] feat(ci): check that demo.py works (#1048) * feat(ci): check that demo.py works * feat(demo.py): add headless flag * fix(GHA): run demo.py with headless mode --- .github/workflows/run-tests.yaml | 216 +++++++++++++++++++------------ demo.py | 23 ++-- 2 files changed, 145 insertions(+), 94 deletions(-) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 34fbabab8..ac4bb4793 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -1,4 +1,4 @@ -# This workflow will run all tests as well as pre-commit +# This workflow will run all tests as well as pre-commit name: Tests and linting on: @@ -7,99 +7,143 @@ on: - master pull_request: schedule: - - cron: '0 0 */2 * *' + - cron: "0 0 */2 * *" jobs: pre-commit: runs-on: ubuntu-latest steps: - # All of these steps are just setup - - uses: actions/checkout@v3 - - name: Setting MAMBA_PATH - run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV - - name: Setting OPENWPM_MAMBA_PATH - run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV - # If the environment.yaml hasn't changed we just reuse the entire conda install - - id: cache - uses: actions/cache@v3 - env: - cache-name: conda-cache - with: - path: ${{ env.MAMBA_PATH }} - key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }} - - - name: Install conda - if: ${{ steps.cache.outputs.cache-hit != 'true' }} - run: $GITHUB_WORKSPACE/scripts/install-mamba.sh - - - run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH - - - name: Install.sh (cache miss) - if: ${{ steps.cache.outputs.cache-hit != 'true' }} - run: $GITHUB_WORKSPACE/install.sh - - name: Install.sh (cache hit) - if: ${{ steps.cache.outputs.cache-hit == 'true' }} - run: $GITHUB_WORKSPACE/install.sh --skip-create - - run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH - # Now we have a working OpenWPM environment - - - run: pre-commit run --all + # All of these steps are just setup + - uses: actions/checkout@v3 + - name: Setting MAMBA_PATH + run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV + - name: Setting OPENWPM_MAMBA_PATH + run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV + # If the environment.yaml hasn't changed we just reuse the entire conda install + - id: cache + uses: actions/cache@v3 + env: + cache-name: conda-cache + with: + path: ${{ env.MAMBA_PATH }} + key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }} + + - name: Install conda + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/scripts/install-mamba.sh + + - run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH + + - name: Install.sh (cache miss) + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/install.sh + - name: Install.sh (cache hit) + if: ${{ steps.cache.outputs.cache-hit == 'true' }} + run: $GITHUB_WORKSPACE/install.sh --skip-create + - run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH + # Now we have a working OpenWPM environment + + - run: pre-commit run --all + + demo: + runs-on: ubuntu-latest + steps: + # All of these steps are just setup + - uses: actions/checkout@v3 + - name: Setting MAMBA_PATH + run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV + - name: Setting OPENWPM_MAMBA_PATH + run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV + # If the environment.yaml hasn't changed we just reuse the entire conda install + - id: cache + uses: actions/cache@v3 + env: + cache-name: conda-cache + with: + path: ${{ env.MAMBA_PATH }} + key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }} + + - name: Install conda + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/scripts/install-mamba.sh + + - run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH + + - name: Install.sh (cache miss) + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/install.sh + - name: Install.sh (cache hit) + if: ${{ steps.cache.outputs.cache-hit == 'true' }} + run: $GITHUB_WORKSPACE/install.sh --skip-create + - run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH + # Now we have a working OpenWPM environment + + - run: python demo.py --headless tests: runs-on: ubuntu-latest strategy: matrix: - test-groups: ["test/test_[a-e]*", "test/test_[f-h]*", "test/test_[i-o,q-r,t-z]*", "test/test_[p]*", "test/test_[s]*", "test/storage/*", "test/extension/*"] + test-groups: + [ + "test/test_[a-e]*", + "test/test_[f-h]*", + "test/test_[i-o,q-r,t-z]*", + "test/test_[p]*", + "test/test_[s]*", + "test/storage/*", + "test/extension/*", + ] fail-fast: false steps: - # All of these steps are just setup, maybe we should wrap them in an action - - uses: actions/checkout@v3 - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - # Setting env variables that depend on $HOME - - name: Setting MAMBA_PATH - run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV - - name: Setting OPENWPM_MAMBA_PATH - run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV - - # If the environment.yaml hasn't changed we just reuse the entire conda install - - id: conda-cache - uses: actions/cache@v3 - env: - cache-name: conda-cache - with: - path: ${{ env.MAMBA_PATH }} - key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }} - - - name: Install conda - if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }} - run: $GITHUB_WORKSPACE/scripts/install-mamba.sh - - - run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH - - - name: Install.sh (cache miss) - if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }} - run: $GITHUB_WORKSPACE/install.sh - - name: Install.sh (cache hit) - if: ${{ steps.conda-cache.outputs.cache-hit == 'true' }} - run: $GITHUB_WORKSPACE/install.sh --skip-create - - - run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH - # Now we have a working OpenWPM environment - - - run: ./scripts/ci.sh - env: - DISPLAY: ":99.0" - TESTS: ${{ matrix.test-groups }} - - name: Test Report - uses: dorny/test-reporter@v1 - if: success() || failure() # run this step even if previous step failed - with: - name: OpenWPM # Name of the check run which will be created - path: junit-report.xml # Path to test results - reporter: java-junit # Format of test results + # All of these steps are just setup, maybe we should wrap them in an action + - uses: actions/checkout@v3 + - name: Cache node modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + # Setting env variables that depend on $HOME + - name: Setting MAMBA_PATH + run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV + - name: Setting OPENWPM_MAMBA_PATH + run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV + + # If the environment.yaml hasn't changed we just reuse the entire conda install + - id: conda-cache + uses: actions/cache@v3 + env: + cache-name: conda-cache + with: + path: ${{ env.MAMBA_PATH }} + key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }} + + - name: Install conda + if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/scripts/install-mamba.sh + + - run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH + + - name: Install.sh (cache miss) + if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }} + run: $GITHUB_WORKSPACE/install.sh + - name: Install.sh (cache hit) + if: ${{ steps.conda-cache.outputs.cache-hit == 'true' }} + run: $GITHUB_WORKSPACE/install.sh --skip-create + + - run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH + # Now we have a working OpenWPM environment + + - run: ./scripts/ci.sh + env: + DISPLAY: ":99.0" + TESTS: ${{ matrix.test-groups }} + - name: Test Report + uses: dorny/test-reporter@v1 + if: success() || failure() # run this step even if previous step failed + with: + name: OpenWPM # Name of the check run which will be created + path: junit-report.xml # Path to test results + reporter: java-junit # Format of test results diff --git a/demo.py b/demo.py index 22f5a0d54..758ca299f 100644 --- a/demo.py +++ b/demo.py @@ -1,5 +1,6 @@ import argparse from pathlib import Path +from typing import Literal import tranco @@ -11,27 +12,33 @@ from openwpm.task_manager import TaskManager parser = argparse.ArgumentParser() -parser.add_argument("--tranco", action="store_true", default=False), +parser.add_argument("--tranco", action="store_true", default=False) +parser.add_argument("--headless", action="store_true", default=False), + args = parser.parse_args() +sites = [ + "http://www.example.com", + "http://www.princeton.edu", + "http://citp.princeton.edu/", +] if args.tranco: # Load the latest tranco list. See https://tranco-list.eu/ print("Loading tranco top sites list...") t = tranco.Tranco(cache=True, cache_dir=".tranco") latest_list = t.list() sites = ["http://" + x for x in latest_list.top(10)] -else: - sites = [ - "http://www.example.com", - "http://www.princeton.edu", - "http://citp.princeton.edu/", - ] + + +display_mode: Literal["native", "headless", "xvfb"] = "native" +if args.headless: + display_mode = "headless" # Loads the default ManagerParams # and NUM_BROWSERS copies of the default BrowserParams NUM_BROWSERS = 2 manager_params = ManagerParams(num_browsers=NUM_BROWSERS) -browser_params = [BrowserParams(display_mode="native") for _ in range(NUM_BROWSERS)] +browser_params = [BrowserParams(display_mode=display_mode) for _ in range(NUM_BROWSERS)] # Update browser configuration (use this for per-browser settings) for browser_param in browser_params: