Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mquinnfd committed Aug 22, 2024
1 parent a13fc97 commit cede86e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 108 deletions.
121 changes: 27 additions & 94 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,35 @@ defaults:
run:
shell: bash

# TODO:

# in the publish workflow, build the package once, up front and add it as a shared artifact

# https://tox.wiki/en/latest/config.html#external-package-builder

# check if docker image has to be built twice
# consider splitting out workflows into different files

jobs:
tests:
tox_tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}

strategy:
# Maybe true?
fail-fast: false
matrix:
include:
# - {name: Windows, python: '3.12', os: windows-latest, tox: fail_fast_test_main }
# # - {name: Mac, python: '3.12', os: macos-latest, tox: fail_fast_test_main }
# Linting
# - { name: "ruff", python: "3.11", os: ubuntu-latest, tox: "ruff" }
# - { name: "mypy", python: "3.10", os: ubuntu-latest, tox: "mypy" }
# run some integration tests and abort immediately if they fail, for faster feedback

# Integration tests
- { name: "Linux", python: "3.12", os: ubuntu-latest, tox: fail_fast_test_main }
# - {name: Windows, python: '3.12', os: windows-latest, tox: fail_fast_test_main }
# # - {name: Mac, python: '3.12', os: macos-latest, tox: fail_fast_test_main }

# Unit tests per Python version
# - { name: "3.12", python: "3.12", os: ubuntu-latest, tox: py312 }
# - { name: "3.11", python: "3.11", os: ubuntu-latest, tox: py311 }
# - { name: "3.10", python: "3.10", os: ubuntu-latest, tox: py310 }
Expand Down Expand Up @@ -68,10 +82,10 @@ jobs:
- name: Install Yarn
run: npm install -g yarn
# Install the project and run the isolated tests
- name: Install project
run: poetry install --no-interaction
# - name: Install project
# run: poetry install --no-interaction
- name: Run tox tests
run:
run: |
source $VENV
tox -e ${{ matrix.tox }}
Expand Down Expand Up @@ -112,17 +126,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# The following steps aren't needed, but if you want 100% guarantee the tagged/release build will work you can add them
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: "3.x"
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip poetry
# python -m poetry config virtualenvs.create false
# python -m poetry self add "poetry-dynamic-versioning[plugin]"
# - run: echo "TAG=$(poetry version -s)" | tee -a $GITHUB_ENV
- uses: docker/login-action@v3
if: github.repository_owner == 'locustio'
with:
Expand All @@ -146,7 +149,7 @@ jobs:

docker_tagged:
name: Tagged - Docker push to tag based on git tag. Also push 'latest' if on master
needs: tests
needs: [tox_tests, lint_typecheck_test_webui]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags') && github.repository_owner == 'locustio'
steps:
Expand All @@ -157,12 +160,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
python -m poetry config virtualenvs.create false
python -m poetry self add "poetry-dynamic-versioning[plugin]"
- run: echo "TAG=$(poetry version -s)" | tee -a $GITHUB_ENV
- run: echo "BRANCH=$(git branch -a --contains ${{ env.TAG }} | grep -v HEAD | cut -d '/' -f3)" | tee -a $GITHUB_ENV
- uses: docker/login-action@v3
with:
Expand All @@ -186,39 +183,10 @@ jobs:

publish:
name: Publish release on tag
needs: [verify_docker_build, tests]
needs: [verify_docker_build, tox_tests, lint_typecheck_test_webui]
if: startsWith(github.event.ref, 'refs/tags') && github.repository_owner == 'locustio'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Yarn
run: npm install -g yarn
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
python -m poetry config virtualenvs.create false
python -m poetry self add "poetry-dynamic-versioning[plugin]"
# Pre-build the UI bundle and don't repeat it on the build step to allow sdist to find the files
- name: Prebuild UI
run: |
yarn webui:install
yarn webui:build
yarn webui:build:lib
- name: Build + set TAG env var for later use
run: |
SKIP_PRE_BUILD=true python -m poetry build
./rename-wheel.sh
echo "TAG=$(poetry version -s)" | tee -a $GITHUB_ENV
- name: Publish tagged version to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand All @@ -242,57 +210,22 @@ jobs:
# access_token: ${{ secrets.TWITTER_API_ACCESS_TOKEN_KEY }}
# access_token_secret: ${{ secrets.TWITTER_API_ACCESS_TOKEN_SECRET }}

