|
| 1 | +name: "Setup Miniconda" |
| 2 | +description: "Wrapper around conda-incubator/setup-miniconda to cache lock files." |
| 3 | +inputs: |
| 4 | + python-version: |
| 5 | + description: "Refer conda-incubator/setup-miniconda." |
| 6 | + required: false |
| 7 | + default: "" |
| 8 | + activate-environment: |
| 9 | + description: "Refer conda-incubator/setup-miniconda." |
| 10 | + required: false |
| 11 | + default: "test" |
| 12 | + environment-file: |
| 13 | + description: "Refer conda-incubator/setup-miniconda." |
| 14 | + required: false |
| 15 | + default: "" |
| 16 | + channels: |
| 17 | + description: "Refer conda-incubator/setup-miniconda." |
| 18 | + required: false |
| 19 | + default: "" |
| 20 | + channel-priority: |
| 21 | + description: "Refer conda-incubator/setup-miniconda, default changed to 'disabled'." |
| 22 | + required: false |
| 23 | + default: "disabled" |
| 24 | + run-post: |
| 25 | + description: "Refer conda-incubator/setup-miniconda, default changed to 'false'." |
| 26 | + required: false |
| 27 | + default: "false" |
| 28 | + cache-number: |
| 29 | + description: "Increase this value to reset cache if env file has not changed." |
| 30 | + required: false |
| 31 | + default: "-3" |
| 32 | + dependencies: |
| 33 | + description: "List of packages separated by ; to use in environment file." |
| 34 | + required: false |
| 35 | + default: "" |
| 36 | +runs: |
| 37 | + using: "composite" |
| 38 | + steps: |
| 39 | + - name: Get Date |
| 40 | + id: get-date |
| 41 | + shell: bash |
| 42 | + run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT |
| 43 | + |
| 44 | + - name: Generate channels hash |
| 45 | + id: channels-hash |
| 46 | + shell: bash |
| 47 | + run: echo "hash=$(echo '${{inputs.channels}}' | sha1sum | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT |
| 48 | + |
| 49 | + - name: Write dependencies |
| 50 | + if: inputs.dependencies != '' |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + printf "dependencies:;${{inputs.dependencies}}" | sed 's/;/\n - /g' > \ |
| 54 | + ${{inputs.environment-file}} |
| 55 | +
|
| 56 | + - name: Cache Conda env |
| 57 | + uses: actions/cache@v4 |
| 58 | + with: |
| 59 | + # TODO: use channels as part of the key |
| 60 | + path: ${{inputs.environment-file}}.lock |
| 61 | + key: setup-miniconda-${{ runner.os }}-${{ runner.arch }}-${{ |
| 62 | + inputs.python-version }}-${{ |
| 63 | + steps.get-date.outputs.today }}-${{ |
| 64 | + steps.channels-hash.hash }}-${{ |
| 65 | + hashFiles(inputs.environment-file) }}-${{ |
| 66 | + inputs.cache-number }} |
| 67 | + id: cache |
| 68 | + |
| 69 | + - name: Setup miniconda |
| 70 | + if: steps.cache.outputs.cache-hit != 'true' |
| 71 | + uses: conda-incubator/setup-miniconda@v3 |
| 72 | + with: |
| 73 | + python-version: ${{ inputs.python-version }} |
| 74 | + activate-environment: ${{inputs.activate-environment}} |
| 75 | + channels: ${{ inputs.channels }} |
| 76 | + channel-priority: ${{ inputs.channel-priority }} |
| 77 | + environment-file: ${{ inputs.environment-file }} |
| 78 | + run-post: ${{ inputs.run-post }} |
| 79 | + |
| 80 | + - name: Save environment resolution |
| 81 | + if: steps.cache.outputs.cache-hit != 'true' |
| 82 | + shell: bash -l {0} |
| 83 | + run: conda list --explicit > ${{inputs.activate-environment}}.lock |
| 84 | + |
| 85 | + - name: Setup conda |
| 86 | + if: steps.cache.outputs.cache-hit == 'true' |
| 87 | + uses: conda-incubator/setup-miniconda@v3 |
| 88 | + with: |
| 89 | + activate-environment: ${{inputs.activate-environment}} |
| 90 | + channels: ${{ inputs.channels }} |
| 91 | + environment-file: ${{inputs.activate-environment}}.lock |
| 92 | + run-post: ${{ inputs.run-post }} |
| 93 | + |
| 94 | + - name: Disable defaults |
| 95 | + shell: bash -l {0} |
| 96 | + run: conda config --remove channels defaults |
0 commit comments