Skip to content

Commit

Permalink
Remove use of syphar/restore-virtualenv (#6875)
Browse files Browse the repository at this point in the history
Use regular `setup-python`'s caching capabilities in tandem with
`pip-compile`.
  • Loading branch information
elprans authored Feb 18, 2024
1 parent a1cede1 commit a93a09d
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 339 deletions.
85 changes: 44 additions & 41 deletions .github/workflows.src/tests.inc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% macro _init() -%>
<% macro init() -%>
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -13,38 +13,31 @@
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
<%- endmacro %>

<% macro _init_venv() -%>
- name: Handle virtualenv
uses: syphar/restore-virtualenv@v1
id: venv-cache
with:
requirement_files: |
setup.py
cache: 'pip'
cache-dependency-path: |
pyproject.toml
custom_cache_key_element: v2
<%- endmacro -%>
<% macro build() %>
<< _init() >>
<%- endmacro %>

# Build virtualenv
<% macro build() %>
<< init() >>

<< _init_venv() >>
- name: Cached requirements.txt
uses: actions/cache@v4
id: requirements-cache
with:
path: requirements.txt
key: edb-requirements-${{ hashFiles('pyproject.toml') }}

- name: Install Python dependencies
if: steps.venv-cache.outputs.cache-hit != 'true'
shell: bash
- name: Compute requirements.txt
if: steps.requirements-cache.outputs.cache-hit != 'true'
run: |
set -e
python -m pip install -U pip setuptools wheel build
bdeps_script="import build; print('\n'.join(build.ProjectBuilder('.').build_system_requires))"
readarray -t build_deps < <(python -c "${bdeps_script}")
python -m pip download --dest=$VIRTUAL_ENV/deps "${build_deps[@]}" .[test]
python -m pip install -U --no-index --find-links=$VIRTUAL_ENV/deps $VIRTUAL_ENV/deps/*
python -m pip install pip-tools
pip-compile --no-strip-extras --all-build-deps --extra test \
--output-file requirements.txt pyproject.toml
# Prepare environment variables and shared artifacts
- name: Install Python dependencies
run: python -m pip install -U -r requirements.txt

<< caller() >>

Expand Down Expand Up @@ -259,19 +252,13 @@
# Install edgedb-server and populate egg-info

- name: Install edgedb-server and populate egg-info
- name: Install edgedb-server
env:
CACHE_HIT: ${{ steps.venv-cache.outputs.cache-hit }}
BUILD_EXT_MODE: skip
run: |
if [[ "$CACHE_HIT" == "true" ]]; then
rsync -av $VIRTUAL_ENV/edgedb_server.egg-info/ ./edgedb_server.egg-info/
else
# --no-build-isolation because we have explicitly installed all deps
# and don't want them to be reinstalled in an "isolated env".
pip install --no-build-isolation --no-deps -e .[test,docs]
rsync -av ./edgedb_server.egg-info/ $VIRTUAL_ENV/edgedb_server.egg-info/
fi
# --no-build-isolation because we have explicitly installed all deps
# and don't want them to be reinstalled in an "isolated env".
pip install --no-build-isolation --no-deps -e .[test,docs]
# Refresh the bootstrap cache

Expand Down Expand Up @@ -306,10 +293,20 @@
echo BUILD_TEMP=$(python setup.py -q ci_helper --type build_temp) >> $GITHUB_ENV
<%- endmacro %>

<% macro restore_cache() %>
<< _init() >>
<% macro install_python_requirements() %>
- name: Download requirements.txt
uses: actions/cache@v4
with:
path: requirements.txt
key: edb-requirements-${{ hashFiles('pyproject.toml') }}

- name: Install Python dependencies
run: python -m pip install -U -r requirements.txt
<%- endmacro %>

<< _init_venv() >>
<% macro restore_cache() %>
<< init() >>
<< install_python_requirements() >>

# Restore the artifacts and environment variables

Expand Down Expand Up @@ -382,7 +379,6 @@

- name: Stop if we cannot retrieve the cache
if: |
steps.venv-cache.outputs.cache-hit != 'true' ||
steps.cli-cache.outputs.cache-hit != 'true' ||
steps.rust-cache.outputs.cache-hit != 'true' ||
steps.ext-cache.outputs.cache-hit != 'true' ||
Expand All @@ -401,7 +397,14 @@
rsync -av ./build/extensions/edb/ ./edb/
rsync -av ./build/lib/edb/ ./edb/
cp build/postgres/install/stamp build/postgres/
rsync -av $VIRTUAL_ENV/edgedb_server.egg-info/ ./edgedb_server.egg-info/
- name: Install edgedb-server
env:
BUILD_EXT_MODE: skip
run: |
# --no-build-isolation because we have explicitly installed all deps
# and don't want them to be reinstalled in an "isolated env".
pip install --no-build-isolation --no-deps -e .[test,docs]
<%- endmacro %>

<% macro setup_terraform() -%>
Expand Down
28 changes: 3 additions & 25 deletions .github/workflows.src/tests.tpl.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% from "tests.inc.yml" import build, calc_cache_key, restore_cache -%>
<% from "tests.inc.yml" import init, build, calc_cache_key, install_python_requirements, restore_cache -%>
name: Tests

on:
Expand Down Expand Up @@ -38,30 +38,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'

- name: Handle virtualenv
uses: syphar/[email protected]
id: venv-cache
with:
requirement_files: |
setup.py
pyproject.toml
custom_cache_key_element: v2

- name: Stop if we cannot retrieve the cache
if: steps.venv-cache.outputs.cache-hit != 'true'
run: |
echo ::error::Cannot retrieve venv cache.
exit 1
<< init() >>
<< install_python_requirements() >>

- name: Download cache key
uses: actions/download-artifact@v4
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.yml -diff -merge
*.yml linguist-generated=true
77 changes: 38 additions & 39 deletions .github/workflows/tests-ha.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a93a09d

Please sign in to comment.