# TODO: Grab the built artifact instead of checking it out
publish_prerelease:
name: Publish prerelease on merge commit to master
needs: tests
if: github.ref == 'refs/heads/master' && github.repository_owner == 'locustio'
needs: tox_tests
if: github.ref == 'refs/heads/master' && github.repository_owner == 'locustio' && ${{ env.NOT_MERGE_COMMIT == '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# asking github if something was not a merge commit is surprisingly difficult
- run: git rev-parse HEAD^2 2>/dev/null >/dev/null || echo NOT_MERGE_COMMIT=1 | tee -a $GITHUB_ENV
- name: Set up Python
if: ${{ env.NOT_MERGE_COMMIT == '' }}
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Set Node.js 20.x
if: ${{ env.NOT_MERGE_COMMIT == '' }}
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Yarn
if: ${{ env.NOT_MERGE_COMMIT == '' }}
run: npm install -g yarn
- name: Install dependencies
if: ${{ env.NOT_MERGE_COMMIT == '' }}
run: |
python -m pip install --upgrade pip poetry
python -m poetry config virtualenvs.create false
python -m poetry self add "poetry-dynamic-versioning[plugin]"
# Pre-build the UI bundle and don't repeat it on the build step to allow sdist to find the files
- name: Prebuild UI
if: ${{ env.NOT_MERGE_COMMIT == '' }}
run: |
yarn webui:install
yarn webui:build
yarn webui:build:lib
- name: Build
if: ${{ env.NOT_MERGE_COMMIT == '' }}
run: |
SKIP_PRE_BUILD=true python -m poetry build
./rename-wheel.sh
- name: Publish prerelease version to PyPI
if: ${{ env.NOT_MERGE_COMMIT == '' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: Set locust version tag
run: echo "TAG=$(poetry version -s | cut -d '.' -f1-3)" | tee -a $GITHUB_ENV
# TODO: Get from initial build
- uses: borales/actions-yarn@v5
name: Publish package on NPM
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.7 # Pin the same version in the tox.ini file.
rev: v0.3.7 # Pin the same version in the pyproject.toml file
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ envlist =
[testenv]
allowlist_externals =
bash
timeout
grep
poetry
yarn
make
timeout
ruff
mypy
commands_pre =
# Ensures test dependencies are available to these envs
poetry install --no-interaction --no-root --only test --no-plugins
commands =
poetry install --with test
poetry run python -m unittest discover []
python -m unittest discover []
; Disable these tests for now, because they are breaking. When someone has time they should be converted into regular unit tests
; bash -ec "PYTHONUNBUFFERED=1 timeout 20s python3 examples/rest.py >{temp_dir}/out.txt 2>/{temp_dir}/err.txt || true"
; grep -qm 1 'my custom error message with response text, response was {"args"' {temp_dir}/out.txt
Expand All @@ -25,16 +27,18 @@ commands =
bash -ec 'PYTHONUNBUFFERED=1 python3 examples/debugging_advanced.py | grep done'

[testenv:fail_fast_test_main]
commands_pre =
poetry install --no-interaction --no-root --only test --no-plugins
python pre_build.py
pip install .
commands =
poetry install --with test
bash -ec 'if [ "$WINDIR" ]; then pip install .; fi' # ensure locust.exe is written to Scripts folder on Windows
poetry run python -m unittest -f locust.test.test_main
python -m unittest -f locust.test.test_main

[testenv:ruff]
; Pin the same version in the .pre-commit-config.yaml file.
commands =
poetry run ruff check .
poetry run ruff format --check
ruff check .
ruff format --check

[testenv:mypy]
commands = poetry run mypy locust/
commands =
mypy locust/

0 comments on commit cede86e

Please sign in to comment.