Skip to content

Commit

Permalink
ci: cache the venv
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioLoayzaM committed May 30, 2024
1 parent 376a5ab commit 44b91fd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 24 deletions.
88 changes: 72 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: main
on: [push]

jobs:
lint:
setup:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
Expand All @@ -13,16 +13,45 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Run the linter
- name: Install dependencies
run: |
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python --version; python -m pip --version
python -m pip install poetry; poetry --version
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
make install
- name: Cache venv
id: cache-venv
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-venv

lint:
runs-on: ubuntu-22.04
needs: [setup]
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Run the linter
run: |
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
make lint-ci
type-check:
runs-on: ubuntu-22.04
needs: [setup]
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -31,12 +60,16 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Run the type-checker
run: |
export PYTHONDONTWRITEBYTECODE=1
python --version; python -m pip --version
python -m pip install poetry; poetry --version
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
make type-check-ci
test:
Expand All @@ -50,13 +83,19 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Run the test suite and coverage
run: |
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
sudo apt-get install -y --no-install-recommends pandoc texlive texlive-latex-extra
make coverage-ci
source .venv/bin/activate
make doctest
docs:
Expand All @@ -70,12 +109,18 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Build the docs
run: |
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
sudo apt-get install -y --no-install-recommends pandoc
source .venv/bin/activate
make docs
upload-docs:
Expand All @@ -90,12 +135,18 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Build docs for publishing
run: |
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
sudo apt-get install -y --no-install-recommends pandoc
source .venv/bin/activate
make pages-ci
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand Down Expand Up @@ -129,11 +180,16 @@ jobs:
with:
python-version: "3.11"
cache: "pip"
- name: Restore venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Build the package
run: |
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDONTWRITEBYTECODE=1; export POETRY_VIRTUALENVS_IN_PROJECT=1
python -m pip install poetry
poetry config virtualenvs.in-project true; poetry install -vv; source `poetry env info --path`/bin/activate
sudo apt-get install -y --no-install-recommends pandoc texlive texlive-latex-extra
make build-ci
- name: Upload build
Expand Down
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ lint: # Format with black and lint with ruff.

lint-ci: # Format with black, lint with ruff, generate report for CI.
@echo "[+] Linting (CI)"
black --check .
ruff check --output-format=github .
poetry run black --check .
poetry run ruff check --output-format=github .

type-check: # Run mypy.
@echo "[+] Type checking"
mypy --config-file pyproject.toml .

type-check-ci: # Run mypy, generate report for CI.
@echo "[+] Type checking (CI)"
mypy --config-file pyproject.toml --junit-xml mypy.xml .
poetry run mypy --config-file pyproject.toml --junit-xml mypy.xml .

.PHONY: import-nist-vectors
import-nist-vectors: # Serialize NIST test vectors with protobuf.
Expand Down Expand Up @@ -86,9 +86,9 @@ coverage: init
coverage-ci: # Run coverage, generate JUnit test report and XML coverage report.
coverage-ci: init
@echo "[+] Testing and checking coverage (CI)"
pytest --verbose --junitxml=junit/test-results.xml --cov="crypto_condor" --cov-report=xml --numprocesses=auto tests/
poetry run pytest --verbose --junitxml=junit/test-results.xml --cov="crypto_condor" --cov-report=xml --numprocesses=auto tests/
# Print coverage report so that CI picks up stats
coverage report
poetry run coverage report

# Separate build target to fully build locally.
build: # Build the package.
Expand All @@ -109,9 +109,8 @@ build-ci: init
publish-ci: # Publish package using the CI pipeline.
publish-ci: init
@echo "[+] Publishing package (CI)"
poetry config repositories.gitlab $(CI_API_V4_URL)/projects/$(CI_PROJECT_ID)/packages/pypi
# JOB_TOKEN is an ephemeral token that is valid while the pipeline is running.
@poetry publish -v --build --repository gitlab --cert $(CI_SERVER_TLS_CA_FILE) -u gitlab-ci-token -p $(CI_JOB_TOKEN)
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry publish -v --build

compile-proto: # Compile .proto files and prints current protoc version.
compile-proto: $(PB2_FILES)
Expand Down

0 comments on commit 44b91fd

Please sign in to comment.