-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce CI usage #83
Reduce CI usage #83
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ env: | |
|
||
jobs: | ||
tests: | ||
name: "${{ matrix.python-version }} on ${{ matrix.os }}" | ||
name: "Test on ${{ matrix.os }}" | ||
runs-on: "${{ matrix.os }}-latest" | ||
|
||
strategy: | ||
|
@@ -31,29 +31,43 @@ jobs: | |
- ubuntu | ||
- macos | ||
- windows | ||
python-version: | ||
- "3.7" | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
- "pypy-3.9" | ||
|
||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v3" | ||
|
||
- name: "Set up Python" | ||
id: "setup-python" | ||
uses: "actions/setup-python@v4" | ||
with: | ||
python-version: "${{ matrix.python-version }}" | ||
cache: pip | ||
cache-dependency-path: 'requirements/*.txt' | ||
# The last listed Python version is the default. | ||
python-version: | | ||
pypy-3.9 | ||
3.7 | ||
3.8 | ||
3.9 | ||
3.10 | ||
3.11 | ||
|
||
- name: "Restore cache" | ||
id: "restore-cache" | ||
uses: "actions/cache@v3" | ||
with: | ||
path: | | ||
.tox/ | ||
.venv/ | ||
key: "cache-python-${{ steps.setup-python.outputs.python-version }}-os-${{ runner.os }}-hash-${{ hashFiles('tox.ini', 'requirements/*.txt') }}" | ||
|
||
- name: "Identify venv path" | ||
shell: "bash" | ||
run: "echo 'venv-path=${{ runner.os == 'Windows' && '.venv/Scripts' || '.venv/bin' }}' >> $GITHUB_ENV" | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This step establishes the relative path to the Python executable and writes it to Although the default shell is specified above to be However, I explicitly included the |
||
|
||
- name: "Install dependencies" | ||
if: "steps.restore-cache.outputs.cache-hit == false" | ||
run: | | ||
python -m pip install -U setuptools | ||
python -m pip install -r requirements/tox.txt | ||
python -m venv .venv | ||
${{ env.venv-path }}/python -m pip install -U setuptools | ||
${{ env.venv-path }}/python -m pip install -r requirements/tox.txt | ||
Comment on lines
65
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This step is expensive, so it only happens when there's a cache miss. A virtual environment is used because it's far easier to cache a virtual environment at a path of our choosing than to try caching items in an OS-specific location. |
||
|
||
- name: "Install pandoc on Linux" | ||
# sudo apt-get pandoc: will install a version from 2018! | ||
|
@@ -72,9 +86,9 @@ jobs: | |
run: | | ||
choco install -y -r --no-progress pandoc | ||
|
||
- name: "Run tox for ${{ matrix.python-version }}" | ||
- name: "Run tox" | ||
run: | | ||
python -m tox | ||
${{ env.venv-path }}/python -m tox -m ci-tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Tox invocation changes from a bare run of Tox (which was intercepted by tox-gh and transformed to a single run of the default test environment) to use Tox 4's new labels. This allows the |
||
|
||
- name: "Upload coverage data" | ||
uses: actions/upload-artifact@v3 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By caching the
.tox/
and.venv/
directories, the virtual environment and the Tox environments can be restored as filesystem operations, rather than as an installation of Python packages.The cache key includes a hash of
tox.ini
and all of therequirements/*.txt
files changes. This ensures that a cache miss occurs if any of those files changes.Note that it may be helpful to modify the cache key in the future. In particular, if the last-listed Python version above ("3.11" currently) doesn't change versions but any of the other versions updates (say, from "3.10.x" to "3.10.y"), then:
py310
test environment.This situation can be improved by adding a step that runs each Python version and writes its exact version to a file. Then, this file could be included in the list of files passed to
hashFiles()
.I haven't learned how to do this yet, so this improvement isn't included. The only thing that will happen in this situation is that Tox has to discard the Python 3.10.x test environment and rebuild it with 3.10.y, so test times will increase until the cache is invalidated by some other means, like when the
requirements/*.txt
files are updated.