Skip to content

Commit

Permalink
ci: adjust setup-envs action to cache default venv and ignore pyr…
Browse files Browse the repository at this point in the history
…ight warning
  • Loading branch information
WSH032 committed Dec 31, 2023
1 parent 8fb597b commit 80714d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
63 changes: 34 additions & 29 deletions .github/actions/setup-envs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |
Setup and cache deps envs for hatch and pre-commit.
will:
`pip install -r requirements.txt -U`
cache hatch venv
cache pre-commit venv
NOTE: `setup-python` first.
create and cache hatch venv
create and cache pre-commit venv
NOTE: use `setup-python` first
inputs:
python-version:
Expand Down Expand Up @@ -51,26 +51,20 @@ runs:
env:
CACHE_VERSION: v1
with:
# Don't cache `.venv-default`, re-creat it instead.
# Because we can't use `==` to constraint the version of deps,
# resulting in cache not being up-to-date
path: |
./.venv-docs
./.venv-fmt
key:
# `v1` is the version of this cache key
"\
hatch-venv-\
${{ runner.os }}-\
${{ env.CACHE_VERSION }}-\
./.venv-default
key: "\
hatch-venv-${{ runner.os }}-${{ env.CACHE_VERSION }}-\
python${{ inputs.python-version }}-\
${{ inputs.python-path }}-\
${{ hashFiles('pyproject.toml', 'requirements.txt') }}\
"
restore-keys: hatch-venv-${{ runner.os }}-
restore-keys: hatch-venv-${{ runner.os }}-${{ env.CACHE_VERSION }}-

# cache pre-commit venv
# ref: https://github.com/pre-commit/action/blob/c7d159c2092cbfaab7352e2d8211ab536aa2267c/action.yml
# modified from: https://github.com/pre-commit/action/blob/c7d159c2092cbfaab7352e2d8211ab536aa2267c/action.yml
# https://pre-commit.com/#github-actions-example
- name: cache pre-commit venv
uses: actions/cache@v3
Expand All @@ -80,32 +74,43 @@ runs:
CACHE_VERSION: v1
with:
path: ~/.cache/pre-commit
key:
# `v1` is the version of this cache key
"\
pre-commit-3-\
${{ runner.os }}-\
${{ env.CACHE_VERSION }}-\
key: "\
pre-commit-3-${{ runner.os }}-${{ env.CACHE_VERSION }}-\
python${{ inputs.python-version }}-\
${{ inputs.python-path }}-\
${{ hashFiles('.pre-commit-config.yaml') }}\
"
restore-keys: pre-commit-3-${{ runner.os }}-
restore-keys: pre-commit-3-${{ runner.os }}-${{ env.CACHE_VERSION }}-

# Create hatch venv
# required by first running of pre-commit local system hooks,
# required before first running of pre-commit local system hooks,
# read `#Environment setup` in `CONTRIBUTING.md` for more info
# We don't create `docs` env, because it's not used in pre-commit hooks
- name: create hatch venv
shell: bash
# NOTE: Do not run `hatch shell <env>` to enter another shell,
# wiil crash github workflow on ubuntu
run: |
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
hatch env create default
hatch run default:pip freeze --local
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
hatch env create fmt
- name: |
init pyright-python to avoid `npm ERR! code ENOTEMPTY`
Issue: https://github.com/RobertCraigie/pyright-python/issues/200
hatch run fmt:pip freeze --local
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
hatch env create docs
hatch run docs:pip freeze --local
# init pyright-python to avoid `npm ERR! code ENOTEMPTY`
# Issue: https://github.com/RobertCraigie/pyright-python/issues/200
- name: init pyright-python
shell: bash
# Ignore warnings to improve performance
# https://github.com/RobertCraigie/pyright-python?tab=readme-ov-file#ignore-warnings
# Set env var in github workflow
# ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-writing-an-environment-variable-to-github_env
run: |
hatch run pyright --help
echo "PYRIGHT_PYTHON_IGNORE_WARNINGS=1" >> "$GITHUB_ENV"
hatch run default:pyright --help
# NOTE: Do not run `hatch shell <env>` to enter another shell,
# which wiil crash github workflow on ubuntu
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ Then, initialize the env with:

```shell
# https://hatch.pypa.io/latest/environment/
# Note: Create hatch venv before running pre-commit
# IMPORTANT: Create hatch venv before running pre-commit
hatch env create default
hatch env create fmt
hatch shell default
hatch env create docs

# IMPORTANT: init pyright-python before running pre-commit
# issue: https://github.com/RobertCraigie/pyright-python/issues/200
hatch run default:pyright --help

# Init pre-commit
# https://pre-commit.com/#3-install-the-git-hook-scripts
pre-commit install
pre-commit run --all-files

# enter the dev environment
hatch shell default
```

That's all! Now, you can start to develop.
Expand Down

0 comments on commit 80714d6

Please sign in to comment.