Skip to content

Commit

Permalink
Add 'no-implicit-channels' setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Sep 28, 2024
1 parent 8f65dda commit 32935f2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/example-14.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "Example 14: Remove implicitly added channels"

on:
pull_request:
branches:
- "*"
push:
branches:
- "develop"
- "main"
- "master"
schedule:
# Note that cronjobs run on master/main by default
- cron: "0 0 * * *"

concurrency:
group:
${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
example-14:
# prevent cronjobs from running on forks
if:
(github.event_name == 'schedule' && github.repository ==
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')
name: Ex14 (${{ matrix.os }}, ${{ matrix.no-implicit-channels }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
no-implicit-channels: [true, false]
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: ./
id: setup-miniconda
continue-on-error: true
with:
channels: conda-forge
python-version: "3.12"
no-implicit-channels: ${{ matrix.no-implicit-channels }}
- shell: bash -el {0}
run: |
channels=$(conda config --show channels --json | jq -r '.channels | join(",")')
if [[ "${{ matrix.no-implicit-channels }}" == "true" ]]; then
if [[ "$channels" != "conda-forge" ]]; then
exit 1
fi
elif [[ "$channels" != "conda-forge,defaults" ]]; then
exit 1
fi
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ inputs:
for more information."
required: false
default: ""
no-implicit-channels:
description:
"Postprocess channels list to remove channels that were not added
explicitly in the 'channels' setting. Will default to 'true' in 2025.03."
required: false
default: ""
show-channel-urls:
description:
'Conda configuration. Show channel URLs when displaying what is going to
Expand Down
10 changes: 10 additions & 0 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47287,6 +47287,15 @@ function applyCondaConfiguration(inputs, options) {
core.info(`Adding channel '${channel}'`);
yield condaCommand(["config", "--add", "channels", channel], options);
}
if (inputs.noImplicitChannels && !channels.includes("defaults")) {
core.info("Removing implicitly added 'defaults' channel");
try {
yield condaCommand(["config", "--remove", "channels", "defaults"], options);
}
catch (err) {
core.info("Removing defaults raised an error -- it was probably not present.");
}
}
// All other options are just passed as their string representations
for (const [key, value] of configEntries) {
if (value.trim().length === 0 || key === "channels") {
Expand Down Expand Up @@ -48115,6 +48124,7 @@ function parseInputs() {
minicondaVersion: core.getInput("miniconda-version"),
miniforgeVariant: core.getInput("miniforge-variant"),
miniforgeVersion: core.getInput("miniforge-version"),
noImplicitChannels: core.getInput("no-implicit-channels"),
pythonVersion: core.getInput("python-version"),
removeProfiles: core.getInput("remove-profiles"),
condaConfig: Object.freeze({
Expand Down
14 changes: 14 additions & 0 deletions src/conda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ export async function applyCondaConfiguration(
await condaCommand(["config", "--add", "channels", channel], options);
}

if (inputs.noImplicitChannels && !channels.includes("defaults")) {
core.info("Removing implicitly added 'defaults' channel");
try {
await condaCommand(
["config", "--remove", "channels", "defaults"],
options,
);
} catch (err) {
core.info(
"Removing defaults raised an error -- it was probably not present.",
);
}
}

// All other options are just passed as their string representations
for (const [key, value] of configEntries) {
if (value.trim().length === 0 || key === "channels") {
Expand Down
1 change: 1 addition & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export async function parseInputs(): Promise<types.IActionInputs> {
minicondaVersion: core.getInput("miniconda-version"),
miniforgeVariant: core.getInput("miniforge-variant"),
miniforgeVersion: core.getInput("miniforge-version"),
noImplicitChannels: core.getInput("no-implicit-channels"),
pythonVersion: core.getInput("python-version"),
removeProfiles: core.getInput("remove-profiles"),
condaConfig: Object.freeze({
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface IActionInputs {
readonly minicondaVersion: string;
readonly miniforgeVariant: string;
readonly miniforgeVersion: string;
readonly noImplicitChannels: string;
readonly pythonVersion: string;
readonly removeProfiles: string;
readonly useMamba: string;
Expand Down

0 comments on commit 32935f2

Please sign in to comment.