Skip to content

Commit d72307a

Browse files
authored
Add activate-environment option (#108)
1 parent 2fcf877 commit d72307a

File tree

11 files changed

+642
-314
lines changed

11 files changed

+642
-314
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
set -euo pipefail
4747
latest_version="$(jq -r '.version' package.json)"
48-
count_expected=13
48+
count_expected=15
4949
count_actual="$(grep -c "setup-pixi@v$latest_version" README.md || true)"
5050
if [ "$count_actual" -ne "$count_expected" ]; then
5151
echo "::error file=README.md::Expected $count_expected mentions of \`setup-pixi@v$latest_version\` in README.md, but found $count_actual."

.github/workflows/test.yml

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ jobs:
693693
cache-write: false
694694
cache-key: test-cache-${{ github.sha }}-${{ github.run_attempt }}-
695695
# check the action logs to see if the cache write was skipped
696-
696+
697697
pyproject:
698698
timeout-minutes: 10
699699
runs-on: ubuntu-latest
@@ -717,6 +717,113 @@ jobs:
717717
cache: true
718718
manifest-path: test/pyproject-manifest/pyproject.toml
719719

720+
environment-activation-unix:
721+
strategy:
722+
matrix:
723+
os: [ubuntu-latest, macos-latest]
724+
runs-on: ${{ matrix.os }}
725+
steps:
726+
- uses: actions/checkout@v4
727+
- name: Move pixi.toml
728+
run: mv test/default/* .
729+
- uses: ./
730+
with:
731+
activate-environment: true
732+
- run: which python | grep '.pixi/envs/default/bin/python'
733+
- run: env | grep CONDA_PREFIX
734+
- run: '[[ $PIXI_ENVIRONMENT_NAME = "default" ]]'
735+
736+
environment-activation-windows-bash:
737+
runs-on: windows-latest
738+
defaults:
739+
run:
740+
shell: bash
741+
steps:
742+
- uses: actions/checkout@v4
743+
- name: Move pixi.toml
744+
run: mv test/default/* .
745+
- uses: ./
746+
with:
747+
activate-environment: true
748+
- run: which python | grep '.pixi/envs/default/python'
749+
- run: env | grep CONDA_PREFIX
750+
- run: '[[ $PIXI_ENVIRONMENT_NAME = "default" ]]'
751+
752+
environment-activation-windows-pwsh:
753+
runs-on: windows-latest
754+
defaults:
755+
run:
756+
shell: pwsh
757+
steps:
758+
- uses: actions/checkout@v4
759+
- name: Move pixi.toml
760+
run: mv test/default/* .
761+
- uses: ./
762+
with:
763+
activate-environment: true
764+
- run: if (-Not (Get-Command python).Path -like '*\.pixi\envs\default\python') { exit 1 }
765+
- run: if (!$env:CONDA_PREFIX) { exit 1 }
766+
- run: if ($env:PIXI_ENVIRONMENT_NAME -ne "default") { exit 1 }
767+
768+
environment-activation-windows-cmd:
769+
runs-on: windows-latest
770+
defaults:
771+
run:
772+
shell: cmd
773+
steps:
774+
- uses: actions/checkout@v4
775+
- name: Move pixi.toml
776+
run: mv test/default/* .
777+
- uses: ./
778+
with:
779+
activate-environment: true
780+
- run: where python | findstr "\.pixi\\envs\\default\\python.exe"
781+
- run: set | findstr CONDA_PREFIX
782+
- run: |
783+
if defined PIXI_ENVIRONMENT_NAME (
784+
if "%PIXI_ENVIRONMENT_NAME%" NEQ "default" (
785+
exit 1
786+
)
787+
)
788+
789+
environment-activation-false:
790+
runs-on: ubuntu-latest
791+
steps:
792+
- uses: actions/checkout@v4
793+
- name: Move pixi.toml
794+
run: mv test/default/* .
795+
- uses: ./
796+
with:
797+
activate-environment: false
798+
- run: '[[ $PIXI_ENVIRONMENT_NAME = "" ]]'
799+
800+
environment-activation-explicit-env:
801+
runs-on: ubuntu-latest
802+
steps:
803+
- uses: actions/checkout@v4
804+
- name: Move pixi.toml
805+
run: mv test/multiple-environments/* .
806+
- uses: ./
807+
with:
808+
environments: py311
809+
activate-environment: true
810+
- run: which python | grep '.pixi/envs/py311/bin/python'
811+
- run: '[[ $PIXI_ENVIRONMENT_NAME = "py311" ]]'
812+
813+
environment-activation-multiple-env:
814+
runs-on: ubuntu-latest
815+
steps:
816+
- uses: actions/checkout@v4
817+
- name: Move pixi.toml
818+
run: mv test/multiple-environments/* .
819+
- uses: ./
820+
with:
821+
environments: >-
822+
py311 py312
823+
activate-environment: py311
824+
- run: which python | grep '.pixi/envs/py311/bin/python'
825+
- run: '[[ $PIXI_ENVIRONMENT_NAME = "py311" ]]'
826+
720827
# not properly testable
721828
# https://github.com/actions/runner/issues/2347
722829
# https://github.com/orgs/community/discussions/15452

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
2323
## Usage
2424

2525
```yml
26-
- uses: prefix-dev/setup-pixi@v0.6.0
26+
- uses: prefix-dev/setup-pixi@v0.7.0
2727
with:
2828
pixi-version: v0.21.1
2929
cache: true
@@ -34,7 +34,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
3434
3535
> [!WARNING]
3636
> Since pixi is not yet stable, the API of this action may change between minor versions.
37-
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.6.0`) to avoid breaking changes.
37+
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.7.0`) to avoid breaking changes.
3838
> You can automatically update the version of this action by using [Dependabot](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot).
3939
>
4040
> Put the following in your `.github/dependabot.yml` file to enable Dependabot for your GitHub Actions:
@@ -73,7 +73,7 @@ In order to not exceed the [10 GB cache size limit](https://docs.github.com/en/a
7373
This can be done by setting the `cache-write` argument.
7474

7575
```yml
76-
- uses: prefix-dev/setup-pixi@v0.6.0
76+
- uses: prefix-dev/setup-pixi@v0.7.0
7777
with:
7878
cache: true
7979
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
@@ -118,7 +118,7 @@ test:
118118
environment: [py311, py312]
119119
steps:
120120
- uses: actions/checkout@v4
121-
- uses: prefix-dev/setup-pixi@v0.6.0
121+
- uses: prefix-dev/setup-pixi@v0.7.0
122122
with:
123123
environments: ${{ matrix.environment }}
124124
```
@@ -128,7 +128,7 @@ test:
128128
The following example will install both the `py311` and the `py312` environment on the runner.
129129

130130
```yml
131-
- uses: prefix-dev/setup-pixi@v0.6.0
131+
- uses: prefix-dev/setup-pixi@v0.7.0
132132
with:
133133
# separated by spaces
134134
environments: >-
@@ -163,7 +163,7 @@ Specify the token using the `auth-token` input argument.
163163
This form of authentication (bearer token in the request headers) is mainly used at [prefix.dev](https://prefix.dev).
164164

165165
```yml
166-
- uses: prefix-dev/setup-pixi@v0.6.0
166+
- uses: prefix-dev/setup-pixi@v0.7.0
167167
with:
168168
auth-host: prefix.dev
169169
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
@@ -175,7 +175,7 @@ Specify the username and password using the `auth-username` and `auth-password`
175175
This form of authentication (HTTP Basic Auth) is used in some enterprise environments with [artifactory](https://jfrog.com/artifactory) for example.
176176

177177
```yml
178-
- uses: prefix-dev/setup-pixi@v0.6.0
178+
- uses: prefix-dev/setup-pixi@v0.7.0
179179
with:
180180
auth-host: custom-artifactory.com
181181
auth-username: ${{ secrets.PIXI_USERNAME }}
@@ -188,7 +188,7 @@ Specify the conda-token using the `conda-token` input argument.
188188
This form of authentication (token is encoded in URL: `https://my-quetz-instance.com/t/<token>/get/custom-channel`) is used at [anaconda.org](https://anaconda.org) or with [quetz instances](https://github.com/mamba-org/quetz).
189189

190190
```yml
191-
- uses: prefix-dev/setup-pixi@v0.6.0
191+
- uses: prefix-dev/setup-pixi@v0.7.0
192192
with:
193193
auth-host: anaconda.org # or my-quetz-instance.com
194194
conda-token: ${{ secrets.CONDA_TOKEN }}
@@ -228,13 +228,39 @@ If you want to use PowerShell, you need to specify `-Command` as well.
228228
> There are some custom shells provided by GitHub that have slightly different behavior, see [`jobs.<job_id>.steps[*].shell`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) in the documentation.
229229
> See the [official documentation](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#custom-shell) and [ADR 0277](https://github.com/actions/runner/blob/main/docs/adrs/0277-run-action-shell-options.md) for more information about how the `shell:` input works in GitHub Actions.
230230

231+
### Environment activation
232+
233+
Instead of using a custom shell wrapper, you can also make all pixi-installed binaries available to subsequent steps by "activating" the installed environment in the currently running job.
234+
To this end, `setup-pixi` adds all environment variables set when executing `pixi run` to `$GITHUB_ENV` and, similarly, adds all path modifications to `$GITHUB_PATH`.
235+
As a result, all installed binaries can be accessed without having to call `pixi run`.
236+
237+
```yml
238+
- uses: prefix-dev/setup-pixi@v0.7.0
239+
with:
240+
activate-environment: true
241+
```
242+
243+
If you are installing multiple environments, you will need to specify the name of the environment that you want to be activated.
244+
245+
```yml
246+
- uses: prefix-dev/setup-pixi@v0.7.0
247+
with:
248+
environments: >-
249+
py311
250+
py312
251+
activate-environment: py311
252+
```
253+
254+
Activating an environment may be more useful than using a custom shell wrapper as it allows non-shell based steps to access binaries on the path.
255+
However, be aware that this option augments the environment of your job.
256+
231257
### `--frozen` and `--locked`
232258

233259
You can specify whether `setup-pixi` should run `pixi install --frozen` or `pixi install --locked` depending on the `frozen` or the `locked` input argument.
234260
See the [official documentation](https://prefix.dev/docs/pixi/cli#install) for more information about the `--frozen` and `--locked` flags.
235261

236262
```yml
237-
- uses: prefix-dev/setup-pixi@v0.6.0
263+
- uses: prefix-dev/setup-pixi@v0.7.0
238264
with:
239265
locked: true
240266
# or
@@ -253,7 +279,7 @@ The first one is the debug logging of the action itself.
253279
This can be enabled by running the action with the `RUNNER_DEBUG` environment variable set to `true`.
254280

255281
```yml
256-
- uses: prefix-dev/setup-pixi@v0.6.0
282+
- uses: prefix-dev/setup-pixi@v0.7.0
257283
env:
258284
RUNNER_DEBUG: true
259285
```
@@ -271,7 +297,7 @@ The second type is the debug logging of the pixi executable.
271297
This can be specified by setting the `log-level` input.
272298

273299
```yml
274-
- uses: prefix-dev/setup-pixi@v0.6.0
300+
- uses: prefix-dev/setup-pixi@v0.7.0
275301
with:
276302
# one of `q`, `default`, `v`, `vv`, or `vvv`.
277303
log-level: vvv
@@ -297,7 +323,7 @@ If nothing is specified, `post-cleanup` will default to `true`.
297323
On self-hosted runners, you also might want to alter the default pixi install location to a temporary location. You can use `pixi-bin-path: ${{ runner.temp }}/bin/pixi` to do this.
298324

299325
```yml
300-
- uses: prefix-dev/setup-pixi@v0.6.0
326+
- uses: prefix-dev/setup-pixi@v0.7.0
301327
with:
302328
post-cleanup: true
303329
# ${{ runner.temp }}\Scripts\pixi.exe on Windows
@@ -313,7 +339,7 @@ You can also use a preinstalled local version of pixi on the runner by not setti
313339
This can be overwritten by setting the `manifest-path` input argument.
314340

315341
```yml
316-
- uses: prefix-dev/setup-pixi@v0.6.0
342+
- uses: prefix-dev/setup-pixi@v0.7.0
317343
with:
318344
manifest-path: pyproject.toml
319345
```

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ inputs:
2121
environments:
2222
description: |
2323
A space-separated list of environments to install. If not specified, only the default environment is installed.
24+
activate-environment:
25+
description: |
26+
If the installed environment should be "activated" for the current job, modifying `$GITHUB_ENV` and
27+
`$GITHUB_PATH`. If more than one environment is specified in `environments`, this must be the name of the
28+
environment. Defaults to `false`. Requires at least pixi v0.21.0.
2429
locked:
25-
description: Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
30+
description:
31+
Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
2632
frozen:
2733
description: Whether to use `pixi install --frozen`. Defaults to `false`.
2834
cache:

0 commit comments

Comments
 (0)