Skip to content

Commit

Permalink
Remove The Environment Configuration In Favor of Using Default Caches
Browse files Browse the repository at this point in the history
Removes the manual management of the python configuration and
environment variables in favor of using virtualenvs, and the caching
them appropriately.

The virtualenv bin folder is added to the GITHUB_PATH to make it easily
accessible in the rest of the workflow.

Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
  • Loading branch information
HassanAbouelela committed Sep 6, 2022
1 parent 6c6a35b commit 585451a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test_setup_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ jobs:
- name: Check Cache Content
run: |
if ! command -v mypy; then
echo "Expected mypy to be installed in the cache, was not found."
exit 1
fi
if command -v black; then
echo "Black was installed in an incorrect context."
exit 1
Expand Down
32 changes: 9 additions & 23 deletions setup-python/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,9 @@ runs:
# Checkout the code to get access to project files such as poetry and pre-commit configs
- uses: actions/checkout@v2

- name: Setup Python Settings
shell: bash
run: |
# Configure pip to cache dependencies and do a user install
echo "PIP_NO_CACHE_DIR=false" >> $GITHUB_ENV
echo "PIP_USER=1" >> $GITHUB_ENV
# Make sure package manager does not use virtualenv
echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV
# Specify explicit paths for python dependencies and the pre-commit
# environment, so we know which directories to cache
echo "POETRY_CACHE_DIR=${{ github.workspace }}/.cache/py-user-base" >> $GITHUB_ENV
echo "PRE_COMMIT_HOME=${{ github.workspace }}/.cache/pre-commit-cache" >> $GITHUB_ENV
USERBASE=${{ github.workspace }}/.cache/py-user-base
echo "PYTHONUSERBASE=$USERBASE" >> $GITHUB_ENV
echo "$USERBASE/bin" >> $GITHUB_PATH
# Install python in our workflow
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
id: python_setup
with:
python-version: ${{ inputs.python_version }}
Expand All @@ -72,7 +53,7 @@ runs:
uses: actions/cache@v2
id: python_cache
with:
path: ${{ env.PYTHONUSERBASE }}
path: ~/.cache/pypoetry
key: "python-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
v1.2.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}\
Expand All @@ -82,7 +63,7 @@ runs:
- name: Pre-commit Environment Caching
uses: actions/cache@v2
with:
path: ${{ env.PRE_COMMIT_HOME }}
path: ~/.cache/pre-commit
key: "precommit-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
v1.2.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}\
Expand All @@ -103,7 +84,7 @@ runs:
fi
echo "::group::Install Poetry"
pip install poetry==1.1.*
pip install poetry
echo "::endgroup::"
echo "::group::Install Dependencies"
Expand All @@ -115,3 +96,8 @@ runs:
poetry install ${{ inputs.install_args }} --no-dev
fi
echo "::endgroup::"
- name: Configure Path
shell: bash
run: |
echo "$(poetry env info --path)/bin" >> $GITHUB_PATH

0 comments on commit 585451a

Please sign in to comment.