Test #223
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
pull_request: | |
paths-ignore: | |
- '**/*.md' | |
push: | |
paths-ignore: | |
- '**/*.md' | |
workflow_dispatch: {} | |
schedule: | |
# Run tests at night during each Sunday | |
- cron: "0 1 * * 0" | |
jobs: | |
export-requirements: | |
name: Export requirements | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.6" | |
- name: Install pip-tools | |
run: pip install pip-tools | |
- name: Export project dependencies | |
run: | | |
pip-compile pyproject.toml | |
pip-compile --extra dev -o dev-requirements.txt pyproject.toml | |
- name: Save resolved dependencies as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: requirements | |
path: | | |
requirements.txt | |
dev-requirements.txt | |
run-tests: | |
name: Run tests | |
needs: export-requirements | |
strategy: | |
fail-fast: true | |
matrix: | |
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] | |
# Service containers are only available on Linux | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices | |
os: [ubuntu-20.04] | |
# os: [ubuntu-latest, macos-latest, windows-latest] | |
services: | |
opensearch: | |
image: opensearchproject/opensearch:latest | |
options: -e "cluster.name=opensearch-cluster" -e "node.name=opensearch" -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" | |
ports: | |
- "9200:9200" | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Download exported requirements.txt artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: requirements | |
- name: Install package dependencies | |
run: pip install -r requirements.txt -r dev-requirements.txt | |
- name: Wait until OpenSearch boots up | |
run: | | |
while ! curl -s -k -u "admin:admin" "https://localhost:9200/_cat/health" | grep -q yellow > /dev/null; do | |
sleep 1 | |
done | |
- name: Run mypy | |
env: | |
TEST_OPENSEARCH_HOST: "https://localhost:9200" | |
run: python -m mypy opensearch_logger --strict | |
- name: Run flake8 | |
run: python -m flake8 opensearch_logger | |
- name: Run tests | |
env: | |
TEST_OPENSEARCH_HOST: "https://localhost:9200" | |
run: python -m pytest -x | |
- name: Run test coverage | |
env: | |
TEST_OPENSEARCH_HOST: "https://localhost:9200" | |
run: python -m pytest --cov --cov-report=xml --cov-config=pyproject.toml | |
if: matrix.python-version == '3.6' | |
- name: Save coverage results artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage | |
path: coverage.xml | |
if: matrix.python-version == '3.6' | |
measure-coverage: | |
name: Report coverage | |
needs: run-tests | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Download coverage results artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: coverage | |
- name: Upload coverage results to Codecov | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
run: bash <(curl -s https://codecov.io/bash) |