Skip to content

Commit

Permalink
Merge pull request #57 from uclahs-cds/aholmes-cicd-python-version
Browse files Browse the repository at this point in the history
Use a consistent and specific Python version in CI/CD
  • Loading branch information
aholmes authored Mar 27, 2024
2 parents 4a3d291 + b770552 commit 38f38fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
43 changes: 11 additions & 32 deletions .github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
outputs:
cache-key-dependencies: ${{ steps.generate-cache-keys.outputs.cache_key }}
cache-key-run: ${{ steps.generate-cache-keys.outputs.cache_key_run }}
python-version: ${{ steps.install-python.outputs.python-version }}

env:
PYTHON_VERSION: "3.10"
Expand All @@ -61,21 +62,10 @@ jobs:
echo "cache_key_dependencies=$cache_key_dependencies" >> $GITHUB_OUTPUT
echo "cache_key_run=$cache_key_run" >> $GITHUB_OUTPUT
#- name: Restore dependency cache
# if: ${{ success() && (github.event_name != 'workflow_dispatch' || inputs.use_dependency_cache == 'true') }}
# TODO figure out a way to get 3rd party dependencies cached without caching BL_Python ... maybe.
# uses: actions/cache/restore@v4
# id: restore-dependency-cache
# with:
# path: |
# .github-venv
# node_modules
# key: ${{ steps.generate-cache-keys.outputs.cache_key_dependencies }}

- name: Set up Python ${{ env.PYTHON_VERSION }}
- name: Set up Python ${{ steps.generate-cache-keys.outputs.python-version }}
#if: ${{ success() && (inputs.use_dependency_cache == 'false' || !steps.restore-dependency-cache.outputs.cache-hit) }}
uses: actions/setup-python@v5
id: install_python
id: install-python
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand All @@ -90,17 +80,6 @@ jobs:
echo 'prefix=${{ github.workspace }}/node_modules' >> ~/.npmrc
npm install -g pyright@`pyright --version | awk '{print $2}'`
# TODO see note above about 3rd party dependencies.
#- name: Save dependency cache
# if: ${{ success() && !steps.restore-dependency-cache.outputs.cache-hit }}
# uses: actions/cache/save@v4
# id: save-dependency-cache
# with:
# path: |
# .github-venv
# node_modules
# key: ${{ steps.generate-cache-keys.outputs.cache_key_dependencies }}

- name: Save run cache
uses: actions/cache/save@v4
id: save-run-cache
Expand All @@ -115,14 +94,14 @@ jobs:
- Checkout

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: ${{ needs.Checkout.outputs.python-version }}

if: ${{( success() && !cancelled() ) }}

steps:
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
id: install_python
id: install-python
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -150,14 +129,14 @@ jobs:
- Checkout

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: ${{ needs.Checkout.outputs.python-version }}

if: ${{( success() && !cancelled() ) }}

steps:
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
id: install_python
id: install-python
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -198,7 +177,7 @@ jobs:
- Checkout

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: ${{ needs.Checkout.outputs.python-version }}

if: ${{( success() && !cancelled() ) }}

Expand All @@ -208,7 +187,7 @@ jobs:
steps:
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
id: install_python
id: install-python
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -250,14 +229,14 @@ jobs:
- Checkout

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: ${{ needs.Checkout.outputs.python-version }}

if: ${{( success() && !cancelled() ) }}

steps:
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
id: install_python
id: install-python
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down
24 changes: 1 addition & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ endif


ACTIVATE_VENV := . $(VENV)/bin/activate
PREFIX_VENV := PATH=$(CURDIR)/$(VENV)/bin:$$PATH
REPORT_VENV_USAGE := echo '\nActivate your venv with `. $(VENV)/bin/activate`'

