Skip to content

Commit

Permalink
Try a thing
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeShirnia committed Apr 26, 2024
1 parent ef209c0 commit d6d57be
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ jobs:
- detect-file-changes
uses: ./.github/workflows/pytest.yml
if: needs.detect-file-changes.outputs.oom_investigate == 'true'
secrets: inherit
175 changes: 140 additions & 35 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,156 @@
name: Run Unit Tests on Multiple Python Versions

name: Run Unit Tests on Multiple Python Versions and Distributions

on:
workflow_call:


env:
REPOSITORY: lukeshirnia/out-of-memory

jobs:
pytest_legacy_python:
name: python:${{ matrix.python-version }}
runs-on: ubuntu-20.04
container:
image: python:${{ matrix.python-version }}-buster
strategy:
fail-fast: true
matrix:
python-version: ["2.7", "3.6"]

build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v3

- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

pytest_latest_python:
name: ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
- name: Build Docker images
run: |
docker-compose build
- name: Build and push Docker images
run: |
docker-compose config | grep 'image:' | awk '{print $2}' | while read image; do
echo "Processing image: $image"
base_image_name=$(echo $image | awk -F: '{print $1}')
version_tag=$(echo $image | awk -F: '{print $2}')
new_tag="${{ env.REPOSITORY }}:${base_image_name#*/}"
echo "Tagging image $image as $new_tag"
docker tag $image $new_tag
docker push $new_tag
done
test-python-versions:
needs: build_and_push
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
python-version: ["python27", "python36", "python310"]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run pytest
run: docker run --rm ${{ env.REPOSITORY }}:${{ matrix.python-version }}-pytest pytest -v --ignore=tests/test_system.py

- name: Display Python version
run: python -c "import sys; print(sys.version)"
test-systems:
needs: build_and_push
runs-on: ubuntu-latest
strategy:
matrix:
distro: ["amazonlinux", "centos7", "osx"]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Test with pytest
- name: Setup test command
id: setup
run: |
pip install pytest pytest-cov
pytest tests/
if [ "${{ matrix.distro }}" == "osx-pytest" ]; then
echo "::set-output name=command::python -m pytest"
else
echo "::set-output name=command::pytest"
fi
- name: Run system tests
run: docker run --rm ${{ env.REPOSITORY }}:${{ matrix.distro }}-pytest ${{ steps.setup.outputs.command }} -v tests/test_system.py -p no:cacheprovider


# name: Run Unit Tests on Multiple Python Versions

# on:
# workflow_call:

# jobs:
# pytest_legacy_python_version:
# name: python:${{ matrix.python-version }}
# runs-on: ubuntu-20.04
# container:
# image: python:${{ matrix.python-version }}-buster
# strategy:
# fail-fast: true
# matrix:
# python-version: ["2.7", "3.6"]
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4

# - name: Display Python version
# run: python -c "import sys; print(sys.version)"

# - name: Test with pytest
# run: |
# pip install pytest pytest-cov
# pytest tests/

# pytest_latest_python_version:
# name: ${{ matrix.os }} ${{ matrix.python-version }}
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: true
# matrix:
# os: [ubuntu-latest]
# python-version: ["3.11"]
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}

# - name: Display Python version
# run: python -c "import sys; print(sys.version)"

# - name: Test with pytest
# run: |
# pip install pytest pytest-cov
# pytest tests/

# pytest_distribution_tests:
# name: ${{ matrix.os }} ${{ matrix.python-version }}
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: true
# matrix:
# os: [ubuntu-latest]
# python-version: ["3.11"]
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}

# - name: Display Python version
# run: python -c "import sys; print(sys.version)"

# - name: Test with pytest
# run: |
# pip install pytest pytest-cov
# pytest tests/distribution_tests/

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ RUN if echo ${IMAGE} | grep -q "amazon"; then \
RUN ${PIP} install pytest

# Only install black on Python 3.x as it doesn't exist on 2.x
RUN if [ $(${PYTHON_VERSION}) -ge 3 ]; then ${PIP} install black isort; fi
RUN if [ $PYTHON_VERSION -ge 3 ]; then ${PIP} install black isort; fi

WORKDIR /app
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
IMAGE: amazonlinux
PIP: pip3
PYTHON_VERSION: 3
image: amazonlinux
image: amazonlinux-pytest
volumes:
- .:/app

Expand All @@ -50,7 +50,7 @@ services:
IMAGE: centos/python-27-centos7
PIP: pip
PYTHON_VERSION: 2
image: centos7
image: centos7-pytest
volumes:
- .:/app

Expand All @@ -62,6 +62,6 @@ services:
IMAGE: sickcodes/docker-osx
PIP: python -m pip
PYTHON_VERSION: 3
image: osx
image: osx-pytest
volumes:
- .:/app

0 comments on commit d6d57be

Please sign in to comment.