Skip to content

update lock

update lock #108

Workflow file for this run

name: Tests
on: [push, pull_request]
permissions:
contents: read
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:
tox_tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
# Maybe true?
fail-fast: false
matrix:
include:
# Static analysis
# - { name: "ruff", python: "3.11", os: ubuntu-latest, tox: "ruff" }
# - { name: "mypy", python: "3.10", os: ubuntu-latest, tox: "mypy" }
# OS 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 on Python versions
# - { 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 }
# - { name: "3.9", python: "3.9", os: ubuntu-latest, tox: py39 }
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up Python and virtual environment
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
plugins: |
poetry-dynamic-versioning[plugin]
poethepoet[poetry_plugin]
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with test --no-plugins
- name: set full Python version in PY env var
if: ${{ matrix.os != 'windows-latest' }}
# See https://pre-commit.com/#github-actions-example
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
# Install node and yarn in order to build the front end during packaging
- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- 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: Run tox tests
run: |
source $VENV
tox -e ${{ matrix.tox }}
lint_typecheck_test_webui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: borales/actions-yarn@v5
with:
cmd: install
dir: locust/webui
- uses: borales/actions-yarn@v5
with:
cmd: build
dir: locust/webui
- uses: borales/actions-yarn@v5
with:
cmd: test
dir: locust/webui
- uses: borales/actions-yarn@v5
with:
cmd: lint
dir: locust/webui
- uses: borales/actions-yarn@v5
with:
cmd: type-check
dir: locust/webui
verify_docker_build:
name: Always - Docker verify, push to tag 'master' if on master
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' # PR build doesnt get proper version, so dont try to build it
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/login-action@v3
if: github.repository_owner == 'locustio'
with:
username: locustbuild
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build and publish image
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/master' && github.repository_owner == 'locustio' }}
tags: locustio/locust:master
docker_tagged:
name: Tagged - Docker push to tag based on git tag. Also push 'latest' if on master
needs: [tox_tests, lint_typecheck_test_webui]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags') && github.repository_owner == 'locustio'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- 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:
username: locustbuild
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build and publish image
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: locustio/locust:${{ env.TAG }}${{ ( env.BRANCH == 'master' && ',locustio/locust:latest') || '' }}
publish:
name: Publish release on tag
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:
- name: Publish tagged version to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- uses: borales/actions-yarn@v5
name: Publish package on NPM
with:
cmd: publish --no-git-tag-version --non-interactive --new-version ${{ github.ref_name }}
dir: locust/webui
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
# The following is disabled because it has stopped working.
# - name: Tweet on release
# uses: infraway/[email protected]
# with:
# status: "New release: ${{ env.TAG }} https://github.com/locustio/locust/releases/tag/${{ env.TAG }}"
# api_key: ${{ secrets.TWITTER_API_CONSUMER_KEY }}
# api_key_secret: ${{ secrets.TWITTER_API_CONSUMER_SECRET }}
# 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: tox_tests
if: github.ref == 'refs/heads/master' && github.repository_owner == 'locustio'
runs-on: ubuntu-latest
steps:
# asking github if something was not a merge commit is surprisingly difficult
- run: git rev-parse HEAD^2 2>/dev/null >/dev/null && echo MERGE_COMMIT=1 | tee -a $GITHUB_ENV || true
- name: Publish prerelease version to PyPI
if: env.MERGE_COMMIT
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
# TODO: Get from initial build
- uses: borales/actions-yarn@v5
if: env.MERGE_COMMIT
name: Publish package on NPM
with:
cmd: publish --no-git-tag-version --non-interactive --tag next --new-version ${{ env.TAG }}-next-${{ github.run_id }}
dir: locust/webui
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}