Skip to content

Merge pull request #18 from logzio/ci/sync-templates #4

Merge pull request #18 from logzio/ci/sync-templates

Merge pull request #18 from logzio/ci/sync-templates #4

Workflow file for this run

name: Automatic tests and code-coverage
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Add S3 bucket name and aws keys to tests config file
run: |
sed -i 's/S3_BUCKET_NAME\b/${{ secrets.AWS_S3_BUCKET_TEST }}/1' tests/config.yaml
sed -i 's/ACCESS_KEY_ID\b/${{ secrets.AWS_ACCESS_KEY_ID }}/1' tests/config.yaml
sed -i 's/SECRET_ACCESS_KEY\b/${{ secrets.AWS_SECRET_ACCESS_KEY }}/1' tests/config.yaml
- name: Run unit tests
run: |
pip install pytest
pip install boto3
pip install httpretty
pip install pyyaml
pip install pytest-cov
pytest --cov-report xml:code_coverage.xml --cov=src tests/lambda_test.py
- name: Code-coverage
run: |
# Get line-rate
line_rate=$(head -2 code_coverage.xml | tail -1 | egrep -o "line-rate=\"[0-1]\.?[0-9]*\"" | egrep -o "[0-1]\.?[0-9]*")
# Print line-rate
echo | awk -v num=$line_rate '{ printf "line-rate: %d%\n", (num * 100) }'
# Check code-coverage conditions
echo | awk -v num=$line_rate '{ if (num < 0.8) { printf "line-rate is less than 80%"; exit 1 } else { exit 0 }}'
exit_code=$?
if [ $exit_code -eq 1 ]; then
exit 1
fi