feat: Allow specifying inputs as environment variables (#214)

This commit is contained in:
Yannik Tausch
2025-07-22 12:53:59 +02:00
committed by GitHub
parent a8c5cac0eb
commit 4522f6409d
5 changed files with 130 additions and 21 deletions
+48
View File
@@ -943,6 +943,54 @@ jobs:
py311 py312
activate-environment: py311
env-variable-input-custom-bin-path:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Move pixi.toml
run: mv test/default/* .
- uses: ./
env:
SETUP_PIXI_PIXI_BIN_PATH: custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
with:
cache: false
- run: |
test -f custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
pixi --help
which pixi | grep -q custom-bin/pixi
# which pixi should be absolute
which pixi | grep -q "^/"
env-variable-input-custom-pixi-url:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Move pixi.toml
run: mv test/old-pixi-lockfiles/* .
- uses: ./
env:
SETUP_PIXI_PIXI_URL: https://github.com/prefix-dev/pixi/releases/download/v0.14.0/pixi-x86_64-unknown-linux-musl
with:
cache: false
- run: pixi --version | grep -q "pixi 0.14.0"
env-variable-input-precendence:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Move pixi.toml
run: mv test/old-pixi-lockfiles/* .
- uses: ./
env:
SETUP_PIXI_PIXI_URL: https://github.com/prefix-dev/pixi/releases/download/v0.14.0/pixi-x86_64-unknown-linux-musl
with:
cache: false
pixi-url: https://github.com/prefix-dev/pixi/releases/download/v0.49.0/pixi-x86_64-unknown-linux-musl
- run: pixi --version | grep -q "pixi 0.49.0"
test-cache-fail-no-lockfile:
runs-on: ${{ matrix.os }}
strategy:
+11
View File
@@ -405,6 +405,17 @@ Optionally, you can combine this with the `pixi-url-bearer-token` input argument
pixi-url-bearer-token: ${{ secrets.PIXI_MIRROR_BEARER_TOKEN }}
```
### Setting inputs from environment variables
Alternatively to setting the inputs in the `with` section, you can also set each of them using environment variables.
The corresponding environment variable names are derived from the input names by converting them to uppercase, replacing hyphens with underscores, and prefixing them with `SETUP_PIXI_`.
For example, the `pixi-bin-path` input can be set using the `SETUP_PIXI_PIXI_BIN_PATH` environment variable.
This is particularly useful if executing the action on a self-hosted runner.
Inputs always take precedence over environment variables.
## More examples
If you want to see more examples, you can take a look at the [GitHub Workflows of this repository](.github/workflows/test.yml).
Generated Vendored
+22 -6
View File
@@ -68836,9 +68836,25 @@ var logLevelSchema = enumType(["q", "default", "v", "vv", "vvv"]);
var PATHS = {
pixiBin: import_path.default.join(import_os.default.homedir(), ".pixi", "bin", `pixi${import_os.default.platform() === "win32" ? ".exe" : ""}`)
};
var getEnvironmentVariableName = (key) => {
return `SETUP_PIXI_${key.toUpperCase().replace(/-/g, "_")}`;
};
var inputOrEnvironmentVariable = (key) => {
const inputValue = core.getInput(key);
if (inputValue !== "") {
return inputValue;
}
const envVarName = getEnvironmentVariableName(key);
const envVarValue = process.env[envVarName];
if (envVarValue !== void 0 && envVarValue !== "") {
core.debug(`Using environment variable ${envVarName} with value: ${envVarValue}`);
return envVarValue;
}
return void 0;
};
var parseOrUndefined = (key, schema, errorMessage) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
const maybeResult = schema.safeParse(input);
@@ -68851,15 +68867,15 @@ var parseOrUndefined = (key, schema, errorMessage) => {
return maybeResult.data;
};
var parseOrUndefinedJSON = (key, schema) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
return schema.parse(JSON.parse(input));
};
var parseOrUndefinedList = (key, schema) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
return input.split(" ").map((s) => schema.parse(s)).filter((s) => s !== "");
Generated Vendored
+22 -6
View File
@@ -24713,9 +24713,25 @@ var logLevelSchema = enumType(["q", "default", "v", "vv", "vvv"]);
var PATHS = {
pixiBin: import_path.default.join(import_os.default.homedir(), ".pixi", "bin", `pixi${import_os.default.platform() === "win32" ? ".exe" : ""}`)
};
var getEnvironmentVariableName = (key) => {
return `SETUP_PIXI_${key.toUpperCase().replace(/-/g, "_")}`;
};
var inputOrEnvironmentVariable = (key) => {
const inputValue = core.getInput(key);
if (inputValue !== "") {
return inputValue;
}
const envVarName = getEnvironmentVariableName(key);
const envVarValue = process.env[envVarName];
if (envVarValue !== void 0 && envVarValue !== "") {
core.debug(`Using environment variable ${envVarName} with value: ${envVarValue}`);
return envVarValue;
}
return void 0;
};
var parseOrUndefined = (key, schema, errorMessage) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
const maybeResult = schema.safeParse(input);
@@ -24728,15 +24744,15 @@ var parseOrUndefined = (key, schema, errorMessage) => {
return maybeResult.data;
};
var parseOrUndefinedJSON = (key, schema) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
return schema.parse(JSON.parse(input));
};
var parseOrUndefinedList = (key, schema) => {
const input = core.getInput(key);
if (input === "") {
const input = inputOrEnvironmentVariable(key);
if (input === void 0) {
return void 0;
}
return input.split(" ").map((s) => schema.parse(s)).filter((s) => s !== "");
+27 -9
View File
@@ -94,10 +94,30 @@ export const PATHS = {
pixiBin: path.join(os.homedir(), '.pixi', 'bin', `pixi${os.platform() === 'win32' ? '.exe' : ''}`)
}
const getEnvironmentVariableName = (key: string): string => {
return `SETUP_PIXI_${key.toUpperCase().replace(/-/g, '_')}`
}
const inputOrEnvironmentVariable = (key: string): string | undefined => {
const inputValue = core.getInput(key)
// GitHub actions sets empty inputs to the empty string
if (inputValue !== '') {
return inputValue
}
const envVarName = getEnvironmentVariableName(key)
const envVarValue = process.env[envVarName]
// Empty environment variables are treated as undefined
if (envVarValue !== undefined && envVarValue !== '') {
core.debug(`Using environment variable ${envVarName} with value: ${envVarValue}`)
return envVarValue
}
return undefined
}
const parseOrUndefined = <T>(key: string, schema: z.ZodSchema<T>, errorMessage?: string): T | undefined => {
const input = core.getInput(key)
// GitHub actions sets empty inputs to the empty string, but we want undefined
if (input === '') {
const input = inputOrEnvironmentVariable(key)
if (input === undefined) {
return undefined
}
const maybeResult = schema.safeParse(input)
@@ -111,18 +131,16 @@ const parseOrUndefined = <T>(key: string, schema: z.ZodSchema<T>, errorMessage?:
}
const parseOrUndefinedJSON = <T>(key: string, schema: z.ZodSchema<T>): T | undefined => {
const input = core.getInput(key)
// GitHub actions sets empty inputs to the empty string, but we want undefined
if (input === '') {
const input = inputOrEnvironmentVariable(key)
if (input === undefined) {
return undefined
}
return schema.parse(JSON.parse(input))
}
const parseOrUndefinedList = <T>(key: string, schema: z.ZodSchema<T>): T[] | undefined => {
const input = core.getInput(key)
// GitHub actions sets empty inputs to the empty string, but we want undefined
if (input === '') {
const input = inputOrEnvironmentVariable(key)
if (input === undefined) {
return undefined
}
return input