Skip to content

Commit

Permalink
feat(ci): check that demo.py works (#1048)
Browse files Browse the repository at this point in the history
* feat(ci): check that demo.py works

* feat(demo.py): add headless flag

* fix(GHA): run demo.py with headless mode
  • Loading branch information
vringar authored Sep 10, 2023
1 parent f0a800a commit a4d2fba
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 94 deletions.
216 changes: 130 additions & 86 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
23 changes: 15 additions & 8 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
from pathlib import Path
from typing import Literal

import tranco

Expand All @@ -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:
Expand Down

0 comments on commit a4d2fba

Please sign in to comment.