Skip to content

Commit 5185adf

Browse files
feat: Add persist-credentials option (#266)
Co-authored-by: Pavel Zwerschke <pavelzw@gmail.com>
1 parent 92596c3 commit 5185adf

9 files changed

Lines changed: 169 additions & 37 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
set -euo pipefail
4949
latest_version="$(jq -r '.version' package.json)"
50-
count_expected=23
50+
count_expected=24
5151
count_actual="$(grep -c "setup-pixi@v$latest_version" README.md || true)"
5252
if [ "$count_actual" -ne "$count_expected" ]; then
5353
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,52 @@ jobs:
646646
# https://github.com/prefix-dev/pixi/issues/330
647647
if: matrix.os == 'ubuntu-latest'
648648
649+
persist-credentials-false:
650+
env:
651+
# We must set this environment variable explicitly to force all
652+
# operating systems to use the same storage mechanism.
653+
# Otherwise, windows and mac will use the keychain, which is more cumbersome to test.
654+
RATTLER_AUTH_FILE: .rattler-credentials.json
655+
strategy:
656+
matrix:
657+
os: [ubuntu-latest, macos-latest, windows-latest]
658+
runs-on: ${{ matrix.os }}
659+
defaults:
660+
run:
661+
shell: bash
662+
steps:
663+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
664+
- name: Move pixi.toml
665+
run: mv test/default/* .
666+
# Sanity check: Login with default persist-credentials behavior
667+
- uses: ./
668+
with:
669+
cache: false
670+
auth-host: https://custom-conda-registry.com
671+
auth-token: custom-token
672+
- name: Assert that the credentials are stored
673+
run: |
674+
# For human log readers
675+
cat "${RATTLER_AUTH_FILE}"
676+
# Actual test
677+
[ $(jq '."*.custom-conda-registry.com".BearerToken' -r "${RATTLER_AUTH_FILE}") = "custom-token" ]
678+
- name: Clean up credentials file
679+
run: rm "${RATTLER_AUTH_FILE}"
680+
# Actual test: Login with persist-credentials: false
681+
- uses: ./
682+
with:
683+
cache: false
684+
auth-host: https://custom-conda-registry.com
685+
auth-token: custom-token
686+
persist-credentials: false
687+
- name: Assert that the credentials are not stored anymore
688+
run: |
689+
# For human log readers
690+
cat "${RATTLER_AUTH_FILE}"
691+
692+
# Actual test
693+
! grep -q '"*.custom-conda-registry.com"' "${RATTLER_AUTH_FILE}"
694+
649695
auth-token-install:
650696
strategy:
651697
matrix:

README.md

Lines changed: 38 additions & 23 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.9.5
26+
- uses: prefix-dev/setup-pixi@v0.9.6
2727
with:
2828
pixi-version: v0.66.0
2929

@@ -35,7 +35,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
3535
3636
> [!WARNING]
3737
> Since pixi is not yet stable, the API of this action may change between minor versions.
38-
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.9.5`) to avoid breaking changes.
38+
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.9.6`) to avoid breaking changes.
3939
> 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).
4040
>
4141
> Put the following in your `.github/dependabot.yml` file to enable Dependabot for your GitHub Actions:
@@ -79,7 +79,7 @@ In order to not exceed the [10 GB cache size limit](https://docs.github.com/en/a
7979
This can be done by setting the `cache-write` argument.
8080

8181
```yml
82-
- uses: prefix-dev/setup-pixi@v0.9.5
82+
- uses: prefix-dev/setup-pixi@v0.9.6
8383
with:
8484
cache: true
8585
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
@@ -124,7 +124,7 @@ test:
124124
environment: [py311, py312]
125125
steps:
126126
- uses: actions/checkout@v4
127-
- uses: prefix-dev/setup-pixi@v0.9.5
127+
- uses: prefix-dev/setup-pixi@v0.9.6
128128
with:
129129
environments: ${{ matrix.environment }}
130130
```
@@ -134,7 +134,7 @@ test:
134134
The following example will install both the `py311` and the `py312` environment on the runner.
135135

136136
```yml
137-
- uses: prefix-dev/setup-pixi@v0.9.5
137+
- uses: prefix-dev/setup-pixi@v0.9.6
138138
with:
139139
# separated by spaces
140140
environments: >-
@@ -157,7 +157,7 @@ For instance, the `keyring`, or `gcloud` executables. The following example show
157157
By default, global environments are not cached. You can enable caching by setting the `global-cache` input to `true`.
158158

159159
```yml
160-
- uses: prefix-dev/setup-pixi@v0.9.5
160+
- uses: prefix-dev/setup-pixi@v0.9.6
161161
with:
162162
global-environments: |
163163
google-cloud-sdk
@@ -190,7 +190,7 @@ Specify the token using the `auth-token` input argument.
190190
This form of authentication (bearer token in the request headers) is mainly used at [prefix.dev](https://prefix.dev).
191191

192192
```yml
193-
- uses: prefix-dev/setup-pixi@v0.9.5
193+
- uses: prefix-dev/setup-pixi@v0.9.6
194194
with:
195195
auth-host: prefix.dev
196196
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
@@ -202,7 +202,7 @@ Specify the username and password using the `auth-username` and `auth-password`
202202
This form of authentication (HTTP Basic Auth) is used in some enterprise environments with [artifactory](https://jfrog.com/artifactory) for example.
203203

204204
```yml
205-
- uses: prefix-dev/setup-pixi@v0.9.5
205+
- uses: prefix-dev/setup-pixi@v0.9.6
206206
with:
207207
auth-host: custom-artifactory.com
208208
auth-username: ${{ secrets.PIXI_USERNAME }}
@@ -215,7 +215,7 @@ Specify the conda-token using the `auth-conda-token` input argument.
215215
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).
216216

217217
```yml
218-
- uses: prefix-dev/setup-pixi@v0.9.5
218+
- uses: prefix-dev/setup-pixi@v0.9.6
219219
with:
220220
auth-host: anaconda.org # or my-quetz-instance.com
221221
auth-conda-token: ${{ secrets.CONDA_TOKEN }}
@@ -227,7 +227,7 @@ Specify the S3 key pair using the `auth-access-key-id` and `auth-secret-access-k
227227
You can also specify the session token using the `auth-session-token` input argument.
228228

229229
```yaml
230-
- uses: prefix-dev/setup-pixi@v0.9.5
230+
- uses: prefix-dev/setup-pixi@v0.9.6
231231
with:
232232
auth-host: s3://my-s3-bucket
233233
auth-s3-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
@@ -238,12 +238,27 @@ You can also specify the session token using the `auth-session-token` input argu
238238

239239
See the [pixi documentation](https://pixi.sh/latest/advanced/s3) for more information about S3 authentication.
240240

241+
#### Restricting credentials to the install step
242+
243+
If you only want pixi to use the authenticated remote channel during the action's own install step
244+
(and not in any subsequent step of the workflow), set `persist-credentials: false`. The action will
245+
then run `pixi auth logout <auth-host>` after `pixi install` has completed but before the action
246+
returns, so that later steps cannot reach the private channel anymore.
247+
248+
```yml
249+
- uses: prefix-dev/setup-pixi@v0.9.6
250+
with:
251+
auth-host: prefix.dev
252+
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
253+
persist-credentials: false
254+
```
255+
241256
#### PyPI keyring provider
242257

243258
You can specify whether to use keyring to look up credentials for PyPI.
244259

245260
```yml
246-
- uses: prefix-dev/setup-pixi@v0.9.5
261+
- uses: prefix-dev/setup-pixi@v0.9.6
247262
with:
248263
pypi-keyring-provider: subprocess # one of 'subprocess', 'disabled'
249264
```
@@ -311,15 +326,15 @@ To this end, `setup-pixi` adds all environment variables set when executing `pix
311326
As a result, all installed binaries can be accessed without having to call `pixi run`.
312327

313328
```yml
314-
- uses: prefix-dev/setup-pixi@v0.9.5
329+
- uses: prefix-dev/setup-pixi@v0.9.6
315330
with:
316331
activate-environment: true
317332
```
318333

319334
If you are installing multiple environments, you will need to specify the name of the environment that you want to be activated.
320335

321336
```yml
322-
- uses: prefix-dev/setup-pixi@v0.9.5
337+
- uses: prefix-dev/setup-pixi@v0.9.6
323338
with:
324339
environments: >-
325340
py311
@@ -336,7 +351,7 @@ You can specify whether `setup-pixi` should run `pixi install --frozen` or `pixi
336351
See the [official documentation](https://pixi.sh/latest/reference/cli/pixi/install/#update-options) for more information about the `--frozen` and `--locked` flags.
337352

338353
```yml
339-
- uses: prefix-dev/setup-pixi@v0.9.5
354+
- uses: prefix-dev/setup-pixi@v0.9.6
340355
with:
341356
locked: true
342357
# or
@@ -355,7 +370,7 @@ The first one is the debug logging of the action itself.
355370
This can be enabled by running the action with the `RUNNER_DEBUG` environment variable set to `true`.
356371

357372
```yml
358-
- uses: prefix-dev/setup-pixi@v0.9.5
373+
- uses: prefix-dev/setup-pixi@v0.9.6
359374
env:
360375
RUNNER_DEBUG: true
361376
```
@@ -373,7 +388,7 @@ The second type is the debug logging of the pixi executable.
373388
This can be specified by setting the `log-level` input.
374389

375390
```yml
376-
- uses: prefix-dev/setup-pixi@v0.9.5
391+
- uses: prefix-dev/setup-pixi@v0.9.6
377392
with:
378393
# one of `q`, `default`, `v`, `vv`, or `vvv`.
379394
log-level: vvv
@@ -399,7 +414,7 @@ If nothing is specified, `post-cleanup` will default to `true`.
399414
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.
400415

401416
```yml
402-
- uses: prefix-dev/setup-pixi@v0.9.5
417+
- uses: prefix-dev/setup-pixi@v0.9.6
403418
with:
404419
post-cleanup: true
405420
# ${{ runner.temp }}\Scripts\pixi.exe on Windows
@@ -415,7 +430,7 @@ You can also use a preinstalled local version of pixi on the runner by not setti
415430
This can be overwritten by setting the `manifest-path` input argument.
416431

417432
```yml
418-
- uses: prefix-dev/setup-pixi@v0.9.5
433+
- uses: prefix-dev/setup-pixi@v0.9.6
419434
with:
420435
manifest-path: pyproject.toml
421436
```
@@ -425,7 +440,7 @@ This can be overwritten by setting the `manifest-path` input argument.
425440
If you're working with a monorepo where your pixi project is in a subdirectory, you can use the `working-directory` input to specify where pixi should look for manifest files (`pixi.toml` or `pyproject.toml`).
426441

427442
```yml
428-
- uses: prefix-dev/setup-pixi@v0.9.5
443+
- uses: prefix-dev/setup-pixi@v0.9.6
429444
with:
430445
working-directory: ./packages/my-project
431446
```
@@ -444,7 +459,7 @@ This will make pixi look for `pixi.toml` or `pyproject.toml` in the `./packages/
444459
You can combine `working-directory` with `manifest-path` if needed:
445460

446461
```yml
447-
- uses: prefix-dev/setup-pixi@v0.9.5
462+
- uses: prefix-dev/setup-pixi@v0.9.6
448463
with:
449464
working-directory: ./packages/my-project
450465
manifest-path: custom-pixi.toml
@@ -455,7 +470,7 @@ You can combine `working-directory` with `manifest-path` if needed:
455470
If you only want to install pixi and not install the current project, you can use the `run-install` option.
456471

457472
```yml
458-
- uses: prefix-dev/setup-pixi@v0.9.5
473+
- uses: prefix-dev/setup-pixi@v0.9.6
459474
with:
460475
run-install: false
461476
```
@@ -466,7 +481,7 @@ You can also download pixi from a custom URL by setting the `pixi-url` input arg
466481
Optionally, you can combine this with the `pixi-url-headers` input argument to supply additional headers for the download request, such as a bearer token.
467482

468483
```yml
469-
- uses: prefix-dev/setup-pixi@v0.9.5
484+
- uses: prefix-dev/setup-pixi@v0.9.6
470485
with:
471486
pixi-url: https://pixi-mirror.example.com/releases/download/v0.48.0/pixi-x86_64-unknown-linux-musl
472487
pixi-url-headers: '{"Authorization": "Bearer ${{ secrets.PIXI_MIRROR_BEARER_TOKEN }}"}'
@@ -482,7 +497,7 @@ It will be rendered with the following variables:
482497
By default, `pixi-url` is equivalent to the following template:
483498

484499
```yml
485-
- uses: prefix-dev/setup-pixi@v0.9.5
500+
- uses: prefix-dev/setup-pixi@v0.9.6
486501
with:
487502
pixi-url: |
488503
{{#if latest~}}

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ inputs:
7878
description: Secret access key to use for S3 authentication.
7979
auth-s3-session-token:
8080
description: Session token to use for S3 authentication.
81+
persist-credentials:
82+
description: |
83+
Whether to keep the credentials configured by `auth-host` available to subsequent workflow
84+
steps. Defaults to `true`. If set to `false`, the action runs `pixi auth logout <auth-host>`
85+
after install, so that later steps cannot reach the private channel anymore. Requires
86+
`auth-host`.
8187
pypi-keyring-provider:
8288
description: |
8389
Specifies whether to use keyring to look up credentials for PyPI.

dist/index.js

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)