Skip to content

Commit

Permalink
Create a basic continuous integration process (#3)
Browse files Browse the repository at this point in the history
* Create a basic continuous integration setup

* Move .env file creation back to test setup

* Run system tests in a shell script

* Add CI badge to README

* Remove unused test code

* Update shell system tests

* Remove unused tests for now

* Clean up workflow file

* Install plugin from local

* Pluralize test

* Remove build on push for this branch

This was really just here for debugging while creating an initial
workflow.

* Remove pytest config since we're not using it
  • Loading branch information
mpeteuil committed Jun 13, 2021
1 parent 6fdbe14 commit da36fc4
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 3 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Heavily based on the Poetry main Github Actions workflow
# https://github.com/python-poetry/poetry/blob/1.2.0a1/.github/workflows/main.yml

name: "CI"
on:
push:
branches:
- main
pull_request:
branches:
- '**'

jobs:
tests:
name: ${{ matrix.os }} / ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [Ubuntu, MacOS]
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2

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

- name: Get full Python version
id: full-python-version
shell: bash
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Install poetry
shell: bash
run: curl -sL https://raw.githubusercontent.com/python-poetry/poetry/1.2.0a1/install-poetry.py | python - -y --preview

- name: Update PATH
shell: bash
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Configure poetry
shell: bash
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v2
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
shell: bash
run: poetry install --no-root

- name: Install poetry-dotenv-plugin
shell: bash
run: poetry plugin add "$GITHUB_WORKSPACE"

- name: Run system tests
shell: bash
run: tests/test_system.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Poetry Dotenv Plugin

[![CI](https://github.com/mpeteuil/poetry-dotenv-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/mpeteuil/poetry-dotenv-plugin/actions/workflows/build.yml)

A [Poetry](https://python-poetry.org/) plugin that automatically loads environment variables from `.env` files into the environment before poetry commands are run.

Supports Python 3.6+
Expand Down
3 changes: 0 additions & 3 deletions tests/test_poetry_dotenv_plugin.py

This file was deleted.

81 changes: 81 additions & 0 deletions tests/test_system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

function create_dotenv_file() {
# Setup .env file so the plugin can do its job
echo "export MY_ENV_VAR='foo'" > .env
}

function delete_dotenv_file() {
# Tear down .env file since we no longer need it
rm -f .env
}

function test_end_to_end_system_with_default_dotenv_file() {
# Setup
local expected
expected='foo'
create_dotenv_file

local output
output=$(poetry run python -c "import os; print(os.environ['MY_ENV_VAR'])")

# Cleanup
delete_dotenv_file

if [ "$expected" = "$output" ]; then
printf "test_end_to_end_system_with_default_dotenv_file: PASSED\n"
else
printf "Expected '$expected', but got '%s'.\n" "$output"
exit 1
fi
}

function test_end_to_end_system_with_dotenv_location_override() {
# Setup
local expected
expected='bar'
local new_dotenv_path
new_dotenv_path="$PWD/tests/tmp"
create_dotenv_file

# Override the file that was just created
mkdir -p "$new_dotenv_path" && echo "export MY_ENV_VAR='bar'" > "$new_dotenv_path/.env"

local output
output=$(export POETRY_DOTENV_LOCATION="$new_dotenv_path/.env" && poetry run python -c "import os; print(os.environ['MY_ENV_VAR'])")

# Cleanup
rm -rf "$new_dotenv_path"
delete_dotenv_file

if [ "$expected" = "$output" ]; then
printf "test_end_to_end_system_with_dotenv_location_override: PASSED\n"
else
printf "Expected '$expected', but got '%s'.\n" "$output"
exit 1
fi
}

function test_end_to_end_system_without_loading_dotenv_file() {
# Setup
local expected
expected='Nonexistent Variable'
create_dotenv_file

local output
output=$(export POETRY_DONT_LOAD_ENV=true && poetry run python -c "import os; print(os.environ.get('MY_ENV_VAR', '$expected'))")

# Cleanup
delete_dotenv_file

if [ "$expected" = "$output" ]; then
printf "test_end_to_end_system_without_loading_dotenv_file: PASSED\n"
else
printf "Expected '$expected', but got '%s'.\n" "$output"
exit 1
fi
}

test_end_to_end_system_with_default_dotenv_file
test_end_to_end_system_with_dotenv_location_override
test_end_to_end_system_without_loading_dotenv_file

0 comments on commit da36fc4

Please sign in to comment.