Example 16: Default environment activation #77
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Example 16: Default environment activation" | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| # Note that cronjobs run on master/main by default | |
| - cron: "0 0 * * *" | |
| jobs: | |
| example-16-build: | |
| # prevent cronjobs from running on forks | |
| if: | |
| (github.event_name == 'schedule' && github.repository == | |
| 'conda-incubator/setup-miniconda') || (github.event_name != 'schedule') | |
| name: | |
| Build Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env | |
| == 'true' && 'default' || 'base' }}) | |
| runs-on: ${{ matrix.os }}-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| add-activation-env: ["false", "true"] | |
| os: ["ubuntu", "windows"] | |
| steps: | |
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Miniconda for installer builds | |
| uses: ./ | |
| with: | |
| activate-environment: "" | |
| auto-activate: false | |
| - name: Create installer | |
| uses: conda-incubator/installer@2d2df0b03c6795f70e128c56403c7d084cca4fb8 # v0.1.0 | |
| id: create-installer | |
| with: | |
| conda-root: ${{ env.CONDA }} | |
| environment-yaml-string: | | |
| channels: | |
| - conda-forge | |
| dependencies: | |
| - constructor | |
| variables: | |
| ADD_ACTIVATION_ENV: '${{ matrix.add-activation-env }}' | |
| EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} | |
| input-directory: etc/example-installers/default-environment/ | |
| - name: Upload installer to Github artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| path: ${{ steps.create-installer.outputs.artifacts-directory }}/* | |
| name: | |
| ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && | |
| 'no-' }}-activation-env | |
| example-16-test: | |
| needs: [example-16-build] | |
| name: | |
| Test Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env == | |
| 'true' && 'default' || 'base' }}, auto-activate-base=${{ | |
| matrix.auto-activate-base }}) | |
| runs-on: ${{ matrix.os }}-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| auto-activate-base: ["false", "true"] | |
| add-activation-env: ["false", "true"] | |
| os: ["ubuntu", "windows"] | |
| steps: | |
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Obtain artifact | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: | |
| ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && | |
| 'no-' }}-activation-env | |
| path: ${{ runner.temp }}/_installer | |
| - name: Determine installer file name | |
| id: installer-file | |
| env: | |
| ARTIFACTS_DIRECTORY: ${{ runner.temp }}/_installer | |
| EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} | |
| run: | | |
| INSTALLER_FILE=$(find "${ARTIFACTS_DIRECTORY}" -name "*.${EXT}" | head -n 1) | |
| echo "installer-file=${INSTALLER_FILE}" >> ${GITHUB_OUTPUT} | |
| shell: bash | |
| - name: Run installation | |
| uses: ./ | |
| with: | |
| activate-environment: "" | |
| auto-activate-base: | |
| ${{ matrix.auto-activate-base == 'true' && 'true' || | |
| 'legacy-placeholder' }} | |
| auto-activate: | |
| ${{ matrix.auto-activate-base == 'true' && '' || 'true' }} | |
| installation-dir: ${{ runner.temp }}/installer_test | |
| installer-url: | |
| file://${{ steps.installer-file.outputs.installer-file }} | |
| - name: Output conda info (bash) | |
| env: | |
| DEFAULT_ENV: ${{ matrix.add-activation-env && 'default' || 'base' }} | |
| TEST_DIR: ${{ runner.temp }}/installer_output | |
| run: | | |
| mkdir -p ${TEST_DIR} | |
| conda info --json > "${TEST_DIR}/bash.json" | |
| shell: bash -el {0} | |
| - name: Output conda info (cmd.exe) | |
| if: matrix.os == 'windows' | |
| env: | |
| TEST_DIR: ${{ runner.temp }}\installer_output | |
| run: | | |
| conda info --json > "%TEST_DIR%\cmd.exe.json" | |
| shell: cmd /C CALL {0} | |
| - name: Output conda info (PowerShell) | |
| if: matrix.os == 'windows' | |
| env: | |
| TEST_DIR: ${{ runner.temp }}\installer_output | |
| run: conda info --json > "${env:TEST_DIR}\pwsh.json" | |
| shell: pwsh | |
| - name: Test default environments | |
| env: | |
| DEFAULT_ENV: | |
| ${{ matrix.add-activation-env == 'true' && matrix.auto-activate-base | |
| == 'false' && 'default' || 'base' }} | |
| TEST_DIR: ${{ runner.temp }}/installer_output | |
| run: | | |
| import json | |
| import os | |
| from pathlib import Path | |
| json_dir = Path(os.environ["TEST_DIR"]) | |
| default_env_expected = os.environ["DEFAULT_ENV"] | |
| incorrect_environments = {} | |
| for file in json_dir.iterdir(): | |
| conda_info = json.loads(file.read_text()) | |
| default_env = conda_info.get("active_prefix_name") | |
| if default_env != default_env_expected: | |
| incorrect_environments[str(file.name).removesuffix(".json")] = default_env | |
| if incorrect_environments: | |
| raise AssertionError( | |
| f"Found incorrect default environments: {incorrect_environments}" | |
| ) | |
| shell: python |