Skip to content

Commit 28eb668

Browse files
feat: Allow caching global environment(s) (#226)
1 parent 194d461 commit 28eb668

File tree

8 files changed

+391
-172
lines changed

8 files changed

+391
-172
lines changed

README.md

Lines changed: 29 additions & 26 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/[email protected].1
26+
- uses: prefix-dev/[email protected].2
2727
with:
2828
pixi-version: v0.49.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/[email protected].1`) to avoid breaking changes.
38+
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/[email protected].2`) 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:
@@ -59,22 +59,25 @@ To see all available input arguments, see the [`action.yml`](action.yml) file.
5959

6060
### Caching
6161

62-
The action supports caching of the pixi environment.
63-
By default, caching is enabled if a `pixi.lock` file is present.
62+
The action supports caching of the project and global pixi environments.
63+
By default, project environment caching is enabled if a `pixi.lock` file is present.
6464
It will then use the `pixi.lock` file to generate a hash of the environment and cache it.
6565
If the cache is hit, the action will skip the installation and use the cached environment.
6666
You can specify the behavior by setting the `cache` input argument.
6767

68-
If you need to customize your cache-key, you can use the `cache-key` input argument.
69-
This will be the prefix of the cache key. The full cache key will be `<cache-key><conda-arch>-<hash>`.
68+
Global environment caching is disabled by default and can be enabled by setting the `global-cache` input to `true`.
69+
As there is no lockfile for global environments, the cache will expire at the end of every month to ensure it does not go stale.
70+
71+
If you need to customize your cache-key, you can use the `cache-key` and `global-cache-key` input arguments.
72+
These will be the prefixes of the cache keys. The full cache keys will be `<cache-key><conda-arch>-<hash>` and `<global-cache-key><conda-arch>-<YYYY-MM>-<hash>` respectively.
7073

7174
#### Only save caches on `main`
7275

7376
In order to not exceed the [10 GB cache size limit](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy) as fast, you might want to restrict when the cache is saved.
7477
This can be done by setting the `cache-write` argument.
7578

7679
```yml
77-
- uses: prefix-dev/[email protected].1
80+
- uses: prefix-dev/[email protected].2
7881
with:
7982
cache: true
8083
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
@@ -119,7 +122,7 @@ test:
119122
environment: [py311, py312]
120123
steps:
121124
- uses: actions/checkout@v4
122-
- uses: prefix-dev/[email protected].1
125+
- uses: prefix-dev/[email protected].2
123126
with:
124127
environments: ${{ matrix.environment }}
125128
```
@@ -129,7 +132,7 @@ test:
129132
The following example will install both the `py311` and the `py312` environment on the runner.
130133

131134
```yml
132-
- uses: prefix-dev/[email protected].1
135+
- uses: prefix-dev/[email protected].2
133136
with:
134137
# separated by spaces
135138
environments: >-
@@ -149,10 +152,10 @@ You can specify `pixi global install` commands by setting the `global-environmen
149152
This will create one environment per line, and install them.
150153
This is useful in particular to install executables that are needed for `pixi install` to work properly.
151154
For instance, the `keyring`, or `gcloud` executables. The following example shows how to install both in separate global environments.
152-
Note that global environments are not cached.
155+
By default, global environments are not cached. You can enable caching by setting the `global-cache` input to `true`.
153156

