Skip to content

Commit

Permalink
Full OS matrix builds for unit and integration tests (Linux, Mac, Win…
Browse files Browse the repository at this point in the history
…dows)
  • Loading branch information
jackie-pc committed Jul 31, 2023
1 parent 9cbe02e commit e34bfb1
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 225 deletions.
53 changes: 37 additions & 16 deletions .github/actions/setup_build_env/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Assumes:
# - CWD is the root directory of your project (e.g. reflex/)
# - You have a poetry.lock file in the root directory of your project
# - You have a pyproject.toml file in the root directory of your project
# Entry conditions:
# - `setup/checkout` has already happened
# - working dir is the root directory of your project (e.g. `reflex/`).
# - You have a `poetry.lock` file in the root directory of your project
# - You have a `pyproject.toml` file in the root directory of your project
#
# Exit conditions:
# - Python of version `python-version` is ready to be invoked as `python`.
# - Poetry of version `poetry-version` is ready ot be invoked as `poetry`.
# - If `run-poetry-install` is true, deps as defined in `pyproject.toml` will have been installed into the venv at `create-venv-at-path`.

name: 'Setup Reflex build environment'
description: 'Sets up Python, install poetry (cached), install project deps (cached)'
inputs:
Expand All @@ -20,9 +27,7 @@ inputs:
description: 'Path to venv (if poetry install is enabled)'
required: false
default: '.venv'
shell:
description: 'Shell to use for running commands'
required: true

runs:
using: "composite"
steps:
Expand All @@ -31,12 +36,25 @@ runs:
with:
python-version: ${{ inputs.python-version }}

# This is required for OS portability in presence of caching.
#
# The act of installing poetry has the side effect of adding
# poetry bin path to system path.
#
# But, if we get a cache hit on the poetry installation, we
# don't get this important side effect. As a result, bare calls
# to "poetry" fails.
- name: Prepare PATH env to include where poetry will be installed into
shell: bash
run: |
echo "~/.local/bin/" >> $GITHUB_PATH
- name: Restore cached poetry install
id: restore-poetry-cache
uses: actions/cache/restore@v3
with:
path: ~/.local
key: python-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}
key: ${{ runner.os }}-python-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}

- if: steps.restore-poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry
Expand All @@ -45,6 +63,7 @@ runs:
version: ${{ inputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: ${{ inputs.create-venv-at-path }}

- if: steps.restore-poetry-cache.outputs.cache-hit != 'true'
name: Save poetry install to cache
Expand All @@ -58,17 +77,19 @@ runs:
uses: actions/cache/restore@v3
with:
path: ${{ inputs.create-venv-at-path }}
key: python-${{ inputs.python-version }}-pydeps-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-python-${{ inputs.python-version }}-pydeps-${{ hashFiles('**/poetry.lock') }}

- if: ${{ inputs.run-poetry-install == 'true' && steps.restore-pydeps-cache.outputs.cache-hit != 'true' }}
name: Run poetry install (will get cached)
shell: ${{ inputs.shell }}
# We skip over installing the root package (the current project code under CI)
# Root package should not be cached - its content is not reflected in poetry.lock / cache key

# On Windows, it is scripts/activate. On Linux and MacOS, it is bin/activate
shell: bash
run: |
python -m venv ${{ inputs.create-venv-at-path }}
source ${{ inputs.create-venv-at-path }}/bin/activate
poetry install --no-interaction --no-root
python -m venv ${{ inputs.create-venv-at-path }}
source ${{ inputs.create-venv-at-path }}/*/activate
poetry install --no-interaction --no-root
- if: steps.restore-pydeps-cache.outputs.cache-hit != 'true'
name: Save Python deps to cache
Expand All @@ -78,10 +99,10 @@ runs:
key: ${{ steps.restore-pydeps-cache.outputs.cache-primary-key }}

- if: ${{ inputs.run-poetry-install == 'true' }}
name: Run poetry install (including root package)
shell: ${{ inputs.shell }}
name: Run poetry install (root package)
# Here we really install the root package (the current project code under CI).env:
# This should not be cached.
shell: bash
run: |
source ${{ inputs.create-venv-at-path }}/bin/activate
source ${{ inputs.create-venv-at-path }}/*/activate
poetry install --only-root --no-interaction
29 changes: 0 additions & 29 deletions .github/workflows/build.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/integration_examples.yml

This file was deleted.

99 changes: 99 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: integration-tests

on:
push:
branches: [ main ]
paths-ignore:
- '**/*.md'
pull_request:
branches: [ main ]
paths-ignore:
- '**/*.md'

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
example-counter:
strategy:
# Prioritize getting more information out of the workflow (even if something fails)
fail-fast: false
matrix:
# Show OS combos first in GUI
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
node-version: [ "16.x" ]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv

- name: Clone Reflex Examples Repo
uses: actions/checkout@v3
with:
repository: reflex-dev/reflex-examples
path: reflex-examples

- name: Install requirements for counter example
working-directory: ./reflex-examples/counter
run: |
poetry run pip install -r requirements.txt
- name: Init Website for counter example
working-directory: ./reflex-examples/counter
run: |
poetry run reflex init
- name: Run Website and Check for errors
run: |
poetry run bash scripts/integration.sh ./reflex-examples/counter dev
reflex-web:
strategy:
fail-fast: false
matrix:
# Show OS combos first in GUI
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ "3.10", "3.11" ]
node-version: [ "16.x" ]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv

- name: Clone Reflex Website Repo
uses: actions/checkout@v3
with:
repository: reflex-dev/reflex-web
path: reflex-web

- name: Install Requirements for reflex-web
working-directory: ./reflex-web
run: poetry run pip install -r requirements.txt
- name: Init Website for reflex-web
working-directory: ./reflex-web
run: poetry run reflex init
- name: Run Website and Check for errors
run: |
poetry run bash scripts/integration.sh ./reflex-web prod
50 changes: 0 additions & 50 deletions .github/workflows/integration_website.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: reflex-init-test
name: reflex-init-in-docker-test

on:
push:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
pull_request:
branches:
- main
paths-ignore:
- '**/*.md'

jobs:
# TODO we can extend to various starting points (e.g. Ubuntu with node, without node, with unzip, without unzip, etc.)
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: unit-tests

on:
push:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/*.md'

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
unit-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# TODO consider bringing back 3.7. Note Windows x 3.7 fails from some sqlalchemy related problem
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv
- run: |
export PYTHONUNBUFFERED=1
poetry run pytest tests --cov --no-cov-on-fail --cov-report=
- run: poetry run coverage html
Loading

0 comments on commit e34bfb1

Please sign in to comment.