Skip to content

Commit 2fb378d

Browse files
committed
python venv cache support
1 parent a3ed755 commit 2fb378d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.github/workflows/self-test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
with:
5858
style: file
5959
files-changed-only: false
60+
cache: true
6061
# to ignore all build folder contents
6162
ignore: build|venv
6263
database: build

action.yml

+20
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ inputs:
5555
[re-running jobs or workflows](https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs).
5656
required: false
5757
default: info
58+
cache:
59+
description: |
60+
This controls if the python virtual environment is cached.
61+
required: false
62+
default: false
5863
lines-changed-only:
5964
description: |
6065
This controls what part of the files are analyzed. The following values are accepted:
@@ -234,6 +239,21 @@ runs:
234239
fi
235240
fi
236241
242+
- if: ${{ inputs.cache == 'true' }}
243+
id: gen-cache-key
244+
shell: python {0}
245+
run: |
246+
import hashlib, os, pathlib
247+
bytes = pathlib.Path(os.path.join(os.environ["GITHUB_ACTION_PATH"], 'requirements.txt')).read_bytes()
248+
print('::set-output hash=%s' % (hashlib.sha1(bytes).hexdigest()))
249+
250+
- uses: actions/cache@v4
251+
if: ${{ inputs.cache == 'true' }}
252+
with:
253+
key: cpp-linter-action-venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ steps.gen-cache-key.outputs.hash }}
254+
restore-keys: cpp-linter-action-venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
255+
path: ${{ github.action_path }}/venv
256+
237257
- name: Setup python venv (Unix)
238258
if: runner.os == 'Linux' || runner.os == 'macOS'
239259
shell: bash

0 commit comments

Comments
 (0)