PACKAGE_INSTALL_DIR := $(VENV)/lib/python*/site-packages/BL_Python
Expand Down Expand Up @@ -82,11 +81,9 @@ _dev_build : _dev_configure
else
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
pip install -e .[dev-dependencies]
# By default, psycopg2 is not installed
# but it should be for development
$(PREFIX_VENV) \
pip install -e src/database[postgres-binary]

rm -rf $(PACKAGE_INSTALL_DIR)
Expand All @@ -103,11 +100,9 @@ _cicd_build : _cicd_configure
else
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
pip install .[dev-dependencies]
# By default, psycopg2 is not installed
# but it should be for CI/CD
$(PREFIX_VENV) \
pip install src/database[postgres-binary]
fi

Expand All @@ -120,10 +115,8 @@ $(PACKAGES) : BL_Python.%: src/%/pyproject.toml $(VENV) $(CONFIGURE_TARGET) $(PY
$(ACTIVATE_VENV)

if [ "$@" = "BL_Python.database" ]; then
$(PREFIX_VENV) \
pip install -e $(dir $<)[postgres-binary]
else
$(PREFIX_VENV) \
pip install -e $(dir $<)
fi

Expand All @@ -137,19 +130,17 @@ SETUP_DEPENDENCIES=$(call dep_to_venv_path,toml/__init__.py) $(call dep_to_venv_
$(call dep_to_venv_path,toml/__init__.py): $(VENV)
$(ACTIVATE_VENV)

$(PREFIX_VENV) pip install toml
pip install toml

$(call dep_to_venv_path,typing_extensions.py): $(VENV)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
pip install typing_extensions

$(PACKAGE_PATHS) : $(VENV) $(SETUP_DEPENDENCIES)
$(PYPROJECT_FILES) : $(VENV) $(SETUP_DEPENDENCIES)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
REWRITE_DEPENDENCIES=$(REWRITE_DEPENDENCIES) \
GITHUB_REF=$(GITHUB_REF) \
GITHUB_WORKSPACE=$(GITHUB_WORKSPACE) \
Expand All @@ -159,25 +150,19 @@ $(PYPROJECT_FILES) : $(VENV) $(SETUP_DEPENDENCIES)
$(VENV) :
test -d $(VENV) || env python$(PYTHON_VERSION) -m venv $(VENV)

# fix Python symlink that is wrong on GitHub Actions for some reason
ln -sf $(which python$(PYTHON_VERSION)) $(VENV)/bin/python$(PYTHON_VERSION)

$(ACTIVATE_VENV)

$(PREFIX_VENV) \
pip install -U pip


format-isort : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
isort src

format-ruff : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
ruff format --preview --respect-gitignore

format : $(VENV) $(BUILD_TARGET) format-isort format-ruff
Expand All @@ -186,20 +171,17 @@ format : $(VENV) $(BUILD_TARGET) format-isort format-ruff
test-isort : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
isort --check-only src

test-ruff : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
ruff format --preview --respect-gitignore --check

test-pyright : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

ifeq "$(PYRIGHT_MODE)" "pip"
$(PREFIX_VENV) \
pyright
else
ifeq "$(PYRIGHT_MODE)" "npm"
Expand All @@ -215,7 +197,6 @@ test-pyright : $(VENV) $(BUILD_TARGET)
test-bandit : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
bandit -c pyproject.toml \
--format sarif \
--output $(BANDIT_REPORT) \
Expand All @@ -228,10 +209,8 @@ test-bandit : $(VENV) $(BUILD_TARGET)
test-pytest : $(VENV) $(BUILD_TARGET)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
pytest $(PYTEST_FLAGS)

$(PREFIX_VENV) \
coverage html -d coverage

test : CMD_PREFIX=@
Expand All @@ -243,7 +222,6 @@ publish-all : REWRITE_DEPENDENCIES=false
publish-all : reset $(VENV)
$(ACTIVATE_VENV)

$(PREFIX_VENV) \
./publish_all.sh $(PYPI_REPO)


Expand Down

0 comments on commit 38f38fd

Please sign in to comment.