Skip to content

Commit b9c8c4c

Browse files
authored
feat: add download-from-astral-mirror input (#897)
## Summary Add a new boolean input `download-from-astral-mirror` (default: `true`) that controls whether uv is downloaded from the Astral mirror or directly from GitHub Releases. When set to `false`, the mirror rewrite is skipped entirely and the download goes straight to GitHub Releases. Closes: #870
1 parent 80cc275 commit b9c8c4c

10 files changed

Lines changed: 66 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,20 @@ jobs:
861861
exit 1
862862
fi
863863
864+
test-download-from-astral-mirror-false:
865+
runs-on: ubuntu-latest
866+
steps:
867+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
868+
with:
869+
persist-credentials: false
870+
- name: Install with download-from-astral-mirror disabled
871+
id: setup-uv
872+
uses: ./
873+
with:
874+
download-from-astral-mirror: false
875+
- name: Verify uv is installed
876+
run: uv --version
877+
864878
test-absolute-path:
865879
runs-on: ubuntu-latest
866880
steps:
@@ -1119,6 +1133,7 @@ jobs:
11191133
- test-restore-cache-restore-cache-false
11201134
- test-no-python-version
11211135
- test-custom-manifest-file
1136+
- test-download-from-astral-mirror-false
11221137
- test-absolute-path
11231138
- test-relative-path
11241139
- test-cache-prune-force

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
120120
# URL to a custom manifest file in the astral-sh/versions format
121121
manifest-file: ""
122122
123+
# Download uv from the Astral mirror instead of directly from GitHub Releases
124+
download-from-astral-mirror: "true"
125+
123126
# Add problem matchers
124127
add-problem-matchers: "true"
125128
```

__tests__/download/download-version.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,32 @@ describe("download-version", () => {
376376
"0.9.26",
377377
);
378378
});
379+
380+
it("skips the Astral mirror when downloadFromAstralMirror is false", async () => {
381+
mockGetArtifact.mockResolvedValue({
382+
archiveFormat: "tar.gz",
383+
checksum: "abc123",
384+
downloadUrl:
385+
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
386+
});
387+
388+
await downloadVersion(
389+
"unknown-linux-gnu",
390+
"x86_64",
391+
"0.9.26",
392+
undefined,
393+
"token",
394+
undefined,
395+
false,
396+
);
397+
398+
expect(mockDownloadTool).toHaveBeenCalledWith(
399+
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
400+
undefined,
401+
"token",
402+
);
403+
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
404+
});
379405
});
380406

381407
describe("rewriteToMirror", () => {

action-types.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ inputs:
5252
type: string
5353
manifest-file:
5454
type: string
55+
download-from-astral-mirror:
56+
type: boolean
5557
add-problem-matchers:
5658
type: boolean
5759
resolution-strategy:

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ inputs:
8080
manifest-file:
8181
description: "URL to a custom manifest file in the astral-sh/versions format."
8282
required: false
83+
download-from-astral-mirror:
84+
description: "Download uv from the Astral mirror instead of directly from GitHub Releases."
85+
default: "true"
8386
add-problem-matchers:
8487
description: "Add problem matchers."
8588
default: "true"

dist/save-cache/index.cjs

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

dist/setup/index.cjs

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

src/download/download-version.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function downloadVersion(
3636
checksum: string | undefined,
3737
githubToken: string,
3838
manifestUrl?: string,
39+
downloadFromAstralMirror = true,
3940
): Promise<{ version: string; cachedToolDir: string }> {
4041
const artifact = await getArtifact(version, arch, platform, manifestUrl);
4142

@@ -52,7 +53,9 @@ export async function downloadVersion(
5253
? checksum
5354
: resolveChecksum(checksum, artifact.checksum);
5455

55-
const mirrorUrl = rewriteToMirror(artifact.downloadUrl);
56+
const mirrorUrl = downloadFromAstralMirror
57+
? rewriteToMirror(artifact.downloadUrl)
58+
: undefined;
5659
const downloadUrl = mirrorUrl ?? artifact.downloadUrl;
5760

5861
try {

src/setup-uv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ async function setupUv(
154154
inputs.checksum,
155155
inputs.githubToken,
156156
inputs.manifestFile,
157+
inputs.downloadFromAstralMirror,
157158
);
158159

159160
return {

src/utils/inputs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface SetupInputs {
4040
pythonDir: string;
4141
githubToken: string;
4242
manifestFile?: string;
43+
downloadFromAstralMirror: boolean;
4344
addProblemMatchers: boolean;
4445
resolutionStrategy: ResolutionStrategy;
4546
}
@@ -73,6 +74,8 @@ export function loadInputs(): SetupInputs {
7374
const pythonDir = getUvPythonDir();
7475
const githubToken = core.getInput("github-token");
7576
const manifestFile = getManifestFile();
77+
const downloadFromAstralMirror =
78+
core.getInput("download-from-astral-mirror") === "true";
7679
const addProblemMatchers = core.getInput("add-problem-matchers") === "true";
7780
const resolutionStrategy = getResolutionStrategy();
7881

@@ -84,6 +87,7 @@ export function loadInputs(): SetupInputs {
8487
cachePython,
8588
cacheSuffix,
8689
checksum,
90+
downloadFromAstralMirror,
8791
enableCache,
8892
githubToken,
8993
ignoreEmptyWorkdir,

0 commit comments

Comments
 (0)