Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions .github/actions/setup-miniconda/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inputs:
required: false
type: string
default: ""
pip-requirements-file:
description: An optional pip requirements file to be installed in the conda environment
required: false
type: string
default: ""

runs:
using: composite
Expand All @@ -32,7 +37,7 @@ runs:

- name: Setup miniconda cache
id: miniconda-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ runner.temp }}/miniconda
key: miniconda-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
Expand Down Expand Up @@ -71,36 +76,40 @@ runs:
MINICONDA_INSTALL_PATH="${RUNNER_TEMP}/miniconda"
echo "${MINICONDA_INSTALL_PATH}/bin" >> $GITHUB_PATH

- name: Setup miniconda env cache (with env file)
id: miniconda-env-cache-env-file
if: inputs.environment-file != ''
uses: actions/cache@v2
with:
path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles(inputs.environment-file) }}

- name: Setup miniconda env cache (without env file)
# When the environment-file or pip-requirements-file inputs are not set or are set to invalid paths, the hashFiles
# function will return an empty string without failing the step. This works out nicely and we can have a various
# combination of cache key such as:
# - Both are missing or invalid: miniconda-env-macOS-ARM64-20221022d--
# - Both are set: miniconda-env-macOS-ARM64-20221022d-HASH(environment-file)-HASH(pip-requirements-file)
# - The first one is missing or invalid: miniconda-env-macOS-ARM64-20221022d--HASH(pip-requirements-file)
# - The second one is missing or invalid: miniconda-env-macOS-ARM64-20221022d-HASH(environment-file)-
#
# There is no need to skip or run actions/cache with complicated logic
- name: Setup miniconda env cache
id: miniconda-env-cache
if: inputs.environment-file == ''
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles(inputs.environment-file) }}-${{ hashFiles(inputs.pip-requirements-file) }}

- name: Setup conda environment with python (v${{ inputs.python-version }})
if: (steps.miniconda-env-cache-env-file.outcome == 'success' && steps.miniconda-env-cache-env-file.outputs.cache-hit != 'true') || (steps.miniconda-env-cache.outcome == 'success' && steps.miniconda-env-cache.outputs.cache-hit != 'true')
if: steps.miniconda-env-cache.outcome == 'success' && steps.miniconda-env-cache.outputs.cache-hit != 'true'
shell: bash
env:
PYTHON_VERSION: ${{ inputs.python-version }}
ENV_FILE: ${{ inputs.environment-file }}
PIP_REQUIREMENTS_FILE: ${{ inputs.pip-requirements-file }}
run: |
set -x

CONDA_BASE_ENV="${RUNNER_TEMP}/conda-python-${PYTHON_VERSION}"
ENV_FILE_FLAG=""
if [[ -f "${ENV_FILE}" ]]; then
ENV_FILE_FLAG="--file ${ENV_FILE}"
elif [[ -n "${ENV_FILE}" ]]; then
echo "::warning::Specified env file (${ENV_FILE}) not found, not going to include it"
fi

conda create \
--yes \
--prefix "${CONDA_BASE_ENV}" \
Expand All @@ -112,6 +121,12 @@ runs:
pkg-config=0.29 \
wheel=0.37

if [[ -f "${PIP_REQUIREMENTS_FILE}" ]]; then
conda run -p "${CONDA_BASE_ENV}" --no-capture-output python3 -mpip install -r "${PIP_REQUIREMENTS_FILE}"
elif [[ -n "${PIP_REQUIREMENTS_FILE}" ]]; then
echo "::warning::Specified pip requirements file (${PIP_REQUIREMENTS_FILE}) not found, not going to include it"
fi

- name: Clone the base conda environment and update GitHub env
shell: bash
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-setup-miniconda-pip-requirements-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Just a dummy file to test miniconda setup
rockset
6 changes: 5 additions & 1 deletion .github/workflows/test-setup-miniconda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ jobs:
env-file:
- ""
- "./.github/workflows/test-setup-miniconda-env-file"
name: ${{ matrix.runner-type }}-py${{ matrix.python-version }}
pip-requirements-file:
- ""
- "./.github/workflows/test-setup-miniconda-pip-requirements-file"
name: ${{ matrix.runner-type }}-py${{ matrix.python-version }}-${{ matrix.env-file }}-${{ matrix.pip-requirements-file }}
runs-on: ${{ matrix.runner-type }}
# If a build is taking longer than 60 minutes on these runners we need
# to have a conversation
Expand All @@ -45,6 +48,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
environment-file: ${{ matrix.env-file }}
pip-requirements-file: ${{ matrix.pip-requirements-file }}

- name: Can use ${CONDA_RUN}, outputs correct python version
run: |
Expand Down