diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..13e914ffe8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,98 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + - name: Run ESLint + run: | + # "--production" to skip installing devDependencies modules + npm ci --production || exit 1 + make lint + + selenium: + runs-on: ubuntu-22.04 + continue-on-error: true + strategy: + matrix: + job: [firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta] + include: + - job: firefox + INFO: "Firefox" + BROWSER: "firefox" + FIREFOX_VERSION: "latest" + - job: firefox-beta + INFO: "Firefox Beta" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-beta" + - job: firefox-nightly + INFO: "Firefox Nightly" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-nightly" + - job: firefox-esr + INFO: "Firefox ESR" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-esr" + - job: edge-beta + INFO: "Edge Beta" + BROWSER: "microsoft-edge-beta" + + env: + INFO: ${{ matrix.INFO }} + BROWSER: ${{ matrix.BROWSER }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install Python dependencies + run: pip install -r tests/requirements.txt + + - name: Set up Firefox + if: ${{ matrix.BROWSER == 'firefox' }} + uses: browser-actions/setup-firefox@v1 + with: + firefox-version: ${{ matrix.FIREFOX_VERSION }} + + - name: Install Geckodriver + if: ${{ matrix.BROWSER == 'firefox' }} + uses: browser-actions/setup-geckodriver@latest + + - name: Set up Edge + if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} + uses: browser-actions/setup-edge@v1 + with: + edge-version: beta + + - name: Install Edge WebDriver + if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} + run: ./scripts/edge_webdriver.sh + + - name: Install Xvfb + run: sudo apt-get install -y xvfb + + - name: Run Tests + run: | + type "$BROWSER" >/dev/null 2>&1 || { + echo "$BROWSER seems to be missing!" + exit 1 + } + echo "Found $("$BROWSER" --version)" + xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 tests/selenium diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7f1540fbf1..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -sudo: required -language: python -os: linux -dist: jammy -python: 3.11 -jobs: - fast_finish: true - include: - - env: INFO="lint" - node_js: node - - env: INFO="Firefox" BROWSER=firefox - addons: - firefox: latest - - env: INFO="Firefox Beta" BROWSER=firefox - addons: - firefox: latest-beta - - env: INFO="Firefox Nightly" BROWSER=firefox - addons: - firefox: latest-nightly - - env: INFO="Firefox ESR" BROWSER=firefox - addons: - firefox: latest-esr - - env: INFO="Edge Beta" BROWSER=microsoft-edge-beta - # from https://www.microsoftedgeinsider.com/en-us/download?platform=linux-deb - install: - - curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg - - sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ - - sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' - - sudo rm microsoft.gpg - - sudo apt update - - sudo apt install microsoft-edge-beta - -before_script: travis_retry ./scripts/setup_travis.sh -script: . ./scripts/run_travis.sh -services: - - xvfb diff --git a/doc/tests.md b/doc/tests.md index b8847fc69a..5e5b005f23 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -5,13 +5,11 @@ There are two types of tests: * [Unit tests](/doc/tests.md#unit-tests) for exercising isolated units of code * [Functional tests](/doc/tests.md#functional-tests) for verifying high-level extension functionality -[Travis CI](/doc/tests.md#travis-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. +[GitHub Actions](/doc/tests.md#github-actions-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. -## Travis CI +## GitHub Actions CI -Every pull request runs the [full suite of tests on Travis CI](https://app.travis-ci.com/github/EFForg/privacybadger/branches). We test on latest stable Chrome and Firefox releases, as well as on Chrome Beta, Edge Beta, Firefox Beta and Firefox ESR. - -See [`.travis.yml`](/.travis.yml) for Travis configuration, [`scripts/setup_travis.sh`](/scripts/setup_travis.sh) for test setup, and [`scripts/run_travis.sh`](/scripts/run_travis.sh) for test execution procedures. +Every pull request runs the full suite of tests on GitHub Actions. See [`test.yml`](/.github/workflows/test.yml) for the GitHub Actions configuration. We use [ESLint](https://eslint.org) to flag potential JavaScript errors and style issues. Please see our [developer guide](/doc/develop.md#lint-your-changes) for setup instructions. @@ -38,7 +36,7 @@ Do verify that removing or mutating the code being tested produces failed assert Our [functional tests](/tests/selenium/) are written in Python and driven by [Selenium](https://selenium-python.readthedocs.io/) and [pytest](https://docs.pytest.org/en/latest/). - To run them in Chrome, you need to [install `chromedriver`](http://chromedriver.chromium.org/getting-started) -- For Firefox, you need to [install `geckodriver`](https://github.com/EFForg/privacybadger/blob/1550b9efb64c1d5e276361e3940f402c3ec87afc/scripts/setup_travis.sh#L21-L50) +- For Firefox, you need to [install `geckodriver`](/scripts/geckodriver.sh) - For Microsoft Edge, [install Microsoft Edge WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) You also need to [install the Python packages](https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/) specified in [`/tests/requirements.txt`](/tests/requirements.txt). @@ -56,9 +54,6 @@ $ BROWSER=/Applications/Firefox.app/Contents/MacOS/firefox-bin pytest -v tests/ $ BROWSER=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome pytest -v tests/ ``` -For more information, see our Travis CI [setup](/scripts/setup_travis.sh) and -[run](/scripts/run_travis.sh) scripts. - ### Invocation examples diff --git a/scripts/chromedriver.sh b/scripts/chromedriver.sh index 33afbb3756..b31d0e9171 100755 --- a/scripts/chromedriver.sh +++ b/scripts/chromedriver.sh @@ -49,7 +49,7 @@ wget -q -O "$TEMPDIR/chromedriver.zip" "$chromedriver_url" \ # check that chromedriver is now present type chromedriver >/dev/null 2>&1 || { - echo "Failed to install ChromeDriver!" + echo "Failed to install ChromeDriver" exit 1 } diff --git a/scripts/edge_webdriver.sh b/scripts/edge_webdriver.sh new file mode 100755 index 0000000000..2d5f924906 --- /dev/null +++ b/scripts/edge_webdriver.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) +edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" +edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) +if [ -z "$edgedriver_version" ]; then + echo "Failed to retrieve Edge WebDriver version!" + exit 1 +fi + +echo "Installing Edge WebDriver version $edgedriver_version ..." +wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" +unzip edgedriver_linux64.zip +sudo mv msedgedriver /usr/local/bin/ +sudo chmod a+x /usr/local/bin/msedgedriver + +# check that Edge WebDriver is now present +type msedgedriver >/dev/null 2>&1 || { + echo "Failed to install Edge WebDriver" + exit 1 +} diff --git a/scripts/geckodriver.sh b/scripts/geckodriver.sh new file mode 100755 index 0000000000..77dbd4931a --- /dev/null +++ b/scripts/geckodriver.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Install the latest version of geckodriver +version=$(curl -sI https://github.com/mozilla/geckodriver/releases/latest | grep -i "^Location: " | sed 's/.*\///' | tr -d '\r') + +# check that we got something +if [ -z "$version" ]; then + echo "Failed to determine the latest Geckodriver version!" + exit 1 +fi + +# Geckodriver distribution is MacOS or Linux specific +os="$(uname -s)" +if [[ $os == "Darwin" ]]; then + os_dist="macos.tar.gz" +else + os_dist="linux64.tar.gz" +fi + +echo "Setting up Geckodriver version $version ..." +url="https://github.com/mozilla/geckodriver/releases/download/${version}/geckodriver-${version}-${os_dist}" +wget -q -O /tmp/geckodriver.tar.gz "$url" +sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/ +sudo chmod a+x /usr/local/bin/geckodriver + +# check that geckodriver is now present +type geckodriver >/dev/null 2>&1 || { + echo "Failed to install Geckodriver" + exit 1 +} diff --git a/scripts/run_travis.sh b/scripts/run_travis.sh deleted file mode 100755 index bd7d5aaa28..0000000000 --- a/scripts/run_travis.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -toplevel=$(git rev-parse --show-toplevel) -testdir=${toplevel}/tests/selenium - -run_lint() { - if ! make -C "$toplevel" lint; then - echo "Linting errors" - exit 1 - fi -} - -run_selenium() { - # autodiscover and run the tests - pytest --capture=no --verbose --durations=10 "$testdir" -} - -if [ "$INFO" == "lint" ]; then - echo "Running lint" - run_lint -else - case $BROWSER in - *chrome*) - echo "Running tests on Chrome" - run_selenium - ;; - *firefox*) - echo "Running tests on Firefox" - run_selenium - ;; - *edge*) - echo "Running tests on Edge" - run_selenium - ;; - *) - echo "Unknown BROWSER value: $BROWSER" - exit 1 - ;; - esac -fi diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh deleted file mode 100755 index f45ab24628..0000000000 --- a/scripts/setup_travis.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash - -toplevel=$(git rev-parse --show-toplevel) - -install_edge_webdriver() { - edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) - edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" - edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) - if [ -z "$edgedriver_version" ]; then - echo "Failed to retrieve Edge WebDriver version!" - exit 1 - fi - - echo "Installing Edge WebDriver version $edgedriver_version ..." - wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" - unzip edgedriver_linux64.zip - sudo mv msedgedriver /usr/local/bin/ - sudo chmod a+x /usr/local/bin/msedgedriver - - # check that Edge WebDriver is now present - type msedgedriver >/dev/null 2>&1 || { - echo "Failed to install Edge WebDriver!" - exit 1 - } -} - -install_geckodriver() { - # Install the latest version of geckodriver - version=$(curl -sI https://github.com/mozilla/geckodriver/releases/latest | grep -i "^Location: " | sed 's/.*\///' | tr -d '\r') - - # check that we got something - if [ -z "$version" ]; then - echo "Failed to determine the latest geckodriver version!" - exit 1 - fi - - # Geckodriver distribution is MacOS or Linux specific - os="$(uname -s)" - if [[ $os == "Darwin" ]]; then - os_dist="macos.tar.gz" - else - os_dist="linux64.tar.gz" - fi - - echo "Setting up geckodriver version $version ..." - url="https://github.com/mozilla/geckodriver/releases/download/${version}/geckodriver-${version}-${os_dist}" - wget -q -O /tmp/geckodriver.tar.gz "$url" - sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/ - sudo chmod a+x /usr/local/bin/geckodriver - - # check that geckodriver is now present - type geckodriver >/dev/null 2>&1 || { - echo "Failed to install geckodriver!" - exit 1 - } -} - -install_python_deps() { - pip install -r "$toplevel"/tests/requirements.txt -} - -install_node_deps() { - # "--production" to skip installing devDependencies modules - npm ci --production || exit 1 -} - -# check that the desired browser is present as it might fail to install -# for example: https://travis-ci.org/EFForg/privacybadger/jobs/362381214 -check_browser() { - type "$BROWSER" >/dev/null 2>&1 || { - echo "$BROWSER seems to be missing!" - exit 1 - } - - # print the version - echo "Found $("$BROWSER" --version)" -} - -case $INFO in - *Chrome*) - check_browser - "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 - install_python_deps - ;; - *Firefox*) - check_browser - install_geckodriver - install_python_deps - ;; - *Edge*) - check_browser - install_edge_webdriver - install_python_deps - ;; - *lint*) - install_node_deps - ;; - *) - echo "bad INFO variable, got $INFO" - exit 1 - ;; -esac diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 85b917a5e2..c477160610 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -145,7 +145,7 @@ def fix_chrome_extension_id(self): @property def wants_xvfb(self): - if self.on_travis or bool(int(os.environ.get('ENABLE_XVFB', 0))): + if self.on_github_actions or bool(int(os.environ.get('ENABLE_XVFB', 0))): try: Xvfb except NameError: @@ -155,8 +155,8 @@ def wants_xvfb(self): return False @property - def on_travis(self): - if "TRAVIS" in os.environ: + def on_github_actions(self): + if "GITHUB_ACTIONS" in os.environ: return True return False