154157
```yml
155-
- uses: prefix-dev/[email protected].1
158+
- uses: prefix-dev/[email protected].2
156159
with:
157160
global-environments: |
158161
google-cloud-sdk
@@ -185,7 +188,7 @@ Specify the token using the `auth-token` input argument.
185188
This form of authentication (bearer token in the request headers) is mainly used at [prefix.dev](https://prefix.dev).
186189

187190
```yml
188-
- uses: prefix-dev/[email protected].1
191+
- uses: prefix-dev/[email protected].2
189192
with:
190193
auth-host: prefix.dev
191194
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
@@ -197,7 +200,7 @@ Specify the username and password using the `auth-username` and `auth-password`
197200
This form of authentication (HTTP Basic Auth) is used in some enterprise environments with [artifactory](https://jfrog.com/artifactory) for example.
198201

199202
```yml
200-
- uses: prefix-dev/[email protected].1
203+
- uses: prefix-dev/[email protected].2
201204
with:
202205
auth-host: custom-artifactory.com
203206
auth-username: ${{ secrets.PIXI_USERNAME }}
@@ -210,7 +213,7 @@ Specify the conda-token using the `auth-conda-token` input argument.
210213
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).
211214

212215
```yml
213-
- uses: prefix-dev/[email protected].1
216+
- uses: prefix-dev/[email protected].2
214217
with:
215218
auth-host: anaconda.org # or my-quetz-instance.com
216219
auth-conda-token: ${{ secrets.CONDA_TOKEN }}
@@ -222,7 +225,7 @@ Specify the S3 key pair using the `auth-access-key-id` and `auth-secret-access-k
222225
You can also specify the session token using the `auth-session-token` input argument.
223226

224227
```yaml
225-
- uses: prefix-dev/[email protected].1
228+
- uses: prefix-dev/[email protected].2
226229
with:
227230
auth-host: s3://my-s3-bucket
228231
auth-s3-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
@@ -238,7 +241,7 @@ See the [pixi documentation](https://pixi.sh/latest/advanced/s3) for more inform
238241
You can specify whether to use keyring to look up credentials for PyPI.
239242

240243
```yml
241-
- uses: prefix-dev/[email protected].1
244+
- uses: prefix-dev/[email protected].2
242245
with:
243246
pypi-keyring-provider: subprocess # one of 'subprocess', 'disabled'
244247
```
@@ -306,15 +309,15 @@ To this end, `setup-pixi` adds all environment variables set when executing `pix
306309
As a result, all installed binaries can be accessed without having to call `pixi run`.
307310

308311
```yml
309-
- uses: prefix-dev/[email protected].1
312+
- uses: prefix-dev/[email protected].2
310313
with:
311314
activate-environment: true
312315
```
313316

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

316319
```yml
317-
- uses: prefix-dev/[email protected].1
320+
- uses: prefix-dev/[email protected].2
318321
with:
319322
environments: >-
320323
py311
@@ -331,7 +334,7 @@ You can specify whether `setup-pixi` should run `pixi install --frozen` or `pixi
331334
See the [official documentation](https://prefix.dev/docs/pixi/cli#install) for more information about the `--frozen` and `--locked` flags.
332335

333336
```yml
334-
- uses: prefix-dev/[email protected].1
337+
- uses: prefix-dev/[email protected].2
335338
with:
336339
locked: true
337340
# or
@@ -350,7 +353,7 @@ The first one is the debug logging of the action itself.
350353
This can be enabled by running the action with the `RUNNER_DEBUG` environment variable set to `true`.
351354

352355
```yml
353-
- uses: prefix-dev/[email protected].1
356+
- uses: prefix-dev/[email protected].2
354357
env:
355358
RUNNER_DEBUG: true
356359
```
@@ -368,7 +371,7 @@ The second type is the debug logging of the pixi executable.
368371
This can be specified by setting the `log-level` input.
369372

370373
```yml
371-
- uses: prefix-dev/[email protected].1
374+
- uses: prefix-dev/[email protected].2
372375
with:
373376
# one of `q`, `default`, `v`, `vv`, or `vvv`.
374377
log-level: vvv
@@ -394,7 +397,7 @@ If nothing is specified, `post-cleanup` will default to `true`.
394397
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.
395398

396399
```yml
397-
- uses: prefix-dev/[email protected].1
400+
- uses: prefix-dev/[email protected].2
398401
with:
399402
post-cleanup: true
400403
# ${{ runner.temp }}\Scripts\pixi.exe on Windows
@@ -410,7 +413,7 @@ You can also use a preinstalled local version of pixi on the runner by not setti
410413
This can be overwritten by setting the `manifest-path` input argument.
411414

412415
```yml
413-
- uses: prefix-dev/[email protected].1
416+
- uses: prefix-dev/[email protected].2
414417
with:
415418
manifest-path: pyproject.toml
416419
```
@@ -420,7 +423,7 @@ This can be overwritten by setting the `manifest-path` input argument.
420423
If you only want to install pixi and not install the current project, you can use the `run-install` option.
421424

422425
```yml
423-
- uses: prefix-dev/[email protected].1
426+
- uses: prefix-dev/[email protected].2
424427
with:
425428
run-install: false
426429
```
@@ -431,7 +434,7 @@ You can also download pixi from a custom URL by setting the `pixi-url` input arg
431434
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.
432435

433436
```yml
434-
- uses: prefix-dev/[email protected].1
437+
- uses: prefix-dev/[email protected].2
435438
with:
436439
pixi-url: https://pixi-mirror.example.com/releases/download/v0.48.0/pixi-x86_64-unknown-linux-musl
437440
pixi-url-headers: '{"Authorization": "Bearer ${{ secrets.PIXI_MIRROR_BEARER_TOKEN }}"}'
@@ -447,7 +450,7 @@ It will be rendered with the following variables:
447450
By default, `pixi-url` is equivalent to the following template:
448451

449452
```yml
450-
- uses: prefix-dev/[email protected].1
453+
- uses: prefix-dev/[email protected].2
451454
with:
452455
pixi-url: |
453456
{{#if latest~}}

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ inputs:
3737
description: Whether to use `pixi install --frozen`. Defaults to `false`.
3838
cache:
3939
description: Whether to cache the pixi environment. Defaults to `true`. Only works if `pixi.lock` is present.
40+
global-cache:
41+
description: |
42+
Whether to cache the global environment(s). Defaults to `false`. As there is no lockfile for global environment,
43+
the global cache will expire at the end of every month, to ensure it does not go stale.
4044
cache-key:
4145
description: |
4246
Cache key prefix to use for caching the pixi environment.
4347
Defaults to `pixi-`. The full cache key is `<cache-key><conda-arch>-<sha-256-of-pixi-lock>`.
48+
global-cache-key:
49+
description: |
50+
Cache key prefix to use for caching the global environments.
51+
Defaults to `pixi-global-`. The full cache key is `<global-cache-key><conda-arch>-<sha-256-of-global-environments>`.
4452
cache-write:
4553
description: |
46-
Whether to write to the cache or only read from it. Defaults to `true`.
54+
Whether to write to the cache or only read from it. Defaults to `true`. Applies to both project and global caches as the case may be.
4755
pixi-bin-path:
4856
description: |
4957
Path to the pixi binary to use. Defaults to `~/.pixi/bin/pixi`.

0 commit comments

Comments
 (0)