Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mambaforge in setup-conda #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 21 additions & 4 deletions .github/workflows/setup-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
pull_request:
branches: [ main ]

# Cancel previous runs that have not completed
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
conda:
strategy:
Expand All @@ -24,6 +29,9 @@ jobs:
- os: windows-latest
conda: anaconda
anaconda-version: "2019.03"
- os: windows-latest
conda: mambaforge
anaconda-version: "latest"

fail-fast: false

Expand All @@ -32,14 +40,22 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup anaconda (defaults)
if: matrix.conda == 'anaconda'
uses: ./setup-conda
with:
# NB no "installer:" key → test that default is used
version: ${{ matrix.anaconda-version}}
installer: ${{ matrix.conda }}

- name: Setup mambaforge (latest)
id: install-mamba
if: matrix.conda == 'mambaforge'
uses: ./setup-conda
with:
installer: ${{ matrix.conda }}
version: latest

- name: Setup miniconda (py39_4.10.3)
if: matrix.conda == 'miniconda'
Expand All @@ -48,5 +64,6 @@ jobs:
installer: ${{ matrix.conda }}
version: py39_4.10.3

- name: Check conda version and location
run: conda info
- name: Check mamba version and location
if: matrix.conda == 'mambaforge'
run: ${{ steps.install-mamba.cmd }} info
11 changes: 7 additions & 4 deletions setup-conda/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Install Anaconda or Miniconda"

inputs:
installer:
description: "Installer to use"
description: "Installer to use: one of anaconda, mambaforge, or miniconda"
required: true
default: "anaconda"
version:
Expand All @@ -13,8 +13,11 @@ inputs:

outputs:
cache-path:
description: "Path to the conda installer, e.g. for use with actions/cache."
description: "Path to the installer, e.g. for use with actions/cache."
value: ${{ steps.install.outputs.cache-path }}
cmd:
description: "Executable name of the installed package manager: 'conda' or 'mamba'."
value: ${{ steps.install.outputs.cmd }}

runs:
using: composite
Expand All @@ -27,6 +30,6 @@ runs:
run: ${GITHUB_ACTION_PATH}/script.sh
shell: bash

- name: Confirm installed conda is on PATH
run: conda info
- name: Confirm installed package manager is on PATH
run: ${{ steps.install.outputs.cmd }} info
shell: bash
24 changes: 17 additions & 7 deletions setup-conda/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ pushd "$GITHUB_ACTION_PATH" || exit
# - a URL_FRAGMENT used in the download URL
case $INSTALLER in
anaconda)
INSTALLER_TYPE="Anaconda3"
URL_FRAGMENT="archive"
INSTALLER_TYPE="Anaconda3-${VERSION}"
BASE_URL="https://repo.anaconda.com/archive"
CMD="conda"
;;
mambaforge)
INSTALLER_TYPE="Mambaforge"
BASE_URL="https://github.com/conda-forge/miniforge/releases/${VERSION}/download"
CMD="mamba"
;;
miniconda)
INSTALLER_TYPE="Miniconda3"
URL_FRAGMENT="miniconda"
INSTALLER_TYPE="Miniconda3-${VERSION}"
BASE_URL="https://repo.anaconda.com/miniconda"
CMD="conda"
;;
*)
echo "::error::'installer:' must be one of (anaconda, miniconda); got '$INSTALLER'"
echo "::error::'installer:' must be one of (anaconda, mambaforge, miniconda); got '$INSTALLER'"
exit 1
esac

Expand Down Expand Up @@ -51,7 +58,7 @@ esac
OS=$(echo "$RUNNER_OS" | sed "s/macOS/MacOSX/")

# URL for installer
URL="https://repo.anaconda.com/$URL_FRAGMENT/${INSTALLER_TYPE}-${VERSION}-${OS}-x86_64.${EXT}"
URL="${BASE_URL}/${INSTALLER_TYPE}-${OS}-x86_64.${EXT}"

# curl --time-cond only works if the named file exists
if [ -x "conda.$EXT" ]; then
Expand All @@ -61,7 +68,7 @@ fi

# Download installer
echo "Download from: $URL"
curl --silent "$URL" --output "conda.$EXT" $TIME_CONDITION
curl --location --silent "$URL" --output "conda.$EXT" $TIME_CONDITION

# Run the installer
# - Run in batch/silent mode ("-b" on *nix, "/S" on Windows), accept the licence
Expand All @@ -86,5 +93,8 @@ esac
# Windows, because this is what GHA expects.
echo "$GITHUB_ACTION_PATH/$INSTALLER_TYPE/$BINDIR" >> "$GITHUB_PATH"

# Write an output value for subsequent steps
echo "cmd=$CMD" >> $GITHUB_OUTPUT

# Return to the last directory
popd || exit