mirror of
https://github.com/prefix-dev/setup-pixi
synced 2026-10-08 15:04:08 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9ac241030 | ||
|
|
b68487257f | ||
|
|
2058dcd92f | ||
|
|
fd715b50ef | ||
|
|
d72307a91c | ||
|
|
2fcf8775bc | ||
|
|
dbc36a133b | ||
|
|
c36e4b321e | ||
|
|
7d0875d54d | ||
|
|
2d1adc67f7 |
@@ -16,7 +16,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v3
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 8
|
||||
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
latest_version="$(jq -r '.version' package.json)"
|
||||
count_expected=13
|
||||
count_expected=15
|
||||
count_actual="$(grep -c "setup-pixi@v$latest_version" README.md || true)"
|
||||
if [ "$count_actual" -ne "$count_expected" ]; then
|
||||
echo "::error file=README.md::Expected $count_expected mentions of \`setup-pixi@v$latest_version\` in README.md, but found $count_actual."
|
||||
@@ -76,7 +76,7 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create pull request
|
||||
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e
|
||||
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e
|
||||
if: failure() && github.ref_name == 'main'
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -90,7 +90,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v3
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 8
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
TAG_NAME: v${{ steps.version-metadata.outputs.newVersion }}
|
||||
- name: Create release
|
||||
if: steps.version-metadata.outputs.changed == 'true'
|
||||
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564
|
||||
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87
|
||||
with:
|
||||
generate_release_notes: true
|
||||
tag_name: v${{ steps.version-metadata.outputs.newVersion }}
|
||||
|
||||
+117
-10
@@ -11,7 +11,7 @@ jobs:
|
||||
default:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
|
||||
cache: [true, false]
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: default ${{ matrix.cache == true && 'with' || 'without' }} cache (${{ matrix.os }})
|
||||
@@ -76,7 +76,7 @@ jobs:
|
||||
custom-pixi-version:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -113,7 +113,7 @@ jobs:
|
||||
install-path:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -126,7 +126,7 @@ jobs:
|
||||
global-install:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -579,7 +579,7 @@ jobs:
|
||||
name: multiple-environments (${{ matrix.os }}, cache=${{ matrix.cache }})
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
|
||||
cache: ['true', 'false']
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
@@ -617,7 +617,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-14]
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi files
|
||||
@@ -633,7 +633,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-14]
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi files
|
||||
@@ -658,7 +658,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-14]
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi files
|
||||
@@ -682,7 +682,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-14]
|
||||
os: [windows-latest, ubuntu-latest, macos-latest, macos-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi files
|
||||
@@ -693,7 +693,7 @@ jobs:
|
||||
cache-write: false
|
||||
cache-key: test-cache-${{ github.sha }}-${{ github.run_attempt }}-
|
||||
# check the action logs to see if the cache write was skipped
|
||||
|
||||
|
||||
pyproject:
|
||||
timeout-minutes: 10
|
||||
runs-on: ubuntu-latest
|
||||
@@ -717,6 +717,113 @@ jobs:
|
||||
cache: true
|
||||
manifest-path: test/pyproject-manifest/pyproject.toml
|
||||
|
||||
environment-activation-unix:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/default/* .
|
||||
- uses: ./
|
||||
with:
|
||||
activate-environment: true
|
||||
- run: which python | grep '.pixi/envs/default/bin/python'
|
||||
- run: env | grep CONDA_PREFIX
|
||||
- run: '[[ $PIXI_ENVIRONMENT_NAME = "default" ]]'
|
||||
|
||||
environment-activation-windows-bash:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/default/* .
|
||||
- uses: ./
|
||||
with:
|
||||
activate-environment: true
|
||||
- run: which python | grep '.pixi/envs/default/python'
|
||||
- run: env | grep CONDA_PREFIX
|
||||
- run: '[[ $PIXI_ENVIRONMENT_NAME = "default" ]]'
|
||||
|
||||
environment-activation-windows-pwsh:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: pwsh
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/default/* .
|
||||
- uses: ./
|
||||
with:
|
||||
activate-environment: true
|
||||
- run: if (-Not (Get-Command python).Path -like '*\.pixi\envs\default\python') { exit 1 }
|
||||
- run: if (!$env:CONDA_PREFIX) { exit 1 }
|
||||
- run: if ($env:PIXI_ENVIRONMENT_NAME -ne "default") { exit 1 }
|
||||
|
||||
environment-activation-windows-cmd:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: cmd
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/default/* .
|
||||
- uses: ./
|
||||
with:
|
||||
activate-environment: true
|
||||
- run: where python | findstr "\.pixi\\envs\\default\\python.exe"
|
||||
- run: set | findstr CONDA_PREFIX
|
||||
- run: |
|
||||
if defined PIXI_ENVIRONMENT_NAME (
|
||||
if "%PIXI_ENVIRONMENT_NAME%" NEQ "default" (
|
||||
exit 1
|
||||
)
|
||||
)
|
||||
|
||||
environment-activation-false:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/default/* .
|
||||
- uses: ./
|
||||
with:
|
||||
activate-environment: false
|
||||
- run: '[[ $PIXI_ENVIRONMENT_NAME = "" ]]'
|
||||
|
||||
environment-activation-explicit-env:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/multiple-environments/* .
|
||||
- uses: ./
|
||||
with:
|
||||
environments: py311
|
||||
activate-environment: true
|
||||
- run: which python | grep '.pixi/envs/py311/bin/python'
|
||||
- run: '[[ $PIXI_ENVIRONMENT_NAME = "py311" ]]'
|
||||
|
||||
environment-activation-multiple-env:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Move pixi.toml
|
||||
run: mv test/multiple-environments/* .
|
||||
- uses: ./
|
||||
with:
|
||||
environments: >-
|
||||
py311 py312
|
||||
activate-environment: py311
|
||||
- run: which python | grep '.pixi/envs/py311/bin/python'
|
||||
- run: '[[ $PIXI_ENVIRONMENT_NAME = "py311" ]]'
|
||||
|
||||
# not properly testable
|
||||
# https://github.com/actions/runner/issues/2347
|
||||
# https://github.com/orgs/community/discussions/15452
|
||||
|
||||
@@ -23,9 +23,9 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
|
||||
## Usage
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
pixi-version: v0.19.1
|
||||
pixi-version: v0.22.0
|
||||
cache: true
|
||||
auth-host: prefix.dev
|
||||
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
|
||||
@@ -34,7 +34,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
|
||||
|
||||
> [!WARNING]
|
||||
> Since pixi is not yet stable, the API of this action may change between minor versions.
|
||||
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.6.0`) to avoid breaking changes.
|
||||
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.8.0`) to avoid breaking changes.
|
||||
> 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).
|
||||
>
|
||||
> 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
|
||||
This can be done by setting the `cache-write` argument.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
cache: true
|
||||
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
|
||||
@@ -118,7 +118,7 @@ test:
|
||||
environment: [py311, py312]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
environments: ${{ matrix.environment }}
|
||||
```
|
||||
@@ -128,7 +128,7 @@ test:
|
||||
The following example will install both the `py311` and the `py312` environment on the runner.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
# separated by spaces
|
||||
environments: >-
|
||||
@@ -163,7 +163,7 @@ Specify the token using the `auth-token` input argument.
|
||||
This form of authentication (bearer token in the request headers) is mainly used at [prefix.dev](https://prefix.dev).
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
auth-host: prefix.dev
|
||||
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
|
||||
@@ -175,7 +175,7 @@ Specify the username and password using the `auth-username` and `auth-password`
|
||||
This form of authentication (HTTP Basic Auth) is used in some enterprise environments with [artifactory](https://jfrog.com/artifactory) for example.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
auth-host: custom-artifactory.com
|
||||
auth-username: ${{ secrets.PIXI_USERNAME }}
|
||||
@@ -188,7 +188,7 @@ Specify the conda-token using the `conda-token` input argument.
|
||||
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).
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
auth-host: anaconda.org # or my-quetz-instance.com
|
||||
conda-token: ${{ secrets.CONDA_TOKEN }}
|
||||
@@ -202,7 +202,7 @@ This can be useful if you want to run commands inside of the pixi environment, b
|
||||
```yml
|
||||
- run: | # everything here will be run inside of the pixi environment
|
||||
python --version
|
||||
pip install -e --no-deps .
|
||||
pip install --no-deps -e .
|
||||
shell: pixi run bash -e {0}
|
||||
```
|
||||
|
||||
@@ -228,13 +228,39 @@ If you want to use PowerShell, you need to specify `-Command` as well.
|
||||
> 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.
|
||||
> 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.
|
||||
|
||||
### Environment activation
|
||||
|
||||
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.
|
||||
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`.
|
||||
As a result, all installed binaries can be accessed without having to call `pixi run`.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
activate-environment: true
|
||||
```
|
||||
|
||||
If you are installing multiple environments, you will need to specify the name of the environment that you want to be activated.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
environments: >-
|
||||
py311
|
||||
py312
|
||||
activate-environment: py311
|
||||
```
|
||||
|
||||
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.
|
||||
However, be aware that this option augments the environment of your job.
|
||||
|
||||
### `--frozen` and `--locked`
|
||||
|
||||
You can specify whether `setup-pixi` should run `pixi install --frozen` or `pixi install --locked` depending on the `frozen` or the `locked` input argument.
|
||||
See the [official documentation](https://prefix.dev/docs/pixi/cli#install) for more information about the `--frozen` and `--locked` flags.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
locked: true
|
||||
# or
|
||||
@@ -253,7 +279,7 @@ The first one is the debug logging of the action itself.
|
||||
This can be enabled by running the action with the `RUNNER_DEBUG` environment variable set to `true`.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
env:
|
||||
RUNNER_DEBUG: true
|
||||
```
|
||||
@@ -271,7 +297,7 @@ The second type is the debug logging of the pixi executable.
|
||||
This can be specified by setting the `log-level` input.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
# one of `q`, `default`, `v`, `vv`, or `vvv`.
|
||||
log-level: vvv
|
||||
@@ -297,7 +323,7 @@ If nothing is specified, `post-cleanup` will default to `true`.
|
||||
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.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
post-cleanup: true
|
||||
# ${{ 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
|
||||
This can be overwritten by setting the `manifest-path` input argument.
|
||||
|
||||
```yml
|
||||
- uses: prefix-dev/setup-pixi@v0.6.0
|
||||
- uses: prefix-dev/setup-pixi@v0.8.0
|
||||
with:
|
||||
manifest-path: pyproject.toml
|
||||
```
|
||||
|
||||
+8
-2
@@ -17,12 +17,18 @@ inputs:
|
||||
manifest-path:
|
||||
description: Path to the manifest file (i.e., `pixi.toml`) to use for the pixi CLI. Defaults to `pixi.toml`.
|
||||
run-install:
|
||||
description: Whether to run `pixi install` after setting up the environment. Defaults to `true`.
|
||||
description: Whether to run `pixi install` after installing pixi. Defaults to `true`.
|
||||
environments:
|
||||
description: |
|
||||
A space-separated list of environments to install. If not specified, only the default environment is installed.
|
||||
activate-environment:
|
||||
description: |
|
||||
If the installed environment should be "activated" for the current job, modifying `$GITHUB_ENV` and
|
||||
`$GITHUB_PATH`. If more than one environment is specified in `environments`, this must be the name of the
|
||||
environment. Defaults to `false`. Requires at least pixi v0.21.0.
|
||||
locked:
|
||||
description: Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
|
||||
description:
|
||||
Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
|
||||
frozen:
|
||||
description: Whether to use `pixi install --frozen`. Defaults to `false`.
|
||||
cache:
|
||||
|
||||
+629
-363
File diff suppressed because it is too large
Load Diff
+272
-67
@@ -6258,7 +6258,7 @@ var import_process = require("process");
|
||||
var import_fs = require("fs");
|
||||
var core = __toESM(require_core());
|
||||
|
||||
// node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
||||
// node_modules/.pnpm/zod@3.23.5/node_modules/zod/lib/index.mjs
|
||||
var util;
|
||||
(function(util2) {
|
||||
util2.assertEqual = (val) => val;
|
||||
@@ -6408,7 +6408,7 @@ var ZodIssueCode = util.arrayToEnum([
|
||||
"not_multiple_of",
|
||||
"not_finite"
|
||||
]);
|
||||
var ZodError = class extends Error {
|
||||
var ZodError = class _ZodError extends Error {
|
||||
constructor(issues) {
|
||||
super();
|
||||
this.issues = [];
|
||||
@@ -6466,6 +6466,11 @@ var ZodError = class extends Error {
|
||||
processError(this);
|
||||
return fieldErrors;
|
||||
}
|
||||
static assert(value) {
|
||||
if (!(value instanceof _ZodError)) {
|
||||
throw new Error(`Not a ZodError: ${value}`);
|
||||
}
|
||||
}
|
||||
toString() {
|
||||
return this.message;
|
||||
}
|
||||
@@ -6605,6 +6610,13 @@ var makeIssue = (params) => {
|
||||
...issueData,
|
||||
path: fullPath
|
||||
};
|
||||
if (issueData.message !== void 0) {
|
||||
return {
|
||||
...issueData,
|
||||
path: fullPath,
|
||||
message: issueData.message
|
||||
};
|
||||
}
|
||||
let errorMessage = "";
|
||||
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
||||
for (const map of maps) {
|
||||
@@ -6613,10 +6625,11 @@ var makeIssue = (params) => {
|
||||
return {
|
||||
...issueData,
|
||||
path: fullPath,
|
||||
message: issueData.message || errorMessage
|
||||
message: errorMessage
|
||||
};
|
||||
};
|
||||
function addIssueToContext(ctx, issueData) {
|
||||
const overrideMap = getErrorMap();
|
||||
const issue = makeIssue({
|
||||
issueData,
|
||||
data: ctx.data,
|
||||
@@ -6624,8 +6637,8 @@ function addIssueToContext(ctx, issueData) {
|
||||
errorMaps: [
|
||||
ctx.common.contextualErrorMap,
|
||||
ctx.schemaErrorMap,
|
||||
getErrorMap(),
|
||||
errorMap
|
||||
overrideMap,
|
||||
overrideMap === errorMap ? void 0 : errorMap
|
||||
// then global default map
|
||||
].filter((x) => !!x)
|
||||
});
|
||||
@@ -6657,9 +6670,11 @@ var ParseStatus = class _ParseStatus {
|
||||
static async mergeObjectAsync(status, pairs) {
|
||||
const syncPairs = [];
|
||||
for (const pair of pairs) {
|
||||
const key = await pair.key;
|
||||
const value = await pair.value;
|
||||
syncPairs.push({
|
||||
key: await pair.key,
|
||||
value: await pair.value
|
||||
key,
|
||||
value
|
||||
});
|
||||
}
|
||||
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
||||
@@ -6692,11 +6707,29 @@ var isAborted = (x) => x.status === "aborted";
|
||||
var isDirty = (x) => x.status === "dirty";
|
||||
var isValid = (x) => x.status === "valid";
|
||||
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
||||
function __classPrivateFieldGet(receiver, state, kind, f) {
|
||||
if (kind === "a" && !f)
|
||||
throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
||||
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
}
|
||||
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
||||
if (kind === "m")
|
||||
throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f)
|
||||
throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
||||
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
||||
}
|
||||
var errorUtil;
|
||||
(function(errorUtil2) {
|
||||
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
||||
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
||||
})(errorUtil || (errorUtil = {}));
|
||||
var _ZodEnum_cache;
|
||||
var _ZodNativeEnum_cache;
|
||||
var ParseInputLazyPath = class {
|
||||
constructor(parent, value, path3, key) {
|
||||
this._cachedPath = [];
|
||||
@@ -6745,12 +6778,17 @@ function processCreateParams(params) {
|
||||
if (errorMap2)
|
||||
return { errorMap: errorMap2, description };
|
||||
const customMap = (iss, ctx) => {
|
||||
var _a, _b;
|
||||
const { message } = params;
|
||||
if (iss.code === "invalid_enum_value") {
|
||||
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
||||
}
|
||||
if (typeof ctx.data === "undefined") {
|
||||
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
||||
}
|
||||
if (iss.code !== "invalid_type")
|
||||
return { message: ctx.defaultError };
|
||||
if (typeof ctx.data === "undefined") {
|
||||
return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
|
||||
}
|
||||
return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
|
||||
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
||||
};
|
||||
return { errorMap: customMap, description };
|
||||
}
|
||||
@@ -6998,35 +7036,40 @@ var ZodType = class {
|
||||
}
|
||||
};
|
||||
var cuidRegex = /^c[^\s-]{8,}$/i;
|
||||
var cuid2Regex = /^[a-z][a-z0-9]*$/;
|
||||
var cuid2Regex = /^[0-9a-z]+$/;
|
||||
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
||||
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
||||
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
||||
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
||||
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
||||
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
||||
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
var emojiRegex;
|
||||
var ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
||||
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
||||
var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
||||
var datetimeRegex = (args) => {
|
||||
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
||||
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
||||
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
||||
function timeRegexSource(args) {
|
||||
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
||||
if (args.precision) {
|
||||
if (args.offset) {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
||||
} else {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
||||
}
|
||||
} else if (args.precision === 0) {
|
||||
if (args.offset) {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
||||
} else {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
||||
}
|
||||
} else {
|
||||
if (args.offset) {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
||||
} else {
|
||||
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
||||
}
|
||||
regex = `${regex}\\.\\d{${args.precision}}`;
|
||||
} else if (args.precision == null) {
|
||||
regex = `${regex}(\\.\\d+)?`;
|
||||
}
|
||||
};
|
||||
return regex;
|
||||
}
|
||||
function timeRegex(args) {
|
||||
return new RegExp(`^${timeRegexSource(args)}$`);
|
||||
}
|
||||
function datetimeRegex(args) {
|
||||
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
||||
const opts = [];
|
||||
opts.push(args.local ? `Z?` : `Z`);
|
||||
if (args.offset)
|
||||
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
||||
regex = `${regex}(${opts.join("|")})`;
|
||||
return new RegExp(`^${regex}$`);
|
||||
}
|
||||
function isValidIP(ip, version2) {
|
||||
if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
|
||||
return true;
|
||||
@@ -7044,15 +7087,11 @@ var ZodString = class _ZodString extends ZodType {
|
||||
const parsedType = this._getType(input);
|
||||
if (parsedType !== ZodParsedType.string) {
|
||||
const ctx2 = this._getOrReturnCtx(input);
|
||||
addIssueToContext(
|
||||
ctx2,
|
||||
{
|
||||
code: ZodIssueCode.invalid_type,
|
||||
expected: ZodParsedType.string,
|
||||
received: ctx2.parsedType
|
||||
}
|
||||
//
|
||||
);
|
||||
addIssueToContext(ctx2, {
|
||||
code: ZodIssueCode.invalid_type,
|
||||
expected: ZodParsedType.string,
|
||||
received: ctx2.parsedType
|
||||
});
|
||||
return INVALID;
|
||||
}
|
||||
const status = new ParseStatus();
|
||||
@@ -7143,6 +7182,16 @@ var ZodString = class _ZodString extends ZodType {
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "nanoid") {
|
||||
if (!nanoidRegex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
addIssueToContext(ctx, {
|
||||
validation: "nanoid",
|
||||
code: ZodIssueCode.invalid_string,
|
||||
message: check.message
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "cuid") {
|
||||
if (!cuidRegex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
@@ -7244,6 +7293,38 @@ var ZodString = class _ZodString extends ZodType {
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "date") {
|
||||
const regex = dateRegex;
|
||||
if (!regex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
addIssueToContext(ctx, {
|
||||
code: ZodIssueCode.invalid_string,
|
||||
validation: "date",
|
||||
message: check.message
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "time") {
|
||||
const regex = timeRegex(check);
|
||||
if (!regex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
addIssueToContext(ctx, {
|
||||
code: ZodIssueCode.invalid_string,
|
||||
validation: "time",
|
||||
message: check.message
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "duration") {
|
||||
if (!durationRegex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
addIssueToContext(ctx, {
|
||||
validation: "duration",
|
||||
code: ZodIssueCode.invalid_string,
|
||||
message: check.message
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "ip") {
|
||||
if (!isValidIP(input.data, check.version)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
@@ -7254,6 +7335,16 @@ var ZodString = class _ZodString extends ZodType {
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else if (check.kind === "base64") {
|
||||
if (!base64Regex.test(input.data)) {
|
||||
ctx = this._getOrReturnCtx(input, ctx);
|
||||
addIssueToContext(ctx, {
|
||||
validation: "base64",
|
||||
code: ZodIssueCode.invalid_string,
|
||||
message: check.message
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
} else {
|
||||
util.assertNever(check);
|
||||
}
|
||||
@@ -7285,6 +7376,9 @@ var ZodString = class _ZodString extends ZodType {
|
||||
uuid(message) {
|
||||
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
nanoid(message) {
|
||||
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
cuid(message) {
|
||||
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
@@ -7294,16 +7388,20 @@ var ZodString = class _ZodString extends ZodType {
|
||||
ulid(message) {
|
||||
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
base64(message) {
|
||||
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
ip(options2) {
|
||||
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options2) });
|
||||
}
|
||||
datetime(options2) {
|
||||
var _a;
|
||||
var _a, _b;
|
||||
if (typeof options2 === "string") {
|
||||
return this._addCheck({
|
||||
kind: "datetime",
|
||||
precision: null,
|
||||
offset: false,
|
||||
local: false,
|
||||
message: options2
|
||||
});
|
||||
}
|
||||
@@ -7311,9 +7409,30 @@ var ZodString = class _ZodString extends ZodType {
|
||||
kind: "datetime",
|
||||
precision: typeof (options2 === null || options2 === void 0 ? void 0 : options2.precision) === "undefined" ? null : options2 === null || options2 === void 0 ? void 0 : options2.precision,
|
||||
offset: (_a = options2 === null || options2 === void 0 ? void 0 : options2.offset) !== null && _a !== void 0 ? _a : false,
|
||||
local: (_b = options2 === null || options2 === void 0 ? void 0 : options2.local) !== null && _b !== void 0 ? _b : false,
|
||||
...errorUtil.errToObj(options2 === null || options2 === void 0 ? void 0 : options2.message)
|
||||
});
|
||||
}
|
||||
date(message) {
|
||||
return this._addCheck({ kind: "date", message });
|
||||
}
|
||||
time(options2) {
|
||||
if (typeof options2 === "string") {
|
||||
return this._addCheck({
|
||||
kind: "time",
|
||||
precision: null,
|
||||
message: options2
|
||||
});
|
||||
}
|
||||
return this._addCheck({
|
||||
kind: "time",
|
||||
precision: typeof (options2 === null || options2 === void 0 ? void 0 : options2.precision) === "undefined" ? null : options2 === null || options2 === void 0 ? void 0 : options2.precision,
|
||||
...errorUtil.errToObj(options2 === null || options2 === void 0 ? void 0 : options2.message)
|
||||
});
|
||||
}
|
||||
duration(message) {
|
||||
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
||||
}
|
||||
regex(regex, message) {
|
||||
return this._addCheck({
|
||||
kind: "regex",
|
||||
@@ -7392,6 +7511,15 @@ var ZodString = class _ZodString extends ZodType {
|
||||
get isDatetime() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
||||
}
|
||||
get isDate() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "date");
|
||||
}
|
||||
get isTime() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "time");
|
||||
}
|
||||
get isDuration() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
||||
}
|
||||
get isEmail() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "email");
|
||||
}
|
||||
@@ -7404,6 +7532,9 @@ var ZodString = class _ZodString extends ZodType {
|
||||
get isUUID() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
||||
}
|
||||
get isNANOID() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
||||
}
|
||||
get isCUID() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
||||
}
|
||||
@@ -7416,6 +7547,9 @@ var ZodString = class _ZodString extends ZodType {
|
||||
get isIP() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
||||
}
|
||||
get isBase64() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
||||
}
|
||||
get minLength() {
|
||||
let min = null;
|
||||
for (const ch of this._def.checks) {
|
||||
@@ -8329,9 +8463,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
||||
const syncPairs = [];
|
||||
for (const pair of pairs) {
|
||||
const key = await pair.key;
|
||||
const value = await pair.value;
|
||||
syncPairs.push({
|
||||
key,
|
||||
value: await pair.value,
|
||||
value,
|
||||
alwaysSet: pair.alwaysSet
|
||||
});
|
||||
}
|
||||
@@ -8682,15 +8817,25 @@ var getDiscriminator = (type) => {
|
||||
} else if (type instanceof ZodEnum) {
|
||||
return type.options;
|
||||
} else if (type instanceof ZodNativeEnum) {
|
||||
return Object.keys(type.enum);
|
||||
return util.objectValues(type.enum);
|
||||
} else if (type instanceof ZodDefault) {
|
||||
return getDiscriminator(type._def.innerType);
|
||||
} else if (type instanceof ZodUndefined) {
|
||||
return [void 0];
|
||||
} else if (type instanceof ZodNull) {
|
||||
return [null];
|
||||
} else if (type instanceof ZodOptional) {
|
||||
return [void 0, ...getDiscriminator(type.unwrap())];
|
||||
} else if (type instanceof ZodNullable) {
|
||||
return [null, ...getDiscriminator(type.unwrap())];
|
||||
} else if (type instanceof ZodBranded) {
|
||||
return getDiscriminator(type.unwrap());
|
||||
} else if (type instanceof ZodReadonly) {
|
||||
return getDiscriminator(type.unwrap());
|
||||
} else if (type instanceof ZodCatch) {
|
||||
return getDiscriminator(type._def.innerType);
|
||||
} else {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
};
|
||||
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
||||
@@ -8750,7 +8895,7 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
||||
const optionsMap = /* @__PURE__ */ new Map();
|
||||
for (const type of options2) {
|
||||
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
||||
if (!discriminatorValues) {
|
||||
if (!discriminatorValues.length) {
|
||||
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
||||
}
|
||||
for (const value of discriminatorValues) {
|
||||
@@ -8950,7 +9095,8 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
||||
for (const key in ctx.data) {
|
||||
pairs.push({
|
||||
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
||||
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
||||
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
||||
alwaysSet: key in ctx.data
|
||||
});
|
||||
}
|
||||
if (ctx.common.async) {
|
||||
@@ -9294,6 +9440,10 @@ function createZodEnum(values, params) {
|
||||
});
|
||||
}
|
||||
var ZodEnum = class _ZodEnum extends ZodType {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
_ZodEnum_cache.set(this, void 0);
|
||||
}
|
||||
_parse(input) {
|
||||
if (typeof input.data !== "string") {
|
||||
const ctx = this._getOrReturnCtx(input);
|
||||
@@ -9305,7 +9455,10 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
||||
});
|
||||
return INVALID;
|
||||
}
|
||||
if (this._def.values.indexOf(input.data) === -1) {
|
||||
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
||||
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
||||
}
|
||||
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
||||
const ctx = this._getOrReturnCtx(input);
|
||||
const expectedValues = this._def.values;
|
||||
addIssueToContext(ctx, {
|
||||
@@ -9341,15 +9494,26 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
||||
}
|
||||
return enumValues;
|
||||
}
|
||||
extract(values) {
|
||||
return _ZodEnum.create(values);
|
||||
extract(values, newDef = this._def) {
|
||||
return _ZodEnum.create(values, {
|
||||
...this._def,
|
||||
...newDef
|
||||
});
|
||||
}
|
||||
exclude(values) {
|
||||
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
|
||||
exclude(values, newDef = this._def) {
|
||||
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
||||
...this._def,
|
||||
...newDef
|
||||
});
|
||||
}
|
||||
};
|
||||
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
||||
ZodEnum.create = createZodEnum;
|
||||
var ZodNativeEnum = class extends ZodType {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
_ZodNativeEnum_cache.set(this, void 0);
|
||||
}
|
||||
_parse(input) {
|
||||
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
||||
const ctx = this._getOrReturnCtx(input);
|
||||
@@ -9362,7 +9526,10 @@ var ZodNativeEnum = class extends ZodType {
|
||||
});
|
||||
return INVALID;
|
||||
}
|
||||
if (nativeEnumValues.indexOf(input.data) === -1) {
|
||||
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
||||
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
||||
}
|
||||
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
||||
const expectedValues = util.objectValues(nativeEnumValues);
|
||||
addIssueToContext(ctx, {
|
||||
received: ctx.data,
|
||||
@@ -9377,6 +9544,7 @@ var ZodNativeEnum = class extends ZodType {
|
||||
return this._def.values;
|
||||
}
|
||||
};
|
||||
_ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
|
||||
ZodNativeEnum.create = (values, params) => {
|
||||
return new ZodNativeEnum({
|
||||
values,
|
||||
@@ -9440,26 +9608,38 @@ var ZodEffects = class extends ZodType {
|
||||
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
||||
if (effect.type === "preprocess") {
|
||||
const processed = effect.transform(ctx.data, checkCtx);
|
||||
if (ctx.common.issues.length) {
|
||||
return {
|
||||
status: "dirty",
|
||||
value: ctx.data
|
||||
};
|
||||
}
|
||||
if (ctx.common.async) {
|
||||
return Promise.resolve(processed).then((processed2) => {
|
||||
return this._def.schema._parseAsync({
|
||||
return Promise.resolve(processed).then(async (processed2) => {
|
||||
if (status.value === "aborted")
|
||||
return INVALID;
|
||||
const result = await this._def.schema._parseAsync({
|
||||
data: processed2,
|
||||
path: ctx.path,
|
||||
parent: ctx
|
||||
});
|
||||
if (result.status === "aborted")
|
||||
return INVALID;
|
||||
if (result.status === "dirty")
|
||||
return DIRTY(result.value);
|
||||
if (status.value === "dirty")
|
||||
return DIRTY(result.value);
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
return this._def.schema._parseSync({
|
||||
if (status.value === "aborted")
|
||||
return INVALID;
|
||||
const result = this._def.schema._parseSync({
|
||||
data: processed,
|
||||
path: ctx.path,
|
||||
parent: ctx
|
||||
});
|
||||
if (result.status === "aborted")
|
||||
return INVALID;
|
||||
if (result.status === "dirty")
|
||||
return DIRTY(result.value);
|
||||
if (status.value === "dirty")
|
||||
return DIRTY(result.value);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (effect.type === "refinement") {
|
||||
@@ -9753,6 +9933,9 @@ var ZodReadonly = class extends ZodType {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
unwrap() {
|
||||
return this._def.innerType;
|
||||
}
|
||||
};
|
||||
ZodReadonly.create = (type, params) => {
|
||||
return new ZodReadonly({
|
||||
@@ -9921,6 +10104,9 @@ var validateInputs = (inputs) => {
|
||||
if (inputs.runInstall === false && inputs.environments) {
|
||||
throw new Error("Cannot specify environments without running install");
|
||||
}
|
||||
if (inputs.activateEnvironment === "true" && inputs.environments && inputs.environments.length > 1) {
|
||||
throw new Error("When installing multiple environments, `activate-environment` must specify the environment name");
|
||||
}
|
||||
};
|
||||
var determinePixiInstallation = (pixiUrlOrVersionSet, pixiBinPath) => {
|
||||
const preinstalledPixi = import_which.default.sync("pixi", { nothrow: true });
|
||||
@@ -9955,10 +10141,17 @@ var inferOptions = (inputs) => {
|
||||
manifestPath = "pixi.toml";
|
||||
} else if ((0, import_fs.existsSync)("pyproject.toml")) {
|
||||
const fileContent = (0, import_fs.readFileSync)("pyproject.toml", "utf-8");
|
||||
const parsedContent = (0, import_toml.parse)(fileContent);
|
||||
if (parsedContent.tool && parsedContent.tool.pixi) {
|
||||
core.debug("The tool.pixi table found so using pyproject.toml as manifest file.");
|
||||
manifestPath = "pyproject.toml";
|
||||
console.log(fileContent);
|
||||
try {
|
||||
const parsedContent = (0, import_toml.parse)(fileContent);
|
||||
console.log(parsedContent);
|
||||
if (parsedContent.tool && parsedContent.tool.pixi) {
|
||||
core.debug("The tool.pixi table found so using pyproject.toml as manifest file.");
|
||||
manifestPath = "pyproject.toml";
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw new Error("Failed to parse pyproject.toml");
|
||||
}
|
||||
} else {
|
||||
if (runInstall) {
|
||||
@@ -9972,6 +10165,16 @@ var inferOptions = (inputs) => {
|
||||
if (!lockFileAvailable && inputs.cacheWrite === true) {
|
||||
throw new Error("You cannot specify cache-write = true without a lock file present");
|
||||
}
|
||||
let activatedEnvironment;
|
||||
if (inputs.activateEnvironment === "true") {
|
||||
if (inputs.environments) {
|
||||
activatedEnvironment = inputs.environments[0];
|
||||
} else {
|
||||
activatedEnvironment = "default";
|
||||
}
|
||||
} else if (inputs.activateEnvironment && inputs.activateEnvironment !== "false") {
|
||||
activatedEnvironment = inputs.activateEnvironment;
|
||||
}
|
||||
const cache = inputs.cacheKey ? { cacheKeyPrefix: inputs.cacheKey, cacheWrite: inputs.cacheWrite ?? true } : inputs.cache === true || lockFileAvailable && inputs.cache !== false ? { cacheKeyPrefix: "pixi-", cacheWrite: inputs.cacheWrite ?? true } : void 0;
|
||||
const frozen = inputs.frozen ?? false;
|
||||
const locked = inputs.locked ?? (lockFileAvailable && !frozen);
|
||||
@@ -9995,6 +10198,7 @@ var inferOptions = (inputs) => {
|
||||
pixiLockFile,
|
||||
runInstall,
|
||||
environments: inputs.environments,
|
||||
activatedEnvironment,
|
||||
frozen,
|
||||
locked,
|
||||
cache,
|
||||
@@ -10021,6 +10225,7 @@ var getOptions = () => {
|
||||
manifestPath: parseOrUndefined("manifest-path", stringType()),
|
||||
runInstall: parseOrUndefinedJSON("run-install", booleanType()),
|
||||
environments: parseOrUndefinedList("environments", stringType()),
|
||||
activateEnvironment: parseOrUndefined("activate-environment", stringType()),
|
||||
locked: parseOrUndefinedJSON("locked", booleanType()),
|
||||
frozen: parseOrUndefinedJSON("frozen", booleanType()),
|
||||
cache: parseOrUndefinedJSON("cache", booleanType()),
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-pixi",
|
||||
"version": "0.6.0",
|
||||
"version": "0.8.0",
|
||||
"private": true,
|
||||
"description": "Action to set up the pixi package manager.",
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import * as os from 'os'
|
||||
import * as osPath from 'path'
|
||||
import * as core from '@actions/core'
|
||||
import { executeGetOutput, pixiCmd } from './util'
|
||||
|
||||
type ShellHook = {
|
||||
environment_variables: Record<string, string>
|
||||
}
|
||||
|
||||
const splitEnvironment = (shellHook: ShellHook): [Record<string, string>, string?] => {
|
||||
if (os.platform() === 'win32') {
|
||||
// On Windows, environment variables are case-insensitive but JSON isn't...
|
||||
const pathEnvs = Object.keys(shellHook.environment_variables).filter((k) => k.toUpperCase() === 'PATH')
|
||||
if (pathEnvs) {
|
||||
const caseSensitivePathName = pathEnvs[0]
|
||||
const path = shellHook.environment_variables[caseSensitivePathName]
|
||||
delete shellHook.environment_variables[caseSensitivePathName]
|
||||
return [shellHook.environment_variables, path]
|
||||
}
|
||||
} else {
|
||||
if ('PATH' in shellHook.environment_variables) {
|
||||
const path = shellHook.environment_variables.PATH
|
||||
delete shellHook.environment_variables.PATH
|
||||
return [shellHook.environment_variables, path]
|
||||
}
|
||||
}
|
||||
|
||||
// If the path cannot be found, return all other environment variables
|
||||
return [shellHook.environment_variables]
|
||||
}
|
||||
|
||||
const getNewPathComponents = (path: string): string[] => {
|
||||
const currentPath = process.env.PATH
|
||||
if (!currentPath) {
|
||||
throw new Error('Unable to obtain current PATH from environment')
|
||||
}
|
||||
if (!path.endsWith(currentPath)) {
|
||||
throw new Error('Unable to handle environment activation which does not only append to PATH')
|
||||
}
|
||||
core.debug(`Found current path '${currentPath}'`)
|
||||
core.debug(`Got new path '${path}'`)
|
||||
const newPath = path.slice(0, path.length - currentPath.length)
|
||||
return newPath.split(osPath.delimiter).filter((p) => p.length > 0)
|
||||
}
|
||||
|
||||
export const activateEnvironment = async (environment: string): Promise<void> => {
|
||||
// First, obtain the environment variables that would be set by environment activation
|
||||
const envOption = environment === 'default' ? '' : `-e ${environment}`
|
||||
const shellHookOutput = await executeGetOutput(pixiCmd(`shell-hook ${envOption} --json`), { silent: true })
|
||||
const shellHook: ShellHook = JSON.parse(shellHookOutput.stdout)
|
||||
|
||||
// Then, we split the environment variables into the special 'PATH' and all others
|
||||
const [envVars, path] = splitEnvironment(shellHook)
|
||||
|
||||
// Finally, new path components are added...
|
||||
if (path) {
|
||||
const newComponents = getNewPathComponents(path)
|
||||
for (const component of newComponents) {
|
||||
core.info(`Adding path component '${component}'`)
|
||||
core.addPath(component)
|
||||
}
|
||||
}
|
||||
|
||||
// ... as well as all remaining environment variables
|
||||
for (const key of Object.keys(envVars)) {
|
||||
core.info(`Exporting environment variable '${key}=${envVars[key]}'`)
|
||||
core.exportVariable(key, envVars[key])
|
||||
}
|
||||
}
|
||||
+20
-12
@@ -8,6 +8,7 @@ import type { PixiSource } from './options'
|
||||
import { options } from './options'
|
||||
import { execute, getPixiUrlFromVersion, pixiCmd } from './util'
|
||||
import { saveCache, tryRestoreCache } from './cache'
|
||||
import { activateEnvironment } from './activate'
|
||||
|
||||
const downloadPixi = (source: PixiSource) => {
|
||||
const url = 'version' in source ? getPixiUrlFromVersion(source.version) : source.url
|
||||
@@ -110,6 +111,8 @@ const generateList = async () => {
|
||||
|
||||
const generateInfo = () => core.group('pixi info', () => execute(pixiCmd('info')))
|
||||
|
||||
const activateEnv = (environment: string) => core.group('Activate environment', () => activateEnvironment(environment))
|
||||
|
||||
const run = async () => {
|
||||
core.debug(`process.env.HOME: ${process.env.HOME}`)
|
||||
core.debug(`os.homedir(): ${os.homedir()}`)
|
||||
@@ -121,18 +124,23 @@ const run = async () => {
|
||||
await pixiInstall()
|
||||
await generateInfo()
|
||||
await generateList()
|
||||
if (options.activatedEnvironment) {
|
||||
await activateEnv(options.activatedEnvironment)
|
||||
}
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
if (core.isDebug()) {
|
||||
run()
|
||||
.catch((error) => {
|
||||
if (core.isDebug()) {
|
||||
throw error
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
exit(1)
|
||||
} else if (typeof error === 'string') {
|
||||
core.setFailed(error)
|
||||
exit(1)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
exit(1)
|
||||
} else if (typeof error === 'string') {
|
||||
core.setFailed(error)
|
||||
exit(1)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
})
|
||||
.then(() => exit(0)) // workaround for https://github.com/actions/toolkit/issues/1578
|
||||
|
||||
+29
-5
@@ -15,6 +15,7 @@ type Inputs = Readonly<{
|
||||
manifestPath?: string
|
||||
runInstall?: boolean
|
||||
environments?: string[]
|
||||
activateEnvironment?: boolean | string
|
||||
frozen?: boolean
|
||||
locked?: boolean
|
||||
cache?: boolean
|
||||
@@ -71,6 +72,7 @@ export type Options = Readonly<{
|
||||
pixiBinPath: string
|
||||
auth?: Auth
|
||||
postCleanup: boolean
|
||||
activatedEnvironment?: string
|
||||
}>
|
||||
|
||||
const logLevelSchema = z.enum(['q', 'default', 'v', 'vv', 'vvv'])
|
||||
@@ -159,6 +161,9 @@ const validateInputs = (inputs: Inputs): void => {
|
||||
if (inputs.runInstall === false && inputs.environments) {
|
||||
throw new Error('Cannot specify environments without running install')
|
||||
}
|
||||
if (inputs.activateEnvironment === 'true' && inputs.environments && inputs.environments.length > 1) {
|
||||
throw new Error('When installing multiple environments, `activate-environment` must specify the environment name')
|
||||
}
|
||||
}
|
||||
|
||||
const determinePixiInstallation = (pixiUrlOrVersionSet: boolean, pixiBinPath: string | undefined) => {
|
||||
@@ -204,11 +209,18 @@ const inferOptions = (inputs: Inputs): Options => {
|
||||
manifestPath = 'pixi.toml'
|
||||
} else if (existsSync('pyproject.toml')) {
|
||||
const fileContent = readFileSync('pyproject.toml', 'utf-8')
|
||||
const parsedContent = parse(fileContent)
|
||||
// only use pyproject.toml if [tool.pixi] is present
|
||||
if (parsedContent.tool && parsedContent.tool.pixi) {
|
||||
core.debug('The tool.pixi table found so using pyproject.toml as manifest file.')
|
||||
manifestPath = 'pyproject.toml'
|
||||
console.log(fileContent)
|
||||
try {
|
||||
const parsedContent = parse(fileContent)
|
||||
console.log(parsedContent)
|
||||
// only use pyproject.toml if [tool.pixi] is present
|
||||
if (parsedContent.tool && parsedContent.tool.pixi) {
|
||||
core.debug('The tool.pixi table found so using pyproject.toml as manifest file.')
|
||||
manifestPath = 'pyproject.toml'
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw new Error('Failed to parse pyproject.toml')
|
||||
}
|
||||
} else {
|
||||
if (runInstall) {
|
||||
@@ -222,6 +234,16 @@ const inferOptions = (inputs: Inputs): Options => {
|
||||
if (!lockFileAvailable && inputs.cacheWrite === true) {
|
||||
throw new Error('You cannot specify cache-write = true without a lock file present')
|
||||
}
|
||||
let activatedEnvironment // default is undefined
|
||||
if (inputs.activateEnvironment === 'true') {
|
||||
if (inputs.environments) {
|
||||
activatedEnvironment = inputs.environments[0]
|
||||
} else {
|
||||
activatedEnvironment = 'default'
|
||||
}
|
||||
} else if (inputs.activateEnvironment && inputs.activateEnvironment !== 'false') {
|
||||
activatedEnvironment = inputs.activateEnvironment
|
||||
}
|
||||
const cache = inputs.cacheKey
|
||||
? { cacheKeyPrefix: inputs.cacheKey, cacheWrite: inputs.cacheWrite ?? true }
|
||||
: inputs.cache === true || (lockFileAvailable && inputs.cache !== false)
|
||||
@@ -255,6 +277,7 @@ const inferOptions = (inputs: Inputs): Options => {
|
||||
pixiLockFile,
|
||||
runInstall,
|
||||
environments: inputs.environments,
|
||||
activatedEnvironment,
|
||||
frozen,
|
||||
locked,
|
||||
cache,
|
||||
@@ -289,6 +312,7 @@ const getOptions = () => {
|
||||
manifestPath: parseOrUndefined('manifest-path', z.string()),
|
||||
runInstall: parseOrUndefinedJSON('run-install', z.boolean()),
|
||||
environments: parseOrUndefinedList('environments', z.string()),
|
||||
activateEnvironment: parseOrUndefined('activate-environment', z.string()),
|
||||
locked: parseOrUndefinedJSON('locked', z.boolean()),
|
||||
frozen: parseOrUndefinedJSON('frozen', z.boolean()),
|
||||
cache: parseOrUndefinedJSON('cache', z.boolean()),
|
||||
|
||||
+8
-2
@@ -2,7 +2,8 @@ import type { BinaryLike } from 'crypto'
|
||||
import { createHash } from 'crypto'
|
||||
import * as os from 'os'
|
||||
import * as core from '@actions/core'
|
||||
import { exec } from '@actions/exec'
|
||||
import type { ExecOptions } from '@actions/exec'
|
||||
import { exec, getExecOutput } from '@actions/exec'
|
||||
import { options } from './options'
|
||||
|
||||
export const getCondaArch = () => {
|
||||
@@ -73,8 +74,13 @@ export const execute = (cmd: string[]) => {
|
||||
return exec(cmd[0], cmd.slice(1))
|
||||
}
|
||||
|
||||
export const executeGetOutput = (cmd: string[], options?: ExecOptions) => {
|
||||
core.debug(`Executing: ${cmd.join(' ')}`)
|
||||
return getExecOutput(cmd[0], cmd.slice(1), options)
|
||||
}
|
||||
|
||||
export const pixiCmd = (command: string, withManifestPath = true) => {
|
||||
let commandArray = [options.pixiBinPath].concat(command.split(' '))
|
||||
let commandArray = [options.pixiBinPath].concat(command.split(' ').filter((x) => x !== ''))
|
||||
if (withManifestPath) {
|
||||
commandArray = commandArray.concat(['--manifest-path', options.manifestPath])
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
description = "Add a short description here"
|
||||
authors = ["Pavel Zwerschke <pavelzw@gmail.com>"]
|
||||
channels = ["conda-forge"]
|
||||
platforms = ["linux-64", "osx-64", "win-64"]
|
||||
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
|
||||
|
||||
[tasks]
|
||||
test = "python -c 'print(\"Hello world!\")'"
|
||||
|
||||
Reference in New Issue
Block a user