Skip to content

Commit 273e480

Browse files
ytauschpavelzw
andauthored
feat: Add pixi-url-bearer-token to authenticate when downloading from pixi-url (#210)
Co-authored-by: Pavel Zwerschke <pavelzw@gmail.com>
1 parent c690703 commit 273e480

File tree

10 files changed

+104
-24
lines changed

10 files changed

+104
-24
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:8080 {
2+
@unauthorized not header Authorization "Bearer s3cr3tT0k3nABC123"
3+
respond @unauthorized "Unauthorized: Invalid token" 401
4+
5+
root * ./assets
6+
file_server
7+
}

.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=17
50+
count_expected=18
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,47 @@ jobs:
190190
pixi-url: https://github.com/prefix-dev/pixi/releases/download/v0.14.0/pixi-x86_64-unknown-linux-musl
191191
- run: pixi --version | grep -q "pixi 0.14.0"
192192

193+
pixi-url-bearer-token:
194+
runs-on: ubuntu-latest
195+
steps:
196+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
197+
- name: Move pixi.toml
198+
run: mv test/old-pixi-lockfiles/* .
199+
- name: Setup caddy
200+
run: |
201+
set -euo pipefail
202+
curl -Ls -o caddy.tar.gz https://github.com/caddyserver/caddy/releases/download/v2.10.0/caddy_2.10.0_linux_amd64.tar.gz
203+
tar -xzf caddy.tar.gz
204+
chmod +x caddy
205+
206+
mkdir -p assets
207+
curl -Ls -o assets/pixi https://github.com/prefix-dev/pixi/releases/download/v0.14.0/pixi-x86_64-unknown-linux-musl
208+
209+
cp .github/assets/pixi-url-auth-test/Caddyfile .
210+
211+
./caddy run --config Caddyfile &
212+
- run: ps -aux | grep caddy
213+
- name: Run with wrong token
214+
uses: ./
215+
id: wrongtoken
216+
with:
217+
cache: false
218+
pixi-url: http://localhost:8080/pixi
219+
pixi-url-bearer-token: wrongtoken
220+
continue-on-error: true
221+
- name: Fail if wrong token did not fail
222+
run: |
223+
echo "Unexpected success!"
224+
exit 1
225+
if: ${{ steps.wrongtoken.outcome != 'failure' }}
226+
- name: Run with correct token
227+
uses: ./
228+
with:
229+
cache: false
230+
pixi-url: http://localhost:8080/pixi
231+
pixi-url-bearer-token: s3cr3tT0k3nABC123
232+
- run: pixi --version | grep -q "pixi 0.14.0"
233+
193234
custom-manifest-path:
194235
strategy:
195236
matrix:

README.md

Lines changed: 29 additions & 17 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.8.10
26+
- uses: prefix-dev/setup-pixi@v0.8.11
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/setup-pixi@v0.8.10`) to avoid breaking changes.
38+
> Please pin the versions of this action to a specific version (i.e., `prefix-dev/setup-pixi@v0.8.11`) 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:
@@ -74,7 +74,7 @@ In order to not exceed the [10 GB cache size limit](https://docs.github.com/en/a
7474
This can be done by setting the `cache-write` argument.
7575

7676
```yml
77-
- uses: prefix-dev/setup-pixi@v0.8.10
77+
- uses: prefix-dev/setup-pixi@v0.8.11
7878
with:
7979
cache: true
8080
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
@@ -119,7 +119,7 @@ test:
119119
environment: [py311, py312]
120120
steps:
121121
- uses: actions/checkout@v4
122-
- uses: prefix-dev/setup-pixi@v0.8.10
122+
- uses: prefix-dev/setup-pixi@v0.8.11
123123
with:
124124
environments: ${{ matrix.environment }}
125125
```
@@ -129,7 +129,7 @@ test:
129129
The following example will install both the `py311` and the `py312` environment on the runner.
130130

131131
```yml
132-
- uses: prefix-dev/setup-pixi@v0.8.10
132+
- uses: prefix-dev/setup-pixi@v0.8.11
133133
with:
134134
# separated by spaces
135135
environments: >-
@@ -165,7 +165,7 @@ Specify the token using the `auth-token` input argument.
165165
This form of authentication (bearer token in the request headers) is mainly used at [prefix.dev](https://prefix.dev).
166166

167167
```yml
168-
- uses: prefix-dev/setup-pixi@v0.8.10
168+
- uses: prefix-dev/setup-pixi@v0.8.11
169169
with:
170170
auth-host: prefix.dev
171171
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
@@ -177,7 +177,7 @@ Specify the username and password using the `auth-username` and `auth-password`
177177
This form of authentication (HTTP Basic Auth) is used in some enterprise environments with [artifactory](https://jfrog.com/artifactory) for example.
178178

179179
```yml
180-
- uses: prefix-dev/setup-pixi@v0.8.10
180+
- uses: prefix-dev/setup-pixi@v0.8.11
181181
with:
182182
auth-host: custom-artifactory.com
183183
auth-username: ${{ secrets.PIXI_USERNAME }}
@@ -190,7 +190,7 @@ Specify the conda-token using the `auth-conda-token` input argument.
190190
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).
191191

192192
```yml
193-
- uses: prefix-dev/setup-pixi@v0.8.10
193+
- uses: prefix-dev/setup-pixi@v0.8.11
194194
with:
195195
auth-host: anaconda.org # or my-quetz-instance.com
196196
auth-conda-token: ${{ secrets.CONDA_TOKEN }}
@@ -202,7 +202,7 @@ Specify the S3 key pair using the `auth-access-key-id` and `auth-secret-access-k
202202
You can also specify the session token using the `auth-session-token` input argument.
203203

204204
```yaml
205-
- uses: prefix-dev/setup-pixi@v0.8.10
205+
- uses: prefix-dev/setup-pixi@v0.8.11
206206
with:
207207
auth-host: s3://my-s3-bucket
208208
auth-s3-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
@@ -274,15 +274,15 @@ To this end, `setup-pixi` adds all environment variables set when executing `pix
274274
As a result, all installed binaries can be accessed without having to call `pixi run`.
275275

276276
```yml
277-
- uses: prefix-dev/setup-pixi@v0.8.10
277+
- uses: prefix-dev/setup-pixi@v0.8.11
278278
with:
279279
activate-environment: true
280280
```
281281

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

284284
```yml
285-
- uses: prefix-dev/setup-pixi@v0.8.10
285+
- uses: prefix-dev/setup-pixi@v0.8.11
286286
with:
287287
environments: >-
288288
py311
@@ -299,7 +299,7 @@ You can specify whether `setup-pixi` should run `pixi install --frozen` or `pixi
299299
See the [official documentation](https://prefix.dev/docs/pixi/cli#install) for more information about the `--frozen` and `--locked` flags.
300300

301301
```yml
302-
- uses: prefix-dev/setup-pixi@v0.8.10
302+
- uses: prefix-dev/setup-pixi@v0.8.11
303303
with:
304304
locked: true
305305
# or
@@ -318,7 +318,7 @@ The first one is the debug logging of the action itself.
318318
This can be enabled by running the action with the `RUNNER_DEBUG` environment variable set to `true`.
319319

320320
```yml
321-
- uses: prefix-dev/setup-pixi@v0.8.10
321+
- uses: prefix-dev/setup-pixi@v0.8.11
322322
env:
323323
RUNNER_DEBUG: true
324324
```
@@ -336,7 +336,7 @@ The second type is the debug logging of the pixi executable.
336336
This can be specified by setting the `log-level` input.
337337

338338
```yml
339-
- uses: prefix-dev/setup-pixi@v0.8.10
339+
- uses: prefix-dev/setup-pixi@v0.8.11
340340
with:
341341
# one of `q`, `default`, `v`, `vv`, or `vvv`.
342342
log-level: vvv
@@ -362,7 +362,7 @@ If nothing is specified, `post-cleanup` will default to `true`.
362362
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.
363363

364364
```yml
365-
- uses: prefix-dev/setup-pixi@v0.8.10
365+
- uses: prefix-dev/setup-pixi@v0.8.11
366366
with:
367367
post-cleanup: true
368368
# ${{ runner.temp }}\Scripts\pixi.exe on Windows
@@ -378,7 +378,7 @@ You can also use a preinstalled local version of pixi on the runner by not setti
378378
This can be overwritten by setting the `manifest-path` input argument.
379379

380380
```yml
381-
- uses: prefix-dev/setup-pixi@v0.8.10
381+
- uses: prefix-dev/setup-pixi@v0.8.11
382382
with:
383383
manifest-path: pyproject.toml
384384
```
@@ -388,11 +388,23 @@ This can be overwritten by setting the `manifest-path` input argument.
388388
If you only want to install pixi and not install the current project, you can use the `run-install` option.
389389

390390
```yml
391-
- uses: prefix-dev/setup-pixi@v0.8.10
391+
- uses: prefix-dev/setup-pixi@v0.8.11
392392
with:
393393
run-install: false
394394
```
395395

396+
### Download pixi from a custom URL
397+
398+
You can also download pixi from a custom URL by setting the `pixi-url` input argument.
399+
Optionally, you can combine this with the `pixi-url-bearer-token` input argument to authenticate the download request.
400+
401+
```yml
402+
- uses: prefix-dev/setup-pixi@v0.8.11
403+
with:
404+
pixi-url: https://pixi-mirror.example.com/releases/download/v0.48.0/pixi-x86_64-unknown-linux-musl
405+
pixi-url-bearer-token: ${{ secrets.PIXI_MIRROR_BEARER_TOKEN }}
406+
```
407+
396408
## More examples
397409

398410
If you want to see more examples, you can take a look at the [GitHub Workflows of this repository](.github/workflows/test.yml).

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ inputs:
1010
description: Version of pixi to install
1111
pixi-url:
1212
description: URL of pixi to install
13+
pixi-url-bearer-token:
14+
description: Bearer token to use for authentication when downloading pixi from a URL.
1315
log-level:
1416
description: |
1517
Log level for the pixi CLI.

dist/index.js

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

dist/post.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-pixi",
3-
"version": "0.8.10",
3+
"version": "0.8.11",
44
"private": true,
55
"description": "Action to set up the pixi package manager.",
66
"scripts": {

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import { activateEnvironment } from './activate'
1212

1313
const downloadPixi = (source: PixiSource) => {
1414
const url = 'version' in source ? getPixiUrlFromVersion(source.version) : source.url
15+
const auth = 'bearerToken' in source && source.bearerToken ? `Bearer ${source.bearerToken}` : ''
1516
return core.group('Downloading Pixi', () => {
1617
core.debug('Installing pixi')
1718
core.debug(`Downloading pixi from ${url}`)
19+
core.debug(`Using Bearer auth: ${auth ? 'yes' : 'no'}`)
1820
return fs
1921
.mkdir(path.dirname(options.pixiBinPath), { recursive: true })
20-
.then(() => downloadTool(url, options.pixiBinPath))
22+
.then(() => downloadTool(url, options.pixiBinPath, auth))
2123
.then((_downloadPath) => fs.chmod(options.pixiBinPath, 0o755))
2224
.then(() => {
2325
core.info(`Pixi installed to ${options.pixiBinPath}`)

src/options.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import which from 'which'
1111
type Inputs = Readonly<{
1212
pixiVersion?: string
1313
pixiUrl?: string
14+
pixiUrlBearerToken?: string
1415
logLevel?: LogLevel
1516
manifestPath?: string
1617
runInstall?: boolean
@@ -39,6 +40,7 @@ export type PixiSource =
3940
}
4041
| {
4142
url: string
43+
bearerToken?: string
4244
}
4345

4446
type Auth = {
@@ -133,6 +135,9 @@ const validateInputs = (inputs: Inputs): void => {
133135
if (inputs.pixiVersion && inputs.pixiUrl) {
134136
throw new Error('You need to specify either pixi-version or pixi-url')
135137
}
138+
if (inputs.pixiUrlBearerToken && !inputs.pixiUrl) {
139+
throw new Error('You need to specify pixi-url when using pixi-url-bearer-token')
140+
}
136141
if (inputs.cacheKey !== undefined && inputs.cache === false) {
137142
throw new Error('Cannot specify cache key without caching')
138143
}
@@ -223,7 +228,7 @@ const inferOptions = (inputs: Inputs): Options => {
223228
const pixiSource = inputs.pixiVersion
224229
? { version: inputs.pixiVersion }
225230
: inputs.pixiUrl
226-
? { url: inputs.pixiUrl }
231+
? { url: inputs.pixiUrl, bearerToken: inputs.pixiUrlBearerToken }
227232
: { version: 'latest' }
228233

229234
const { downloadPixi, pixiBinPath } = determinePixiInstallation(
@@ -340,6 +345,7 @@ const getOptions = () => {
340345
'pixi-version must either be `latest` or a version string matching `vX.Y.Z`.'
341346
),
342347
pixiUrl: parseOrUndefined('pixi-url', z.string().url()),
348+
pixiUrlBearerToken: parseOrUndefined('pixi-url-bearer-token', z.string()),
343349
logLevel: parseOrUndefined(
344350
'log-level',
345351
logLevelSchema,

0 commit comments

Comments
 (0)