Skip to content

Commit e06108d

Browse files
authored
Use astral-sh/versions as primary version provider (#802)
Closes: #777 Closes: #325
1 parent 0f6ec07 commit e06108d

28 files changed

Lines changed: 3655 additions & 42927 deletions

‎.github/release-drafter.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ categories:
1919
labels:
2020
- "maintenance"
2121
- "ci"
22-
- "update-known-versions"
22+
- "update-known-checksums"
2323
- title: "📚 Documentation"
2424
labels:
2525
- "documentation"

.github/workflows/update-known-versions.yml renamed to .github/workflows/update-known-checksums.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Update known versions"
1+
name: "Update known checksums"
22
on:
33
workflow_dispatch:
44
schedule:
@@ -21,13 +21,11 @@ jobs:
2121
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
2222
with:
2323
node-version: "20"
24-
- name: Update known versions
25-
id: update-known-versions
24+
- name: Update known checksums
25+
id: update-known-checksums
2626
run:
27-
node dist/update-known-versions/index.js
27+
node dist/update-known-checksums/index.js
2828
src/download/checksum/known-checksums.ts
29-
version-manifest.json
30-
${{ secrets.GITHUB_TOKEN }}
3129
- name: Check for changes
3230
id: changes-exist
3331
run: |
@@ -48,10 +46,10 @@ jobs:
4846
git config user.name "$GITHUB_ACTOR"
4947
git config user.email "[email protected]"
5048
git add .
51-
git commit -m "chore: update known versions for $LATEST_VERSION"
49+
git commit -m "chore: update known checksums for $LATEST_VERSION"
5250
git push origin HEAD:refs/heads/main
5351
env:
54-
LATEST_VERSION: ${{ steps.update-known-versions.outputs.latest-version }}
52+
LATEST_VERSION: ${{ steps.update-known-checksums.outputs.latest-version }}
5553

5654
- name: Create Pull Request
5755
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' && steps.commit-and-push.outcome != 'success' }}
@@ -60,11 +58,11 @@ jobs:
6058
commit-message: "chore: update known checksums"
6159
title:
6260
"chore: update known checksums for ${{
63-
steps.update-known-versions.outputs.latest-version }}"
61+
steps.update-known-checksums.outputs.latest-version }}"
6462
body:
6563
"chore: update known checksums for ${{
66-
steps.update-known-versions.outputs.latest-version }}"
64+
steps.update-known-checksums.outputs.latest-version }}"
6765
base: main
68-
labels: "automated-pr,update-known-versions"
69-
branch: update-known-versions-pr
66+
labels: "automated-pr,update-known-checksums"
67+
branch: update-known-checksums-pr
7068
delete-branch: true

‎README.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
6868
# The checksum of the uv version to install
6969
checksum: ""
7070
71-
# Used to increase the rate limit when retrieving versions and downloading uv
71+
# Used when downloading uv from GitHub releases
7272
github-token: ${{ github.token }}
7373
7474
# Enable uploading of the uv cache: true, false, or auto (enabled on GitHub-hosted runners, disabled on self-hosted runners)
@@ -114,7 +114,7 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
114114
# Custom path to set UV_TOOL_BIN_DIR to
115115
tool-bin-dir: ""
116116
117-
# URL to the manifest file containing available versions and download URLs
117+
# URL to a custom manifest file (NDJSON preferred, legacy JSON array is deprecated)
118118
manifest-file: ""
119119
120120
# Add problem matchers
@@ -190,10 +190,12 @@ For more advanced configuration options, see our detailed documentation:
190190

191191
## How it works
192192

