Tests and CI #4
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: CI | |
on: | |
push: | |
branches: [development] | |
pull_request: | |
branches: [development] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Cache Poetry and dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/pypoetry | |
.venv | |
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: | | |
${{ runner.os }}-poetry- | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Install dependencies | |
run: | | |
poetry install --no-interaction --with dev | |
- name: Update Pinecone | |
run: | | |
poetry add pinecone-client@latest | |
poetry install | |
- name: Display installed packages | |
run: | | |
poetry show | |
- name: Run unit tests with coverage report | |
run: | | |
poetry run python -m pytest -v --cov=./src --cov-report term-missing:skip-covered tests | |
- name: Check coverage is at least 60% | |
run: | | |
poetry run coverage report -m | |
COVERAGE=$(poetry run coverage report -m | grep -Po '^TOTAL.*\s(\d+%)$' | awk '{sub("%", "", $NF); print $NF}') | |
echo "Coverage is $COVERAGE%" | |
if [ "$COVERAGE" -lt "60" ]; then | |
exit 1 | |
fi | |
- name: Python Semantic Release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
pip install python-semantic-release | |
git config user.name github-actions | |
git config user.email [email protected] | |
semantic-release version | |
semantic-release publish | |
- name: Check if release was created | |
id: check-release | |
run: | | |
if [ -n "$(git tag --points-at HEAD)" ]; then | |
echo "RELEASE_CREATED=true" >> $GITHUB_ENV | |
else | |
echo "RELEASE_CREATED=false" >> $GITHUB_ENV | |
fi | |
- name: Merge development into main if release created | |
if: ${{ env.RELEASE_CREATED == 'true' }} | |
run: | | |
git checkout main | |
git merge --ff-only development | |
git push origin main |