Skip to content

Commit 4cef846

Browse files
committed
Try caching virtualenvs in GitHub Actions
1 parent fa7fb74 commit 4cef846

File tree

3 files changed

+49
-195
lines changed

3 files changed

+49
-195
lines changed

.github/workflows/release.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@ on:
55

66
jobs:
77
publish:
8-
name: Deploy release to PyPI
8+
name: Publish release to PyPI
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout source code
12-
uses: actions/checkout@v3
13-
- name: Set up Python
14-
uses: actions/setup-python@v4
12+
uses: actions/checkout@v4
13+
- name: Restore cached virtualenv
14+
id: restore-venv-cache
15+
uses: actions/cache/restore@v4
1516
with:
16-
python-version: 3.9
17-
- name: Install dependencies
18-
run: pip install .
17+
path: ./venv
18+
key: ${{ runner.os }}-3.9-venv-${{ hashFiles('**/pyproject.toml') }}
19+
- name: Build venv
20+
if: steps.restore-venv-cache.outputs.cache-hit != 'true'
21+
run: |
22+
python -m venv ./venv
23+
./venv/bin/python -m pip install .
24+
1925
# [BJ] Shouldn't we run tests here to prevent an easily preventable catastrophe?
2026
# Or is test.yml being ran when we publish a package?
2127
- name: Build package
2228
# [TODO] We need to confirm this produces the same exact result as `python setup.py sdist`
2329
run: python -m build
2430
- name: Publish package to PyPI
25-
uses: pypa/gh-action-pypi-publish@v1.8.10
31+
uses: pypa/gh-action-pypi-publish@v1.12.4
2632
with:
2733
user: __token__
2834
password: ${{ secrets.PYPI_PASSWORD }}
@@ -31,14 +37,13 @@ jobs:
3137
rm -rf ./docs/_build
3238
tox -e docs
3339
- name: Upload docs
34-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
3541
with:
3642
name: python_sdk_docs
3743
path: docs/_build/html
38-
# Test upload
39-
# - name: Publish package to TestPyPI
40-
# uses: pypa/gh-action-pypi-publish@master
41-
# with:
42-
# user: __token__
43-
# password: ${{ secrets.TEST_PYPI_PASSWORD }}
44-
# repository_url: https://test.pypi.org/legacy/
44+
- name: Cache virtualenv
45+
uses: actions/cache/save@v4
46+
if: steps.restore-venv-cache.outputs.cache-hit != 'true'
47+
with:
48+
path: ./venv
49+
key: ${{ steps.restore-venv-cache.outputs.cache-primary-key }}

.github/workflows/test.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,49 @@ jobs:
1616
- "latest"
1717
include:
1818
- os: ubuntu-22.04
19-
python: 3.7
19+
python: 3.9
2020
splunk-version: "9.3"
2121
- os: ubuntu-22.04
22-
python: 3.7
22+
python: 3.9
2323
splunk-version: "9.4"
2424
- os: ubuntu-22.04
25-
python: 3.7
25+
python: 3.9
2626
splunk-version: "latest"
2727
fail-fast: false
2828

2929
steps:
3030
- name: Checkout source code
31-
uses: actions/checkout@v3
31+
uses: actions/checkout@v4
3232
- name: Set up .env
3333
run: cp ./.env.template ./.env
34-
- name: Run docker-compose
34+
- name: Run docker-compose with Splunk v${{ matrix.splunk-version }}
3535
run: SPLUNK_VERSION=${{ matrix.splunk-version }} docker compose up -d
36+
- name: Restore cached virtualenv
37+
id: restore-venv-cache
38+
uses: actions/cache/restore@v4
39+
with:
40+
path: ./venv
41+
key: ${{ runner.os }}-${{ matrix.python }}-venv-${{ hashFiles('**/pyproject.toml') }}
3642
- name: Setup Python ${{ matrix.python }}
37-
uses: actions/setup-python@v4
43+
uses: actions/setup-python@v5
44+
if: steps.restore-venv-cache.outputs.cache-hit != 'true'
3845
with:
3946
python-version: ${{ matrix.python }}
40-
- name: Install dependencies
41-
run: pip install .
47+
48+
- name: Build venv
49+
if: steps.restore-venv-cache.outputs.cache-hit != 'true'
50+
run: |
51+
python -m venv ./venv
52+
./venv/bin/python -m pip install .
4253
- name: Run test suite
4354
run: tox -e py
55+
- name: Cache virtualenv
56+
uses: actions/cache/save@v4
57+
if: steps.restore-venv-cache.outputs.cache-hit != 'true'
58+
with:
59+
path: ./venv
60+
key: ${{ steps.restore-venv-cache.outputs.cache-primary-key }}
4461
# [BJ] I'll obviously uncomment this step after I finish fiddling
45-
# fossa-scan:
46-
# uses: splunk/oss-scanning-public/.github/workflows/oss-scan.yml@main
47-
# secrets: inherit
62+
# fossa-scan:
63+
# uses: splunk/oss-scanning-public/.github/workflows/oss-scan.yml@main
64+
# secrets: inherit

0 commit comments

Comments
 (0)