diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml index 92570dd..012eb0c 100644 --- a/.github/workflows/production-deploy.yml +++ b/.github/workflows/production-deploy.yml @@ -42,7 +42,7 @@ jobs: environment: "production" version-bump: ${{ inputs.version-bump }} branch: ${{ inputs.branch }} - run-database-tests: false + run-database-tests: true seed: ${{ inputs.seed }} request_delay: ${{ inputs.request_delay }} max_concurrency: ${{ inputs.max_concurrency }} diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index d294a28..5f02c0d 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -7,58 +7,62 @@ on: workflow_dispatch: jobs: -# test: -# name: Test -# runs-on: ubuntu-latest -# permissions: -# contents: read -# actions: read -# checks: write -# pull-requests: write -# strategy: -# fail-fast: false -# matrix: -# python-version: ["3.8"] -# steps: -# - name: Checkout -# uses: actions/checkout@v4 -# - name: Set up Python ${{ matrix.python-version }} -# id: python-setup -# uses: actions/setup-python@v5 -# with: -# python-version: ${{ matrix.python-version }} -# -# - name: Install dependencies -# run: | -# python -m venv .venv -# .venv/bin/pip install pytest -# .venv/bin/pip install -r app/requirements.txt -# -# -# - name: Lint with flake8 -# run: | -# source .venv/bin/activate -# .venv/bin/pip install flake8 -# # stop the build if there are Python syntax errors or undefined names -# flake8 ./app --count --select=E9,F63,F7,F82 --show-source --statistics -# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide -# flake8 ./app --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# -# - name: Run tests -# if: always() -# run: | -# source .venv/bin/activate -# pytest --junit-xml=./reports/pytest.xml --tb=auto -v -# -# - name: Upload test results -# uses: actions/upload-artifact@v4 -# if: always() -# with: -# name: test-results-${{ matrix.python-version }} -# path: ./reports/pytest.xml -# if-no-files-found: warn + test: + name: Test + runs-on: ubuntu-latest + permissions: + contents: read + actions: read + checks: write + pull-requests: write + strategy: + fail-fast: false + matrix: + python-version: ["3.12"] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + id: python-setup + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m venv .venv + .venv/bin/pip install pytest + .venv/bin/pip install -r app/requirements.txt + + - name: Download NLTK data + run: | + .venv/bin/python -m nltk.downloader wordnet word2vec_sample brown stopwords punkt punkt_tab + + + - name: Lint with flake8 + run: | + source .venv/bin/activate + .venv/bin/pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 ./app --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 ./app --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Run tests + if: always() + run: | + source .venv/bin/activate + pytest --junit-xml=./reports/pytest.xml --tb=auto -v + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results-${{ matrix.python-version }} + path: ./reports/pytest.xml + if-no-files-found: warn deploy: -# needs: test + needs: test uses: lambda-feedback/evaluation-function-workflows/.github/workflows/deploy.yml@main with: template-repository-name: "lambda-feedback/evaluation-function-boilerplate-python" diff --git a/.github/workflows/test-lint.yml b/.github/workflows/test-lint.yml index 3ad75ee..1b559a9 100644 --- a/.github/workflows/test-lint.yml +++ b/.github/workflows/test-lint.yml @@ -1,8 +1,7 @@ name: Test and Lint on: -# pull_request: - workflow_dispatch: + pull_request: jobs: test: @@ -32,6 +31,10 @@ jobs: .venv/bin/pip install pytest .venv/bin/pip install -r app/requirements.txt + - name: Download NLTK data + run: | + .venv/bin/python -m nltk.downloader wordnet word2vec_sample brown stopwords punkt punkt_tab + - name: Lint with flake8 run: | source .venv/bin/activate diff --git a/README.md b/README.md index 4054297..421d168 100755 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Once the code passes all these tests, it will then be uploaded to AWS and will b ## Pre-requisites Although all programming can be done through the GitHub interface, it is recommended you do this locally on your machine. To do this, you must have installed: -- Python 3.8 or higher. +- Python 3.12 or higher. - GitHub Desktop or the `git` CLI. diff --git a/app/Dockerfile b/app/Dockerfile index e74a84a..ddbe1a5 100755 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,9 +1,13 @@ -# Base image that bundles AWS Lambda Python 3.8 image with some middleware functions -# FROM base-eval-tmp -FROM ghcr.io/lambda-feedback/baseevalutionfunctionlayer:main-3.8 +# Base image that bundles the AWS Lambda Python image with the lambda-feedback middleware (app.handler) +FROM ghcr.io/lambda-feedback/baseevalutionfunctionlayer:main-3.12 + +# The 3.12 image is Amazon Linux 2023: use dnf, and install `find` (used below) +RUN dnf install -y findutils wget unzip && dnf clean all WORKDIR /app +ENV PYTHONPATH=/app + RUN mkdir /usr/share/nltk_data RUN mkdir -p /usr/share/nltk_data/corpora /usr/share/nltk_data/models /usr/share/nltk_data/tokenizers @@ -15,9 +19,11 @@ COPY requirements.txt . COPY brown_length . COPY word_freqs . COPY w2v . -RUN yum install -y wget unzip RUN pip3 install -r requirements.txt +# The healthcheck command runs the pytest suite +RUN pip3 install pytest + # # Download NLTK data files # RUN wget -O /usr/share/nltk_data/corpora/wordnet.zip https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/wordnet.zip # RUN wget -O /usr/share/nltk_data/models/word2vec_sample.zip https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/models/word2vec_sample.zip @@ -40,19 +46,19 @@ RUN pip3 install -r requirements.txt # RUN rm /usr/share/nltk_data/tokenizers/*.zip # Warnings: those commands sometimes download corrupted zips, so it is better to wget each package from the main site -RUN python -m nltk.downloader wordnet -RUN python -m nltk.downloader word2vec_sample -RUN python -m nltk.downloader brown -RUN python -m nltk.downloader stopwords -RUN python -m nltk.downloader punkt -RUN python -m nltk.downloader punkt_tab +RUN python3 -m nltk.downloader wordnet +RUN python3 -m nltk.downloader word2vec_sample +RUN python3 -m nltk.downloader brown +RUN python3 -m nltk.downloader stopwords +RUN python3 -m nltk.downloader punkt +RUN python3 -m nltk.downloader punkt_tab # Copy the evaluation and testing scripts COPY brown_length ./app/ COPY word_freqs ./app/ COPY w2v ./app/ COPY evaluation.py ./app/ -COPY evaluation_test.py ./app/ +COPY evaluation_tests.py ./app/ # Copy Documentation COPY docs/dev.md ./app/docs/dev.md @@ -62,5 +68,6 @@ COPY docs/user.md ./app/docs/user.md RUN chmod 644 $(find . -type f) RUN chmod 755 $(find . -type d) -# The entrypoint for AWS is to invoke the handler function within the app package -CMD [ "/app/app.handler" ] +# The entrypoint for AWS is to invoke the handler function within the app package. +# Python 3.12's Lambda runtime imports this as a module name, so it can't be a path. +CMD [ "app.handler" ] diff --git a/app/evaluation_test.py b/app/evaluation_tests.py similarity index 100% rename from app/evaluation_test.py rename to app/evaluation_tests.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..589497f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +# evaluation_tests.py is the name the base layer's healthcheck imports, so +# include it alongside pytest's default patterns. +python_files = test_*.py *_test.py *_tests.py