|
| 1 | +name: "Example 16: Default environment activation" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + schedule: |
| 9 | + # Note that cronjobs run on master/main by default |
| 10 | + - cron: "0 0 * * *" |
| 11 | + |
| 12 | +jobs: |
| 13 | + example-16-build: |
| 14 | + # prevent cronjobs from running on forks |
| 15 | + if: |
| 16 | + (github.event_name == 'schedule' && github.repository == |
| 17 | + 'conda-incubator/setup-miniconda') || (github.event_name != 'schedule') |
| 18 | + name: |
| 19 | + Build Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env |
| 20 | + == 'true' && 'default' || 'base' }}) |
| 21 | + runs-on: ${{ matrix.os }}-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + add-activation-env: ["false", "true"] |
| 26 | + os: ["ubuntu", "windows"] |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 29 | + with: |
| 30 | + persist-credentials: false |
| 31 | + |
| 32 | + - name: Set up Miniconda for installer builds |
| 33 | + uses: ./ |
| 34 | + with: |
| 35 | + activate-environment: "" |
| 36 | + auto-activate: false |
| 37 | + |
| 38 | + - name: Create installer |
| 39 | + uses: conda-incubator/installer@2d2df0b03c6795f70e128c56403c7d084cca4fb8 # v0.1.0 |
| 40 | + id: create-installer |
| 41 | + with: |
| 42 | + conda-root: ${{ env.CONDA }} |
| 43 | + environment-yaml-string: | |
| 44 | + channels: |
| 45 | + - conda-forge |
| 46 | + dependencies: |
| 47 | + - constructor |
| 48 | + variables: |
| 49 | + ADD_ACTIVATION_ENV: '${{ matrix.add-activation-env }}' |
| 50 | + EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} |
| 51 | + input-directory: etc/example-installers/default-environment/ |
| 52 | + |
| 53 | + - name: Upload installer to Github artifact |
| 54 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 55 | + with: |
| 56 | + path: ${{ steps.create-installer.outputs.artifacts-directory }}/* |
| 57 | + name: |
| 58 | + ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && |
| 59 | + 'no-' }}-activation-env |
| 60 | + |
| 61 | + example-16-test: |
| 62 | + needs: [example-16-build] |
| 63 | + name: |
| 64 | + Test Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env == |
| 65 | + 'true' && 'default' || 'base' }}, auto-activate-base=${{ |
| 66 | + matrix.auto-activate-base }}) |
| 67 | + runs-on: ${{ matrix.os }}-latest |
| 68 | + strategy: |
| 69 | + fail-fast: false |
| 70 | + matrix: |
| 71 | + auto-activate-base: ["false", "true"] |
| 72 | + add-activation-env: ["false", "true"] |
| 73 | + os: ["ubuntu", "windows"] |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 76 | + with: |
| 77 | + persist-credentials: false |
| 78 | + |
| 79 | + - name: Obtain artifact |
| 80 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 81 | + with: |
| 82 | + name: |
| 83 | + ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && |
| 84 | + 'no-' }}-activation-env |
| 85 | + path: ${{ runner.temp }}/_installer |
| 86 | + |
| 87 | + - name: Determine installer file name |
| 88 | + id: installer-file |
| 89 | + env: |
| 90 | + ARTIFACTS_DIRECTORY: ${{ runner.temp }}/_installer |
| 91 | + EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} |
| 92 | + run: | |
| 93 | + INSTALLER_FILE=$(find "${ARTIFACTS_DIRECTORY}" -name "*.${EXT}" | head -n 1) |
| 94 | + echo "installer-file=${INSTALLER_FILE}" >> ${GITHUB_OUTPUT} |
| 95 | + shell: bash |
| 96 | + |
| 97 | + - name: Run installation |
| 98 | + uses: ./ |
| 99 | + with: |
| 100 | + activate-environment: "" |
| 101 | + auto-activate-base: |
| 102 | + ${{ matrix.auto-activate-base == 'true' && 'true' || |
| 103 | + 'legacy-placeholder' }} |
| 104 | + auto-activate: |
| 105 | + ${{ matrix.auto-activate-base == 'true' && '' || 'true' }} |
| 106 | + installation-dir: ${{ runner.temp }}/installer_test |
| 107 | + installer-url: |
| 108 | + file://${{ steps.installer-file.outputs.installer-file }} |
| 109 | + |
| 110 | + - name: Output conda info (bash) |
| 111 | + env: |
| 112 | + DEFAULT_ENV: ${{ matrix.add-activation-env && 'default' || 'base' }} |
| 113 | + TEST_DIR: ${{ runner.temp }}/installer_output |
| 114 | + run: | |
| 115 | + mkdir -p ${TEST_DIR} |
| 116 | + conda info --json > "${TEST_DIR}/bash.json" |
| 117 | + shell: bash -el {0} |
| 118 | + |
| 119 | + - name: Output conda info (cmd.exe) |
| 120 | + if: matrix.os == 'windows' |
| 121 | + env: |
| 122 | + TEST_DIR: ${{ runner.temp }}\installer_output |
| 123 | + run: | |
| 124 | + conda info --json > "%TEST_DIR%\cmd.exe.json" |
| 125 | + shell: cmd /C CALL {0} |
| 126 | + |
| 127 | + - name: Output conda info (PowerShell) |
| 128 | + if: matrix.os == 'windows' |
| 129 | + env: |
| 130 | + TEST_DIR: ${{ runner.temp }}\installer_output |
| 131 | + run: conda info --json > "${env:TEST_DIR}\pwsh.json" |
| 132 | + shell: pwsh |
| 133 | + |
| 134 | + - name: Test default environments |
| 135 | + env: |
| 136 | + DEFAULT_ENV: |
| 137 | + ${{ matrix.add-activation-env == 'true' && matrix.auto-activate-base |
| 138 | + == 'false' && 'default' || 'base' }} |
| 139 | + TEST_DIR: ${{ runner.temp }}/installer_output |
| 140 | + run: | |
| 141 | + import json |
| 142 | + import os |
| 143 | + from pathlib import Path |
| 144 | +
|
| 145 | + json_dir = Path(os.environ["TEST_DIR"]) |
| 146 | + default_env_expected = os.environ["DEFAULT_ENV"] |
| 147 | + incorrect_environments = {} |
| 148 | + for file in json_dir.iterdir(): |
| 149 | + conda_info = json.loads(file.read_text()) |
| 150 | + default_env = conda_info.get("active_prefix_name") |
| 151 | + if default_env != default_env_expected: |
| 152 | + incorrect_environments[str(file.name).removesuffix(".json")] = default_env |
| 153 | + if incorrect_environments: |
| 154 | + raise AssertionError( |
| 155 | + f"Found incorrect default environments: {incorrect_environments}" |
| 156 | + ) |
| 157 | + shell: python |
0 commit comments