193-
This action downloads uv from the uv repo's official
194-
[GitHub Releases](https://github.com/astral-sh/uv) and uses the
195-
[GitHub Actions Toolkit](https://github.com/actions/toolkit) to cache it as a tool to speed up
196-
consecutive runs on self-hosted runners.
193+
By default, this action resolves uv versions from
194+
[`astral-sh/versions`](https://github.com/astral-sh/versions) (NDJSON) and downloads uv from the
195+
official [GitHub Releases](https://github.com/astral-sh/uv).
196+
197+
It then uses the [GitHub Actions Toolkit](https://github.com/actions/toolkit) to cache uv as a
198+
tool to speed up consecutive runs on self-hosted runners.
197199

198200
The installed version of uv is then added to the runner PATH, enabling later steps to invoke it
199201
by name (`uv`).

‎__tests__/download/checksum/checksum.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {
44
validateChecksum,
55
} from "../../../src/download/checksum/checksum";
66

7+
const validChecksum =
8+
"f3da96ec7e995debee7f5d52ecd034dfb7074309a1da42f76429ecb814d813a3";
9+
const filePath = "__tests__/fixtures/checksumfile";
10+
711
test("checksum should match", async () => {
8-
const validChecksum =
9-
"f3da96ec7e995debee7f5d52ecd034dfb7074309a1da42f76429ecb814d813a3";
10-
const filePath = "__tests__/fixtures/checksumfile";
1112
// string params don't matter only test the checksum mechanism, not known checksums
1213
await validateChecksum(
1314
validChecksum,
@@ -18,6 +19,16 @@ test("checksum should match", async () => {
1819
);
1920
});
2021

22+
test("provided checksum beats known checksums", async () => {
23+
await validateChecksum(
24+
validChecksum,
25+
filePath,
26+
"x86_64",
27+
"unknown-linux-gnu",
28+
"0.3.0",
29+
);
30+
});
31+
2132
type KnownVersionFixture = { version: string; known: boolean };
2233

2334
it.each<KnownVersionFixture>([
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
2+
3+
const mockInfo = jest.fn();
4+
const mockWarning = jest.fn();
5+
6+
jest.mock("@actions/core", () => ({
7+
debug: jest.fn(),
8+
info: mockInfo,
9+
warning: mockWarning,
10+
}));
11+
12+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
13+
const mockDownloadTool = jest.fn<any>();
14+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
15+
const mockExtractTar = jest.fn<any>();
16+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
17+
const mockExtractZip = jest.fn<any>();
18+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
19+
const mockCacheDir = jest.fn<any>();
20+
21+
jest.mock("@actions/tool-cache", () => {
22+
const actual = jest.requireActual("@actions/tool-cache") as Record<
23+
string,
24+
unknown
25+
>;
26+
27+
return {
28+
...actual,
29+
cacheDir: mockCacheDir,
30+
downloadTool: mockDownloadTool,
31+
extractTar: mockExtractTar,
32+
extractZip: mockExtractZip,
33+
};
34+
});
35+
36+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
37+
const mockGetLatestVersionFromNdjson = jest.fn<any>();
38+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
39+
const mockGetAllVersionsFromNdjson = jest.fn<any>();
40+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
41+
const mockGetArtifactFromNdjson = jest.fn<any>();
42+
43+
jest.mock("../../src/download/versions-client", () => ({
44+
getAllVersions: mockGetAllVersionsFromNdjson,
45+
getArtifact: mockGetArtifactFromNdjson,
46+
getLatestVersion: mockGetLatestVersionFromNdjson,
47+
}));
48+
49+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
50+
const mockGetAllManifestVersions = jest.fn<any>();
51+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
52+
const mockGetLatestVersionInManifest = jest.fn<any>();
53+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
54+
const mockGetManifestArtifact = jest.fn<any>();
55+
56+
jest.mock("../../src/download/version-manifest", () => ({
57+
getAllVersions: mockGetAllManifestVersions,
58+
getLatestKnownVersion: mockGetLatestVersionInManifest,
59+
getManifestArtifact: mockGetManifestArtifact,
60+
}));
61+
62+
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
63+
const mockValidateChecksum = jest.fn<any>();
64+
65+
jest.mock("../../src/download/checksum/checksum", () => ({
66+
validateChecksum: mockValidateChecksum,
67+
}));
68+
69+
import {
70+
downloadVersionFromManifest,
71+
downloadVersionFromNdjson,
72+
resolveVersion,
73+
} from "../../src/download/download-version";
74+
75+
describe("download-version", () => {
76+
beforeEach(() => {
77+
mockInfo.mockReset();
78+
mockWarning.mockReset();
79+
mockDownloadTool.mockReset();
80+
mockExtractTar.mockReset();
81+
mockExtractZip.mockReset();
82+
mockCacheDir.mockReset();
83+
mockGetLatestVersionFromNdjson.mockReset();
84+
mockGetAllVersionsFromNdjson.mockReset();
85+
mockGetArtifactFromNdjson.mockReset();
86+
mockGetAllManifestVersions.mockReset();
87+
mockGetLatestVersionInManifest.mockReset();
88+
mockGetManifestArtifact.mockReset();
89+
mockValidateChecksum.mockReset();
90+
91+
mockDownloadTool.mockResolvedValue("/tmp/downloaded");
92+
mockExtractTar.mockResolvedValue("/tmp/extracted");
93+
mockExtractZip.mockResolvedValue("/tmp/extracted");
94+
mockCacheDir.mockResolvedValue("/tmp/cached");
95+
});
96+
97+
describe("resolveVersion", () => {
98+
it("uses astral-sh/versions to resolve latest", async () => {
99+
mockGetLatestVersionFromNdjson.mockResolvedValue("0.9.26");
100+
101+
const version = await resolveVersion("latest", undefined);
102+
103+
expect(version).toBe("0.9.26");
104+
expect(mockGetLatestVersionFromNdjson).toHaveBeenCalledTimes(1);
105+
});
106+
107+
it("uses astral-sh/versions to resolve available versions", async () => {
108+
mockGetAllVersionsFromNdjson.mockResolvedValue(["0.9.26", "0.9.25"]);
109+
110+
const version = await resolveVersion("^0.9.0", undefined);
111+
112+
expect(version).toBe("0.9.26");
113+
expect(mockGetAllVersionsFromNdjson).toHaveBeenCalledTimes(1);
114+
});
115+
116+
it("does not fall back when astral-sh/versions fails", async () => {
117+
mockGetLatestVersionFromNdjson.mockRejectedValue(
118+
new Error("NDJSON unavailable"),
119+
);
120+
121+
await expect(resolveVersion("latest", undefined)).rejects.toThrow(
122+
"NDJSON unavailable",
123+
);
124+
});
125+
126+
it("uses manifest-file when provided", async () => {
127+
mockGetAllManifestVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
128+
129+
const version = await resolveVersion(
130+
"^0.9.0",
131+
"https://example.com/custom.ndjson",
132+
);
133+
134+
expect(version).toBe("0.9.26");
135+
expect(mockGetAllManifestVersions).toHaveBeenCalledWith(
136+
"https://example.com/custom.ndjson",
137+
);
138+
});
139+
});
140+
141+
describe("downloadVersionFromNdjson", () => {
142+
it("fails when NDJSON metadata lookup fails", async () => {
143+
mockGetArtifactFromNdjson.mockRejectedValue(
144+
new Error("NDJSON unavailable"),
145+
);
146+
147+
await expect(
148+
downloadVersionFromNdjson(
149+
"unknown-linux-gnu",
150+
"x86_64",
151+
"0.9.26",
152+
undefined,
153+
"token",
154+
),
155+
).rejects.toThrow("NDJSON unavailable");
156+
157+
expect(mockDownloadTool).not.toHaveBeenCalled();
158+
expect(mockValidateChecksum).not.toHaveBeenCalled();
159+
});
160+
161+
it("fails when no matching artifact exists in NDJSON metadata", async () => {
162+
mockGetArtifactFromNdjson.mockResolvedValue(undefined);
163+
164+
await expect(
165+
downloadVersionFromNdjson(
166+
"unknown-linux-gnu",
167+
"x86_64",
168+
"0.9.26",
169+
undefined,
170+
"token",
171+
),
172+
).rejects.toThrow(
173+
"Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson .",
174+
);
175+
176+
expect(mockDownloadTool).not.toHaveBeenCalled();
177+
expect(mockValidateChecksum).not.toHaveBeenCalled();
178+
});
179+
180+
it("uses built-in checksums for default NDJSON downloads", async () => {
181+
mockGetArtifactFromNdjson.mockResolvedValue({
182+
archiveFormat: "tar.gz",
183+
sha256: "ndjson-checksum-that-should-be-ignored",
184+
url: "https://example.com/uv.tar.gz",
185+
});
186+
187+
await downloadVersionFromNdjson(
188+
"unknown-linux-gnu",
189+
"x86_64",
190+
"0.9.26",
191+
undefined,
192+
"token",
193+
);
194+
195+
expect(mockValidateChecksum).toHaveBeenCalledWith(
196+
undefined,
197+
"/tmp/downloaded",
198+
"x86_64",
199+
"unknown-linux-gnu",
200+
"0.9.26",
201+
);
202+
});
203+
});
204+
205+
describe("downloadVersionFromManifest", () => {
206+
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
207+
mockGetManifestArtifact.mockResolvedValue({
208+
archiveFormat: "tar.gz",
209+
checksum: "manifest-checksum",
210+
downloadUrl: "https://example.com/custom-uv.tar.gz",
211+
});
212+
213+
await downloadVersionFromManifest(
214+
"https://example.com/custom.ndjson",
215+
"unknown-linux-gnu",
216+
"x86_64",
217+
"0.9.26",
218+
"",
219+
"token",
220+
);
221+
222+
expect(mockValidateChecksum).toHaveBeenCalledWith(
223+
"manifest-checksum",
224+
"/tmp/downloaded",
225+
"x86_64",
226+
"unknown-linux-gnu",
227+
"0.9.26",
228+
);
229+
});
230+
231+
it("prefers checksum input over manifest-file checksum metadata", async () => {
232+
mockGetManifestArtifact.mockResolvedValue({
233+
archiveFormat: "tar.gz",
234+
checksum: "manifest-checksum",
235+
downloadUrl: "https://example.com/custom-uv.tar.gz",
236+
});
237+
238+
await downloadVersionFromManifest(
239+
"https://example.com/custom.ndjson",
240+
"unknown-linux-gnu",
241+
"x86_64",
242+
"0.9.26",
243+
"user-checksum",
244+
"token",
245+
);
246+
247+
expect(mockValidateChecksum).toHaveBeenCalledWith(
248+
"user-checksum",
249+
"/tmp/downloaded",
250+
"x86_64",
251+
"unknown-linux-gnu",
252+
"0.9.26",
253+
);
254+
});
255+
});
256+
});

0 commit comments

Comments
 (0)