Skip to content

Commit 4f8e16b

Browse files
committed
python venv cache support
1 parent a3ed755 commit 4f8e16b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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

+21
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,22 @@ runs:
234239
fi
235240
fi
236241
242+
- if: ${{ inputs.cache == 'true' }}
243+
id: gen-cache-key
244+
shell: python
245+
run: |
246+
import hashlib, os, pathlib
247+
fp = pathlib.Path(os.path.join(os.environ["GITHUB_ACTION_PATH"], 'requirements.txt'))
248+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
249+
print('hash=%s' % (hashlib.sha1(fp.read_bytes()).hexdigest()), file=f)
250+
251+
- uses: actions/cache@v4
252+
if: ${{ inputs.cache == 'true' }}
253+
with:
254+
key: cpp-linter-action-venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ steps.gen-cache-key.outputs.hash }}
255+
restore-keys: cpp-linter-action-venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
256+
path: ${{ github.action_path }}/venv
257+
237258
- name: Setup python venv (Unix)
238259
if: runner.os == 'Linux' || runner.os == 'macOS'
239260
shell: bash

0 commit comments

Comments
 (0)