mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-03-29 01:49:53 +00:00
Remove deprecrated custom manifest (#813)
This commit is contained in:
committed by
GitHub
parent
8cc8d1cbfc
commit
89709315bb
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -808,12 +808,12 @@ jobs:
|
|||||||
- name: Install from custom manifest file
|
- name: Install from custom manifest file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
manifest-file: "https://raw.githubusercontent.com/astral-sh/setup-uv/${{ github.ref }}/__tests__/download/custom-manifest.json"
|
manifest-file: "https://raw.githubusercontent.com/astral-sh/setup-uv/${{ github.ref }}/__tests__/download/custom-manifest.ndjson"
|
||||||
- run: uv sync
|
- run: uv sync
|
||||||
working-directory: __tests__/fixtures/uv-project
|
working-directory: __tests__/fixtures/uv-project
|
||||||
- name: Correct version gets installed
|
- name: Correct version gets installed
|
||||||
run: |
|
run: |
|
||||||
if [ "$(uv --version)" != "uv 0.7.12-alpha.1" ]; then
|
if [ "$(uv --version)" != "uv 0.9.26" ]; then
|
||||||
echo "Wrong uv version: $(uv --version)"
|
echo "Wrong uv version: $(uv --version)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
|||||||
# Custom path to set UV_TOOL_BIN_DIR to
|
# Custom path to set UV_TOOL_BIN_DIR to
|
||||||
tool-bin-dir: ""
|
tool-bin-dir: ""
|
||||||
|
|
||||||
# URL to a custom manifest file (NDJSON preferred, legacy JSON array is deprecated)
|
# URL to a custom manifest file in the astral-sh/versions format
|
||||||
manifest-file: ""
|
manifest-file: ""
|
||||||
|
|
||||||
# Add problem matchers
|
# Add problem matchers
|
||||||
@@ -190,8 +190,8 @@ For more advanced configuration options, see our detailed documentation:
|
|||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
By default, this action resolves uv versions from
|
By default, this action resolves uv versions from the
|
||||||
[`astral-sh/versions`](https://github.com/astral-sh/versions) (NDJSON) and downloads uv from the
|
[`astral-sh/versions`](https://github.com/astral-sh/versions) manifest and downloads uv from the
|
||||||
official [GitHub Releases](https://github.com/astral-sh/uv).
|
official [GitHub Releases](https://github.com/astral-sh/uv).
|
||||||
|
|
||||||
It then uses the [GitHub Actions Toolkit](https://github.com/actions/toolkit) to cache uv as a
|
It then uses the [GitHub Actions Toolkit](https://github.com/actions/toolkit) to cache uv as a
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"arch": "x86_64",
|
|
||||||
"artifactName": "uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
"downloadUrl": "https://release.pyx.dev/0.7.12-alpha.1/uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
"platform": "unknown-linux-gnu",
|
|
||||||
"version": "0.7.12-alpha.1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
1
__tests__/download/custom-manifest.ndjson
Normal file
1
__tests__/download/custom-manifest.ndjson
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":"0.9.26","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"30ccbf0a66dc8727a02b0e245c583ee970bdafecf3a443c1686e1b30ec4939e8"}]}
|
||||||
@@ -32,29 +32,16 @@ jest.unstable_mockModule("@actions/tool-cache", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||||
const mockGetLatestVersionFromNdjson = jest.fn<any>();
|
const mockGetLatestVersion = jest.fn<any>();
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||||
const mockGetAllVersionsFromNdjson = jest.fn<any>();
|
const mockGetAllVersions = jest.fn<any>();
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||||
const mockGetArtifactFromNdjson = jest.fn<any>();
|
const mockGetArtifact = jest.fn<any>();
|
||||||
|
|
||||||
jest.unstable_mockModule("../../src/download/versions-client", () => ({
|
jest.unstable_mockModule("../../src/download/manifest", () => ({
|
||||||
getAllVersions: mockGetAllVersionsFromNdjson,
|
getAllVersions: mockGetAllVersions,
|
||||||
getArtifact: mockGetArtifactFromNdjson,
|
getArtifact: mockGetArtifact,
|
||||||
getLatestVersion: mockGetLatestVersionFromNdjson,
|
getLatestVersion: mockGetLatestVersion,
|
||||||
}));
|
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
|
||||||
const mockGetAllManifestVersions = jest.fn<any>();
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
|
||||||
const mockGetLatestVersionInManifest = jest.fn<any>();
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
|
||||||
const mockGetManifestArtifact = jest.fn<any>();
|
|
||||||
|
|
||||||
jest.unstable_mockModule("../../src/download/version-manifest", () => ({
|
|
||||||
getAllVersions: mockGetAllManifestVersions,
|
|
||||||
getLatestKnownVersion: mockGetLatestVersionInManifest,
|
|
||||||
getManifestArtifact: mockGetManifestArtifact,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||||
@@ -64,12 +51,9 @@ jest.unstable_mockModule("../../src/download/checksum/checksum", () => ({
|
|||||||
validateChecksum: mockValidateChecksum,
|
validateChecksum: mockValidateChecksum,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const {
|
const { downloadVersion, resolveVersion, rewriteToMirror } = await import(
|
||||||
downloadVersionFromManifest,
|
"../../src/download/download-version"
|
||||||
downloadVersionFromNdjson,
|
);
|
||||||
resolveVersion,
|
|
||||||
rewriteToMirror,
|
|
||||||
} = await import("../../src/download/download-version");
|
|
||||||
|
|
||||||
describe("download-version", () => {
|
describe("download-version", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -79,12 +63,9 @@ describe("download-version", () => {
|
|||||||
mockExtractTar.mockReset();
|
mockExtractTar.mockReset();
|
||||||
mockExtractZip.mockReset();
|
mockExtractZip.mockReset();
|
||||||
mockCacheDir.mockReset();
|
mockCacheDir.mockReset();
|
||||||
mockGetLatestVersionFromNdjson.mockReset();
|
mockGetLatestVersion.mockReset();
|
||||||
mockGetAllVersionsFromNdjson.mockReset();
|
mockGetAllVersions.mockReset();
|
||||||
mockGetArtifactFromNdjson.mockReset();
|
mockGetArtifact.mockReset();
|
||||||
mockGetAllManifestVersions.mockReset();
|
|
||||||
mockGetLatestVersionInManifest.mockReset();
|
|
||||||
mockGetManifestArtifact.mockReset();
|
|
||||||
mockValidateChecksum.mockReset();
|
mockValidateChecksum.mockReset();
|
||||||
|
|
||||||
mockDownloadTool.mockResolvedValue("/tmp/downloaded");
|
mockDownloadTool.mockResolvedValue("/tmp/downloaded");
|
||||||
@@ -94,36 +75,28 @@ describe("download-version", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveVersion", () => {
|
describe("resolveVersion", () => {
|
||||||
it("uses astral-sh/versions to resolve latest", async () => {
|
it("uses the default manifest to resolve latest", async () => {
|
||||||
mockGetLatestVersionFromNdjson.mockResolvedValue("0.9.26");
|
mockGetLatestVersion.mockResolvedValue("0.9.26");
|
||||||
|
|
||||||
const version = await resolveVersion("latest", undefined);
|
const version = await resolveVersion("latest", undefined);
|
||||||
|
|
||||||
expect(version).toBe("0.9.26");
|
expect(version).toBe("0.9.26");
|
||||||
expect(mockGetLatestVersionFromNdjson).toHaveBeenCalledTimes(1);
|
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockGetLatestVersion).toHaveBeenCalledWith(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses astral-sh/versions to resolve available versions", async () => {
|
it("uses the default manifest to resolve available versions", async () => {
|
||||||
mockGetAllVersionsFromNdjson.mockResolvedValue(["0.9.26", "0.9.25"]);
|
mockGetAllVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
|
||||||
|
|
||||||
const version = await resolveVersion("^0.9.0", undefined);
|
const version = await resolveVersion("^0.9.0", undefined);
|
||||||
|
|
||||||
expect(version).toBe("0.9.26");
|
expect(version).toBe("0.9.26");
|
||||||
expect(mockGetAllVersionsFromNdjson).toHaveBeenCalledTimes(1);
|
expect(mockGetAllVersions).toHaveBeenCalledTimes(1);
|
||||||
});
|
expect(mockGetAllVersions).toHaveBeenCalledWith(undefined);
|
||||||
|
|
||||||
it("does not fall back when astral-sh/versions fails", async () => {
|
|
||||||
mockGetLatestVersionFromNdjson.mockRejectedValue(
|
|
||||||
new Error("NDJSON unavailable"),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(resolveVersion("latest", undefined)).rejects.toThrow(
|
|
||||||
"NDJSON unavailable",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses manifest-file when provided", async () => {
|
it("uses manifest-file when provided", async () => {
|
||||||
mockGetAllManifestVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
|
mockGetAllVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
|
||||||
|
|
||||||
const version = await resolveVersion(
|
const version = await resolveVersion(
|
||||||
"^0.9.0",
|
"^0.9.0",
|
||||||
@@ -131,37 +104,35 @@ describe("download-version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(version).toBe("0.9.26");
|
expect(version).toBe("0.9.26");
|
||||||
expect(mockGetAllManifestVersions).toHaveBeenCalledWith(
|
expect(mockGetAllVersions).toHaveBeenCalledWith(
|
||||||
"https://example.com/custom.ndjson",
|
"https://example.com/custom.ndjson",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("downloadVersionFromNdjson", () => {
|
describe("downloadVersion", () => {
|
||||||
it("fails when NDJSON metadata lookup fails", async () => {
|
it("fails when manifest lookup fails", async () => {
|
||||||
mockGetArtifactFromNdjson.mockRejectedValue(
|
mockGetArtifact.mockRejectedValue(new Error("manifest unavailable"));
|
||||||
new Error("NDJSON unavailable"),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
downloadVersionFromNdjson(
|
downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
undefined,
|
undefined,
|
||||||
"token",
|
"token",
|
||||||
),
|
),
|
||||||
).rejects.toThrow("NDJSON unavailable");
|
).rejects.toThrow("manifest unavailable");
|
||||||
|
|
||||||
expect(mockDownloadTool).not.toHaveBeenCalled();
|
expect(mockDownloadTool).not.toHaveBeenCalled();
|
||||||
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when no matching artifact exists in NDJSON metadata", async () => {
|
it("fails when no matching artifact exists in the default manifest", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue(undefined);
|
mockGetArtifact.mockResolvedValue(undefined);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
downloadVersionFromNdjson(
|
downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -176,14 +147,14 @@ describe("download-version", () => {
|
|||||||
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses built-in checksums for default NDJSON downloads", async () => {
|
it("uses built-in checksums for default manifest downloads", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
sha256: "ndjson-checksum-that-should-be-ignored",
|
checksum: "manifest-checksum-that-should-be-ignored",
|
||||||
url: "https://example.com/uv.tar.gz",
|
downloadUrl: "https://example.com/uv.tar.gz",
|
||||||
});
|
});
|
||||||
|
|
||||||
await downloadVersionFromNdjson(
|
await downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -201,13 +172,14 @@ describe("download-version", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rewrites GitHub Releases URLs to the Astral mirror", async () => {
|
it("rewrites GitHub Releases URLs to the Astral mirror", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
sha256: "abc123",
|
checksum: "abc123",
|
||||||
url: "https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
});
|
});
|
||||||
|
|
||||||
await downloadVersionFromNdjson(
|
await downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -223,13 +195,13 @@ describe("download-version", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not rewrite non-GitHub URLs", async () => {
|
it("does not rewrite non-GitHub URLs", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
sha256: "abc123",
|
checksum: "abc123",
|
||||||
url: "https://example.com/uv.tar.gz",
|
downloadUrl: "https://example.com/uv.tar.gz",
|
||||||
});
|
});
|
||||||
|
|
||||||
await downloadVersionFromNdjson(
|
await downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -245,17 +217,18 @@ describe("download-version", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to GitHub Releases when the mirror fails", async () => {
|
it("falls back to GitHub Releases when the mirror fails", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
sha256: "abc123",
|
checksum: "abc123",
|
||||||
url: "https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
});
|
});
|
||||||
|
|
||||||
mockDownloadTool
|
mockDownloadTool
|
||||||
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||||
.mockResolvedValueOnce("/tmp/downloaded");
|
.mockResolvedValueOnce("/tmp/downloaded");
|
||||||
|
|
||||||
await downloadVersionFromNdjson(
|
await downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -264,14 +237,12 @@ describe("download-version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(mockDownloadTool).toHaveBeenCalledTimes(2);
|
expect(mockDownloadTool).toHaveBeenCalledTimes(2);
|
||||||
// Mirror request: no token
|
|
||||||
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
"https://releases.astral.sh/github/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
"https://releases.astral.sh/github/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
// GitHub fallback: token restored
|
|
||||||
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
@@ -284,16 +255,16 @@ describe("download-version", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not fall back for non-GitHub URLs", async () => {
|
it("does not fall back for non-GitHub URLs", async () => {
|
||||||
mockGetArtifactFromNdjson.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
sha256: "abc123",
|
checksum: "abc123",
|
||||||
url: "https://example.com/uv.tar.gz",
|
downloadUrl: "https://example.com/uv.tar.gz",
|
||||||
});
|
});
|
||||||
|
|
||||||
mockDownloadTool.mockRejectedValue(new Error("download failed"));
|
mockDownloadTool.mockRejectedValue(new Error("download failed"));
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
downloadVersionFromNdjson(
|
downloadVersion(
|
||||||
"unknown-linux-gnu",
|
"unknown-linux-gnu",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"0.9.26",
|
"0.9.26",
|
||||||
@@ -304,6 +275,56 @@ describe("download-version", () => {
|
|||||||
|
|
||||||
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "manifest-checksum",
|
||||||
|
downloadUrl: "https://example.com/custom-uv.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.9.26",
|
||||||
|
"",
|
||||||
|
"token",
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
||||||
|
"manifest-checksum",
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"x86_64",
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"0.9.26",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers checksum input over manifest-file checksum metadata", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "manifest-checksum",
|
||||||
|
downloadUrl: "https://example.com/custom-uv.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.9.26",
|
||||||
|
"user-checksum",
|
||||||
|
"token",
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
||||||
|
"user-checksum",
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"x86_64",
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"0.9.26",
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("rewriteToMirror", () => {
|
describe("rewriteToMirror", () => {
|
||||||
@@ -329,56 +350,4 @@ describe("download-version", () => {
|
|||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("downloadVersionFromManifest", () => {
|
|
||||||
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
|
|
||||||
mockGetManifestArtifact.mockResolvedValue({
|
|
||||||
archiveFormat: "tar.gz",
|
|
||||||
checksum: "manifest-checksum",
|
|
||||||
downloadUrl: "https://example.com/custom-uv.tar.gz",
|
|
||||||
});
|
|
||||||
|
|
||||||
await downloadVersionFromManifest(
|
|
||||||
"https://example.com/custom.ndjson",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
"x86_64",
|
|
||||||
"0.9.26",
|
|
||||||
"",
|
|
||||||
"token",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
|
||||||
"manifest-checksum",
|
|
||||||
"/tmp/downloaded",
|
|
||||||
"x86_64",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
"0.9.26",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("prefers checksum input over manifest-file checksum metadata", async () => {
|
|
||||||
mockGetManifestArtifact.mockResolvedValue({
|
|
||||||
archiveFormat: "tar.gz",
|
|
||||||
checksum: "manifest-checksum",
|
|
||||||
downloadUrl: "https://example.com/custom-uv.tar.gz",
|
|
||||||
});
|
|
||||||
|
|
||||||
await downloadVersionFromManifest(
|
|
||||||
"https://example.com/custom.ndjson",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
"x86_64",
|
|
||||||
"0.9.26",
|
|
||||||
"user-checksum",
|
|
||||||
"token",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
|
||||||
"user-checksum",
|
|
||||||
"/tmp/downloaded",
|
|
||||||
"x86_64",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
"0.9.26",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
168
__tests__/download/manifest.test.ts
Normal file
168
__tests__/download/manifest.test.ts
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
|
||||||
|
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||||
|
const mockFetch = jest.fn<any>();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.unstable_mockModule("../../src/utils/fetch", () => ({
|
||||||
|
fetch: mockFetch,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const {
|
||||||
|
clearManifestCache,
|
||||||
|
fetchManifest,
|
||||||
|
getAllVersions,
|
||||||
|
getArtifact,
|
||||||
|
getLatestVersion,
|
||||||
|
parseManifest,
|
||||||
|
} = await import("../../src/download/manifest");
|
||||||
|
|
||||||
|
const sampleManifestResponse = `{"version":"0.9.25","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.25/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"606b3c6949d971709f2526fa0d9f0fd23ccf60e09f117999b406b424af18a6a6"}]}
|
||||||
|
{"version":"0.9.26","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f"},{"platform":"x86_64-pc-windows-msvc","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-pc-windows-msvc.zip","archive_format":"zip","sha256":"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036"}]}`;
|
||||||
|
|
||||||
|
const multiVariantManifestResponse = `{"version":"0.9.26","artifacts":[{"platform":"aarch64-apple-darwin","variant":"python-managed","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin-managed.tar.gz","archive_format":"tar.gz","sha256":"managed-checksum"},{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.zip","archive_format":"zip","sha256":"default-checksum"}]}`;
|
||||||
|
|
||||||
|
function createMockResponse(
|
||||||
|
ok: boolean,
|
||||||
|
status: number,
|
||||||
|
statusText: string,
|
||||||
|
data: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
ok,
|
||||||
|
status,
|
||||||
|
statusText,
|
||||||
|
text: async () => data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("manifest", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
clearManifestCache();
|
||||||
|
mockFetch.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchManifest", () => {
|
||||||
|
it("fetches and parses manifest data", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const versions = await fetchManifest();
|
||||||
|
|
||||||
|
expect(versions).toHaveLength(2);
|
||||||
|
expect(versions[0]?.version).toBe("0.9.25");
|
||||||
|
expect(versions[1]?.version).toBe("0.9.26");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws on a failed fetch", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(false, 500, "Internal Server Error", ""),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(fetchManifest()).rejects.toThrow(
|
||||||
|
"Failed to fetch manifest data: 500 Internal Server Error",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("caches results per URL", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
await fetchManifest("https://example.com/custom.ndjson");
|
||||||
|
await fetchManifest("https://example.com/custom.ndjson");
|
||||||
|
|
||||||
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getAllVersions", () => {
|
||||||
|
it("returns all version strings", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const versions = await getAllVersions(
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(versions).toEqual(["0.9.25", "0.9.26"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getArtifact", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("finds an artifact by version and platform", async () => {
|
||||||
|
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum:
|
||||||
|
"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("finds a windows artifact", async () => {
|
||||||
|
const artifact = await getArtifact("0.9.26", "x86_64", "pc-windows-msvc");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "zip",
|
||||||
|
checksum:
|
||||||
|
"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-pc-windows-msvc.zip",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers the default variant when multiple artifacts share a platform", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", multiVariantManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "zip",
|
||||||
|
checksum: "default-checksum",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.zip",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for an unknown version", async () => {
|
||||||
|
const artifact = await getArtifact("0.0.1", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for an unknown platform", async () => {
|
||||||
|
const artifact = await getArtifact(
|
||||||
|
"0.9.26",
|
||||||
|
"aarch64",
|
||||||
|
"unknown-linux-musl",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(artifact).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("parseManifest", () => {
|
||||||
|
it("throws for malformed manifest data", () => {
|
||||||
|
expect(() => parseManifest('{"version":"0.1.0"', "test-source")).toThrow(
|
||||||
|
"Failed to parse manifest data from test-source",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|
||||||
|
|
||||||
const mockWarning = jest.fn();
|
|
||||||
|
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
|
||||||
debug: jest.fn(),
|
|
||||||
info: jest.fn(),
|
|
||||||
warning: mockWarning,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
|
||||||
const mockFetch = jest.fn<any>();
|
|
||||||
jest.unstable_mockModule("../../src/utils/fetch", () => ({
|
|
||||||
fetch: mockFetch,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const {
|
|
||||||
clearManifestCache,
|
|
||||||
getAllVersions,
|
|
||||||
getLatestKnownVersion,
|
|
||||||
getManifestArtifact,
|
|
||||||
} = await import("../../src/download/version-manifest");
|
|
||||||
|
|
||||||
const legacyManifestResponse = JSON.stringify([
|
|
||||||
{
|
|
||||||
arch: "x86_64",
|
|
||||||
artifactName: "uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
downloadUrl:
|
|
||||||
"https://example.com/releases/download/0.7.12-alpha.1/uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
platform: "unknown-linux-gnu",
|
|
||||||
version: "0.7.12-alpha.1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arch: "x86_64",
|
|
||||||
artifactName: "uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
downloadUrl:
|
|
||||||
"https://example.com/releases/download/0.7.13/uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
platform: "unknown-linux-gnu",
|
|
||||||
version: "0.7.13",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const ndjsonManifestResponse = `{"version":"0.10.0","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://example.com/releases/download/0.10.0/uv-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"checksum-100"}]}
|
|
||||||
{"version":"0.9.30","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://example.com/releases/download/0.9.30/uv-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"checksum-0930"}]}`;
|
|
||||||
|
|
||||||
const multiVariantManifestResponse = `{"version":"0.10.0","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"managed-python","url":"https://example.com/releases/download/0.10.0/uv-x86_64-unknown-linux-gnu-managed-python.tar.gz","archive_format":"tar.gz","sha256":"checksum-managed"},{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://example.com/releases/download/0.10.0/uv-x86_64-unknown-linux-gnu-default.zip","archive_format":"zip","sha256":"checksum-default"}]}`;
|
|
||||||
|
|
||||||
function createMockResponse(
|
|
||||||
ok: boolean,
|
|
||||||
status: number,
|
|
||||||
statusText: string,
|
|
||||||
data: string,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
ok,
|
|
||||||
status,
|
|
||||||
statusText,
|
|
||||||
text: async () => data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("version-manifest", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
clearManifestCache();
|
|
||||||
mockFetch.mockReset();
|
|
||||||
mockWarning.mockReset();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("supports the legacy JSON manifest format", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", legacyManifestResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const latest = await getLatestKnownVersion(
|
|
||||||
"https://example.com/legacy.json",
|
|
||||||
);
|
|
||||||
const artifact = await getManifestArtifact(
|
|
||||||
"https://example.com/legacy.json",
|
|
||||||
"0.7.13",
|
|
||||||
"x86_64",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(latest).toBe("0.7.13");
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: undefined,
|
|
||||||
checksum: undefined,
|
|
||||||
downloadUrl:
|
|
||||||
"https://example.com/releases/download/0.7.13/uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
});
|
|
||||||
expect(mockWarning).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("supports NDJSON manifests", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", ndjsonManifestResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const versions = await getAllVersions("https://example.com/custom.ndjson");
|
|
||||||
const artifact = await getManifestArtifact(
|
|
||||||
"https://example.com/custom.ndjson",
|
|
||||||
"0.10.0",
|
|
||||||
"x86_64",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(versions).toEqual(["0.10.0", "0.9.30"]);
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: "tar.gz",
|
|
||||||
checksum: "checksum-100",
|
|
||||||
downloadUrl:
|
|
||||||
"https://example.com/releases/download/0.10.0/uv-x86_64-unknown-linux-gnu.tar.gz",
|
|
||||||
});
|
|
||||||
expect(mockWarning).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("prefers the default variant when a manifest contains multiple variants", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", multiVariantManifestResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const artifact = await getManifestArtifact(
|
|
||||||
"https://example.com/multi-variant.ndjson",
|
|
||||||
"0.10.0",
|
|
||||||
"x86_64",
|
|
||||||
"unknown-linux-gnu",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: "zip",
|
|
||||||
checksum: "checksum-default",
|
|
||||||
downloadUrl:
|
|
||||||
"https://example.com/releases/download/0.10.0/uv-x86_64-unknown-linux-gnu-default.zip",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
|
||||||
const mockFetch = jest.fn<any>();
|
|
||||||
|
|
||||||
jest.unstable_mockModule("../../src/utils/fetch", () => ({
|
|
||||||
fetch: mockFetch,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const {
|
|
||||||
clearCache,
|
|
||||||
fetchVersionData,
|
|
||||||
getAllVersions,
|
|
||||||
getArtifact,
|
|
||||||
getLatestVersion,
|
|
||||||
parseVersionData,
|
|
||||||
} = await import("../../src/download/versions-client");
|
|
||||||
|
|
||||||
const sampleNdjsonResponse = `{"version":"0.9.26","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f"},{"platform":"x86_64-pc-windows-msvc","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-pc-windows-msvc.zip","archive_format":"zip","sha256":"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036"}]}
|
|
||||||
{"version":"0.9.25","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.25/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"606b3c6949d971709f2526fa0d9f0fd23ccf60e09f117999b406b424af18a6a6"}]}`;
|
|
||||||
|
|
||||||
const multiVariantNdjsonResponse = `{"version":"0.9.26","artifacts":[{"platform":"aarch64-apple-darwin","variant":"python-managed","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin-managed.tar.gz","archive_format":"tar.gz","sha256":"managed-checksum"},{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.zip","archive_format":"zip","sha256":"default-checksum"}]}`;
|
|
||||||
|
|
||||||
function createMockResponse(
|
|
||||||
ok: boolean,
|
|
||||||
status: number,
|
|
||||||
statusText: string,
|
|
||||||
data: string,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
ok,
|
|
||||||
status,
|
|
||||||
statusText,
|
|
||||||
text: async () => data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("versions-client", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
clearCache();
|
|
||||||
mockFetch.mockReset();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("fetchVersionData", () => {
|
|
||||||
it("should fetch and parse NDJSON data", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", sampleNdjsonResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const versions = await fetchVersionData();
|
|
||||||
|
|
||||||
expect(versions).toHaveLength(2);
|
|
||||||
expect(versions[0].version).toBe("0.9.26");
|
|
||||||
expect(versions[1].version).toBe("0.9.25");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw error on failed fetch", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(false, 500, "Internal Server Error", ""),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(fetchVersionData()).rejects.toThrow(
|
|
||||||
"Failed to fetch version data: 500 Internal Server Error",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should cache results", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", sampleNdjsonResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
await fetchVersionData();
|
|
||||||
await fetchVersionData();
|
|
||||||
|
|
||||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getLatestVersion", () => {
|
|
||||||
it("should return the first version (newest)", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", sampleNdjsonResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const latest = await getLatestVersion();
|
|
||||||
|
|
||||||
expect(latest).toBe("0.9.26");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getAllVersions", () => {
|
|
||||||
it("should return all version strings", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", sampleNdjsonResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const versions = await getAllVersions();
|
|
||||||
|
|
||||||
expect(versions).toEqual(["0.9.26", "0.9.25"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getArtifact", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", sampleNdjsonResponse),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should find artifact by version and platform", async () => {
|
|
||||||
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
|
|
||||||
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: "tar.gz",
|
|
||||||
sha256:
|
|
||||||
"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f",
|
|
||||||
url: "https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should find windows artifact", async () => {
|
|
||||||
const artifact = await getArtifact("0.9.26", "x86_64", "pc-windows-msvc");
|
|
||||||
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: "zip",
|
|
||||||
sha256:
|
|
||||||
"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036",
|
|
||||||
url: "https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-pc-windows-msvc.zip",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should prefer the default variant when multiple artifacts share a platform", async () => {
|
|
||||||
mockFetch.mockResolvedValue(
|
|
||||||
createMockResponse(true, 200, "OK", multiVariantNdjsonResponse),
|
|
||||||
);
|
|
||||||
|
|
||||||
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
|
|
||||||
|
|
||||||
expect(artifact).toEqual({
|
|
||||||
archiveFormat: "zip",
|
|
||||||
sha256: "default-checksum",
|
|
||||||
url: "https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.zip",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return undefined for unknown version", async () => {
|
|
||||||
const artifact = await getArtifact("0.0.1", "aarch64", "apple-darwin");
|
|
||||||
|
|
||||||
expect(artifact).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return undefined for unknown platform", async () => {
|
|
||||||
const artifact = await getArtifact(
|
|
||||||
"0.9.26",
|
|
||||||
"aarch64",
|
|
||||||
"unknown-linux-musl",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(artifact).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("parseVersionData", () => {
|
|
||||||
it("should throw for malformed NDJSON", () => {
|
|
||||||
expect(() =>
|
|
||||||
parseVersionData('{"version":"0.1.0"', "test-source"),
|
|
||||||
).toThrow("Failed to parse version data from test-source");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -75,7 +75,7 @@ inputs:
|
|||||||
description: "Custom path to set UV_TOOL_BIN_DIR to."
|
description: "Custom path to set UV_TOOL_BIN_DIR to."
|
||||||
required: false
|
required: false
|
||||||
manifest-file:
|
manifest-file:
|
||||||
description: "URL to a custom manifest file. Supports the astral-sh/versions NDJSON format and the legacy JSON array format (deprecated)."
|
description: "URL to a custom manifest file in the astral-sh/versions format."
|
||||||
required: false
|
required: false
|
||||||
add-problem-matchers:
|
add-problem-matchers:
|
||||||
description: "Add problem matchers."
|
description: "Add problem matchers."
|
||||||
|
|||||||
360
dist/setup/index.cjs
generated
vendored
360
dist/setup/index.cjs
generated
vendored
@@ -91886,7 +91886,7 @@ var semver5 = __toESM(require_semver5(), 1);
|
|||||||
var TOOL_CACHE_NAME = "uv";
|
var TOOL_CACHE_NAME = "uv";
|
||||||
var STATE_UV_PATH = "uv-path";
|
var STATE_UV_PATH = "uv-path";
|
||||||
var STATE_UV_VERSION = "uv-version";
|
var STATE_UV_VERSION = "uv-version";
|
||||||
var VERSIONS_NDJSON_URL = "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
var VERSIONS_MANIFEST_URL = "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
||||||
var GITHUB_RELEASES_PREFIX = "https://github.com/astral-sh/uv/releases/download/";
|
var GITHUB_RELEASES_PREFIX = "https://github.com/astral-sh/uv/releases/download/";
|
||||||
var ASTRAL_MIRROR_PREFIX = "https://releases.astral.sh/github/uv/releases/download/";
|
var ASTRAL_MIRROR_PREFIX = "https://releases.astral.sh/github/uv/releases/download/";
|
||||||
|
|
||||||
@@ -96373,7 +96373,7 @@ async function validateFileCheckSum(filePath, expected) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/download/version-manifest.ts
|
// src/download/manifest.ts
|
||||||
var semver4 = __toESM(require_semver5(), 1);
|
var semver4 = __toESM(require_semver5(), 1);
|
||||||
|
|
||||||
// src/utils/fetch.ts
|
// src/utils/fetch.ts
|
||||||
@@ -96394,45 +96394,6 @@ var fetch = async (url2, opts) => await (0, import_undici2.fetch)(url2, {
|
|||||||
...opts
|
...opts
|
||||||
});
|
});
|
||||||
|
|
||||||
// src/download/legacy-version-manifest.ts
|
|
||||||
var warnedLegacyManifestUrls = /* @__PURE__ */ new Set();
|
|
||||||
function parseLegacyManifestEntries(parsedEntries, manifestUrl) {
|
|
||||||
warnAboutLegacyManifestFormat(manifestUrl);
|
|
||||||
return parsedEntries.map((entry, index) => {
|
|
||||||
if (!isLegacyManifestEntry(entry)) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid legacy manifest-file entry at index ${index} in ${manifestUrl}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
arch: entry.arch,
|
|
||||||
checksum: entry.checksum,
|
|
||||||
downloadUrl: entry.downloadUrl,
|
|
||||||
platform: entry.platform,
|
|
||||||
version: entry.version
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function warnAboutLegacyManifestFormat(manifestUrl) {
|
|
||||||
if (warnedLegacyManifestUrls.has(manifestUrl)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
warnedLegacyManifestUrls.add(manifestUrl);
|
|
||||||
warning(
|
|
||||||
`manifest-file ${manifestUrl} uses the legacy JSON array format, which is deprecated. Please migrate to the astral-sh/versions NDJSON format before the next major release.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
function isLegacyManifestEntry(value) {
|
|
||||||
if (!isRecord(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const checksumIsValid = typeof value.checksum === "string" || value.checksum === void 0;
|
|
||||||
return typeof value.arch === "string" && checksumIsValid && typeof value.downloadUrl === "string" && typeof value.platform === "string" && typeof value.version === "string";
|
|
||||||
}
|
|
||||||
function isRecord(value) {
|
|
||||||
return typeof value === "object" && value !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/download/variant-selection.ts
|
// src/download/variant-selection.ts
|
||||||
function selectDefaultVariant(entries, duplicateEntryDescription) {
|
function selectDefaultVariant(entries, duplicateEntryDescription) {
|
||||||
const firstEntry = entries[0];
|
const firstEntry = entries[0];
|
||||||
@@ -96459,73 +96420,88 @@ function formatVariants(entries) {
|
|||||||
return entries.map((entry) => entry.variant ?? "default").sort((left, right) => left.localeCompare(right)).join(", ");
|
return entries.map((entry) => entry.variant ?? "default").sort((left, right) => left.localeCompare(right)).join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/download/versions-client.ts
|
// src/download/manifest.ts
|
||||||
var cachedVersionData = /* @__PURE__ */ new Map();
|
var cachedManifestData = /* @__PURE__ */ new Map();
|
||||||
async function fetchVersionData(url2 = VERSIONS_NDJSON_URL) {
|
async function fetchManifest(manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const cachedVersions = cachedVersionData.get(url2);
|
const cachedVersions = cachedManifestData.get(manifestUrl);
|
||||||
if (cachedVersions !== void 0) {
|
if (cachedVersions !== void 0) {
|
||||||
debug(`Using cached NDJSON version data from ${url2}`);
|
debug(`Using cached manifest data from ${manifestUrl}`);
|
||||||
return cachedVersions;
|
return cachedVersions;
|
||||||
}
|
}
|
||||||
info(`Fetching version data from ${url2} ...`);
|
info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||||
const response = await fetch(url2, {});
|
const response = await fetch(manifestUrl, {});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to fetch version data: ${response.status} ${response.statusText}`
|
`Failed to fetch manifest data: ${response.status} ${response.statusText}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const body2 = await response.text();
|
const body2 = await response.text();
|
||||||
const versions = parseVersionData(body2, url2);
|
const versions = parseManifest(body2, manifestUrl);
|
||||||
cachedVersionData.set(url2, versions);
|
cachedManifestData.set(manifestUrl, versions);
|
||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
function parseVersionData(data, sourceDescription) {
|
function parseManifest(data, sourceDescription) {
|
||||||
|
const trimmed = data.trim();
|
||||||
|
if (trimmed === "") {
|
||||||
|
throw new Error(`Manifest at ${sourceDescription} is empty.`);
|
||||||
|
}
|
||||||
|
if (trimmed.startsWith("[")) {
|
||||||
|
throw new Error(
|
||||||
|
`Legacy JSON array manifests are no longer supported in ${sourceDescription}. Use the astral-sh/versions manifest format instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
const versions = [];
|
const versions = [];
|
||||||
for (const [index, line] of data.split("\n").entries()) {
|
for (const [index, line] of data.split("\n").entries()) {
|
||||||
const trimmed = line.trim();
|
const record = line.trim();
|
||||||
if (trimmed === "") {
|
if (record === "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let parsed;
|
let parsed;
|
||||||
try {
|
try {
|
||||||
parsed = JSON.parse(trimmed);
|
parsed = JSON.parse(record);
|
||||||
} catch (error2) {
|
} catch (error2) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to parse version data from ${sourceDescription} at line ${index + 1}: ${error2.message}`
|
`Failed to parse manifest data from ${sourceDescription} at line ${index + 1}: ${error2.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isNdjsonVersion(parsed)) {
|
if (!isManifestVersion(parsed)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid NDJSON record in ${sourceDescription} at line ${index + 1}.`
|
`Invalid manifest record in ${sourceDescription} at line ${index + 1}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
versions.push(parsed);
|
versions.push(parsed);
|
||||||
}
|
}
|
||||||
if (versions.length === 0) {
|
if (versions.length === 0) {
|
||||||
throw new Error(`No version data found in ${sourceDescription}.`);
|
throw new Error(`No manifest data found in ${sourceDescription}.`);
|
||||||
}
|
}
|
||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
async function getLatestVersion() {
|
async function getLatestVersion(manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest(manifestUrl);
|
||||||
const latestVersion = versions[0]?.version;
|
const [firstVersion, ...remainingVersions] = versions.map(
|
||||||
if (!latestVersion) {
|
(versionData) => versionData.version
|
||||||
throw new Error("No versions found in NDJSON data");
|
);
|
||||||
|
if (firstVersion === void 0) {
|
||||||
|
throw new Error("No versions found in manifest data");
|
||||||
}
|
}
|
||||||
debug(`Latest version from NDJSON: ${latestVersion}`);
|
const latestVersion = remainingVersions.reduce(
|
||||||
|
(latest, current) => semver4.gt(current, latest) ? current : latest,
|
||||||
|
firstVersion
|
||||||
|
);
|
||||||
|
debug(`Latest version from manifest: ${latestVersion}`);
|
||||||
return latestVersion;
|
return latestVersion;
|
||||||
}
|
}
|
||||||
async function getAllVersions() {
|
async function getAllVersions(manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest(manifestUrl);
|
||||||
return versions.map((versionData) => versionData.version);
|
return versions.map((versionData) => versionData.version);
|
||||||
}
|
}
|
||||||
async function getArtifact(version4, arch3, platform2) {
|
async function getArtifact(version4, arch3, platform2, manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest(manifestUrl);
|
||||||
const versionData = versions.find(
|
const versionData = versions.find(
|
||||||
(candidate) => candidate.version === version4
|
(candidate) => candidate.version === version4
|
||||||
);
|
);
|
||||||
if (!versionData) {
|
if (!versionData) {
|
||||||
debug(`Version ${version4} not found in NDJSON data`);
|
debug(`Version ${version4} not found in manifest ${manifestUrl}`);
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
const targetPlatform = `${arch3}-${platform2}`;
|
const targetPlatform = `${arch3}-${platform2}`;
|
||||||
@@ -96538,143 +96514,36 @@ async function getArtifact(version4, arch3, platform2) {
|
|||||||
);
|
);
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
const artifact = selectArtifact(matchingArtifacts, version4, targetPlatform);
|
const artifact = selectDefaultVariant(
|
||||||
return {
|
matchingArtifacts,
|
||||||
archiveFormat: artifact.archive_format,
|
|
||||||
sha256: artifact.sha256,
|
|
||||||
url: artifact.url
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function selectArtifact(artifacts, version4, targetPlatform) {
|
|
||||||
return selectDefaultVariant(
|
|
||||||
artifacts,
|
|
||||||
`Multiple artifacts found for ${targetPlatform} in version ${version4}`
|
`Multiple artifacts found for ${targetPlatform} in version ${version4}`
|
||||||
);
|
);
|
||||||
|
return {
|
||||||
|
archiveFormat: artifact.archive_format,
|
||||||
|
checksum: artifact.sha256,
|
||||||
|
downloadUrl: artifact.url
|
||||||
|
};
|
||||||
}
|
}
|
||||||
function isNdjsonVersion(value) {
|
function isManifestVersion(value) {
|
||||||
if (!isRecord2(value)) {
|
if (!isRecord(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return value.artifacts.every(isNdjsonArtifact);
|
return value.artifacts.every(isManifestArtifact);
|
||||||
}
|
}
|
||||||
function isNdjsonArtifact(value) {
|
function isManifestArtifact(value) {
|
||||||
if (!isRecord2(value)) {
|
if (!isRecord(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const variantIsValid = typeof value.variant === "string" || value.variant === void 0;
|
const variantIsValid = typeof value.variant === "string" || value.variant === void 0;
|
||||||
return typeof value.archive_format === "string" && typeof value.platform === "string" && typeof value.sha256 === "string" && typeof value.url === "string" && variantIsValid;
|
return typeof value.archive_format === "string" && typeof value.platform === "string" && typeof value.sha256 === "string" && typeof value.url === "string" && variantIsValid;
|
||||||
}
|
}
|
||||||
function isRecord2(value) {
|
function isRecord(value) {
|
||||||
return typeof value === "object" && value !== null;
|
return typeof value === "object" && value !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/download/version-manifest.ts
|
|
||||||
var cachedManifestEntries = /* @__PURE__ */ new Map();
|
|
||||||
async function getLatestKnownVersion(manifestUrl) {
|
|
||||||
const versions = await getAllVersions2(manifestUrl);
|
|
||||||
const latestVersion = versions.reduce(
|
|
||||||
(latest, current) => semver4.gt(current, latest) ? current : latest
|
|
||||||
);
|
|
||||||
return latestVersion;
|
|
||||||
}
|
|
||||||
async function getAllVersions2(manifestUrl) {
|
|
||||||
const manifestEntries = await getManifestEntries(manifestUrl);
|
|
||||||
return [...new Set(manifestEntries.map((entry) => entry.version))];
|
|
||||||
}
|
|
||||||
async function getManifestArtifact(manifestUrl, version4, arch3, platform2) {
|
|
||||||
const manifestEntries = await getManifestEntries(manifestUrl);
|
|
||||||
const entry = selectManifestEntry(
|
|
||||||
manifestEntries,
|
|
||||||
manifestUrl,
|
|
||||||
version4,
|
|
||||||
arch3,
|
|
||||||
platform2
|
|
||||||
);
|
|
||||||
if (!entry) {
|
|
||||||
return void 0;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
archiveFormat: entry.archiveFormat,
|
|
||||||
checksum: entry.checksum,
|
|
||||||
downloadUrl: entry.downloadUrl
|
|
||||||
};
|
|
||||||
}
|
|
||||||
async function getManifestEntries(manifestUrl) {
|
|
||||||
const cachedEntries = cachedManifestEntries.get(manifestUrl);
|
|
||||||
if (cachedEntries !== void 0) {
|
|
||||||
debug(`Using cached manifest-file from: ${manifestUrl}`);
|
|
||||||
return cachedEntries;
|
|
||||||
}
|
|
||||||
info(`Fetching manifest-file from: ${manifestUrl}`);
|
|
||||||
const response = await fetch(manifestUrl, {});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to fetch manifest-file: ${response.status} ${response.statusText}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const data = await response.text();
|
|
||||||
const parsedEntries = parseManifestEntries(data, manifestUrl);
|
|
||||||
cachedManifestEntries.set(manifestUrl, parsedEntries);
|
|
||||||
return parsedEntries;
|
|
||||||
}
|
|
||||||
function parseManifestEntries(data, manifestUrl) {
|
|
||||||
const trimmed = data.trim();
|
|
||||||
if (trimmed === "") {
|
|
||||||
throw new Error(`manifest-file at ${manifestUrl} is empty.`);
|
|
||||||
}
|
|
||||||
const parsedAsJson = tryParseJson(trimmed);
|
|
||||||
if (Array.isArray(parsedAsJson)) {
|
|
||||||
return parseLegacyManifestEntries(parsedAsJson, manifestUrl);
|
|
||||||
}
|
|
||||||
const versions = parseVersionData(trimmed, manifestUrl);
|
|
||||||
return mapNdjsonVersionsToManifestEntries(versions, manifestUrl);
|
|
||||||
}
|
|
||||||
function mapNdjsonVersionsToManifestEntries(versions, manifestUrl) {
|
|
||||||
const manifestEntries = [];
|
|
||||||
for (const versionData of versions) {
|
|
||||||
for (const artifact of versionData.artifacts) {
|
|
||||||
const [arch3, ...platformParts] = artifact.platform.split("-");
|
|
||||||
if (arch3 === void 0 || platformParts.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid artifact platform '${artifact.platform}' in manifest-file ${manifestUrl}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
manifestEntries.push({
|
|
||||||
arch: arch3,
|
|
||||||
archiveFormat: artifact.archive_format,
|
|
||||||
checksum: artifact.sha256,
|
|
||||||
downloadUrl: artifact.url,
|
|
||||||
platform: platformParts.join("-"),
|
|
||||||
variant: artifact.variant,
|
|
||||||
version: versionData.version
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return manifestEntries;
|
|
||||||
}
|
|
||||||
function selectManifestEntry(manifestEntries, manifestUrl, version4, arch3, platform2) {
|
|
||||||
const matches = manifestEntries.filter(
|
|
||||||
(candidate) => candidate.version === version4 && candidate.arch === arch3 && candidate.platform === platform2
|
|
||||||
);
|
|
||||||
if (matches.length === 0) {
|
|
||||||
return void 0;
|
|
||||||
}
|
|
||||||
return selectDefaultVariant(
|
|
||||||
matches,
|
|
||||||
`manifest-file ${manifestUrl} contains multiple artifacts for version ${version4}, arch ${arch3}, platform ${platform2}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
function tryParseJson(value) {
|
|
||||||
try {
|
|
||||||
return JSON.parse(value);
|
|
||||||
} catch {
|
|
||||||
return void 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/download/download-version.ts
|
// src/download/download-version.ts
|
||||||
function tryGetFromToolCache(arch3, version4) {
|
function tryGetFromToolCache(arch3, version4) {
|
||||||
debug(`Trying to get uv from tool cache for ${version4}...`);
|
debug(`Trying to get uv from tool cache for ${version4}...`);
|
||||||
@@ -96687,24 +96556,25 @@ function tryGetFromToolCache(arch3, version4) {
|
|||||||
const installedPath = find(TOOL_CACHE_NAME, resolvedVersion, arch3);
|
const installedPath = find(TOOL_CACHE_NAME, resolvedVersion, arch3);
|
||||||
return { installedPath, version: resolvedVersion };
|
return { installedPath, version: resolvedVersion };
|
||||||
}
|
}
|
||||||
async function downloadVersionFromNdjson(platform2, arch3, version4, checkSum2, githubToken2) {
|
async function downloadVersion(platform2, arch3, version4, checkSum2, githubToken2, manifestUrl) {
|
||||||
const artifact = await getArtifact(version4, arch3, platform2);
|
const artifact = await getArtifact(version4, arch3, platform2, manifestUrl);
|
||||||
if (!artifact) {
|
if (!artifact) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not find artifact for version ${version4}, arch ${arch3}, platform ${platform2} in ${VERSIONS_NDJSON_URL} .`
|
getMissingArtifactMessage(version4, arch3, platform2, manifestUrl)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const mirrorUrl = rewriteToMirror(artifact.url);
|
const checksum = manifestUrl === void 0 ? checkSum2 : resolveChecksum(checkSum2, artifact.checksum);
|
||||||
const downloadUrl = mirrorUrl ?? artifact.url;
|
const mirrorUrl = rewriteToMirror(artifact.downloadUrl);
|
||||||
|
const downloadUrl = mirrorUrl ?? artifact.downloadUrl;
|
||||||
const downloadToken = mirrorUrl !== void 0 ? void 0 : githubToken2;
|
const downloadToken = mirrorUrl !== void 0 ? void 0 : githubToken2;
|
||||||
try {
|
try {
|
||||||
return await downloadVersion(
|
return await downloadArtifact(
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
`uv-${arch3}-${platform2}`,
|
`uv-${arch3}-${platform2}`,
|
||||||
platform2,
|
platform2,
|
||||||
arch3,
|
arch3,
|
||||||
version4,
|
version4,
|
||||||
checkSum2,
|
checksum,
|
||||||
downloadToken
|
downloadToken
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -96714,13 +96584,13 @@ async function downloadVersionFromNdjson(platform2, arch3, version4, checkSum2,
|
|||||||
warning(
|
warning(
|
||||||
`Failed to download from mirror, falling back to GitHub Releases: ${err.message}`
|
`Failed to download from mirror, falling back to GitHub Releases: ${err.message}`
|
||||||
);
|
);
|
||||||
return await downloadVersion(
|
return await downloadArtifact(
|
||||||
artifact.url,
|
artifact.downloadUrl,
|
||||||
`uv-${arch3}-${platform2}`,
|
`uv-${arch3}-${platform2}`,
|
||||||
platform2,
|
platform2,
|
||||||
arch3,
|
arch3,
|
||||||
version4,
|
version4,
|
||||||
checkSum2,
|
checksum,
|
||||||
githubToken2
|
githubToken2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -96731,29 +96601,7 @@ function rewriteToMirror(url2) {
|
|||||||
}
|
}
|
||||||
return ASTRAL_MIRROR_PREFIX + url2.slice(GITHUB_RELEASES_PREFIX.length);
|
return ASTRAL_MIRROR_PREFIX + url2.slice(GITHUB_RELEASES_PREFIX.length);
|
||||||
}
|
}
|
||||||
async function downloadVersionFromManifest(manifestUrl, platform2, arch3, version4, checkSum2, githubToken2) {
|
async function downloadArtifact(downloadUrl, artifactName, platform2, arch3, version4, checksum, githubToken2) {
|
||||||
const artifact = await getManifestArtifact(
|
|
||||||
manifestUrl,
|
|
||||||
version4,
|
|
||||||
arch3,
|
|
||||||
platform2
|
|
||||||
);
|
|
||||||
if (!artifact) {
|
|
||||||
throw new Error(
|
|
||||||
`manifest-file does not contain version ${version4}, arch ${arch3}, platform ${platform2}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return await downloadVersion(
|
|
||||||
artifact.downloadUrl,
|
|
||||||
`uv-${arch3}-${platform2}`,
|
|
||||||
platform2,
|
|
||||||
arch3,
|
|
||||||
version4,
|
|
||||||
resolveChecksum(checkSum2, artifact.checksum),
|
|
||||||
githubToken2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
async function downloadVersion(downloadUrl, artifactName, platform2, arch3, version4, checksum, githubToken2) {
|
|
||||||
info(`Downloading uv from "${downloadUrl}" ...`);
|
info(`Downloading uv from "${downloadUrl}" ...`);
|
||||||
const downloadPath = await downloadTool(
|
const downloadPath = await downloadTool(
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
@@ -96786,6 +96634,12 @@ async function downloadVersion(downloadUrl, artifactName, platform2, arch3, vers
|
|||||||
);
|
);
|
||||||
return { cachedToolDir, version: version4 };
|
return { cachedToolDir, version: version4 };
|
||||||
}
|
}
|
||||||
|
function getMissingArtifactMessage(version4, arch3, platform2, manifestUrl) {
|
||||||
|
if (manifestUrl === void 0) {
|
||||||
|
return `Could not find artifact for version ${version4}, arch ${arch3}, platform ${platform2} in ${VERSIONS_MANIFEST_URL} .`;
|
||||||
|
}
|
||||||
|
return `manifest-file does not contain version ${version4}, arch ${arch3}, platform ${platform2}.`;
|
||||||
|
}
|
||||||
function resolveChecksum(checkSum2, manifestChecksum) {
|
function resolveChecksum(checkSum2, manifestChecksum) {
|
||||||
return checkSum2 !== void 0 && checkSum2 !== "" ? checkSum2 : manifestChecksum;
|
return checkSum2 !== void 0 && checkSum2 !== "" ? checkSum2 : manifestChecksum;
|
||||||
}
|
}
|
||||||
@@ -96794,23 +96648,16 @@ function getExtension(platform2) {
|
|||||||
}
|
}
|
||||||
async function resolveVersion(versionInput, manifestUrl, resolutionStrategy2 = "highest") {
|
async function resolveVersion(versionInput, manifestUrl, resolutionStrategy2 = "highest") {
|
||||||
debug(`Resolving version: ${versionInput}`);
|
debug(`Resolving version: ${versionInput}`);
|
||||||
let version4;
|
|
||||||
const isSimpleMinimumVersionSpecifier = versionInput.includes(">") && !versionInput.includes(",");
|
const isSimpleMinimumVersionSpecifier = versionInput.includes(">") && !versionInput.includes(",");
|
||||||
const resolveVersionSpecifierToLatest = isSimpleMinimumVersionSpecifier && resolutionStrategy2 === "highest";
|
const resolveVersionSpecifierToLatest = isSimpleMinimumVersionSpecifier && resolutionStrategy2 === "highest";
|
||||||
if (resolveVersionSpecifierToLatest) {
|
if (resolveVersionSpecifierToLatest) {
|
||||||
info("Found minimum version specifier, using latest version");
|
info("Found minimum version specifier, using latest version");
|
||||||
}
|
}
|
||||||
if (manifestUrl !== void 0) {
|
const version4 = versionInput === "latest" || resolveVersionSpecifierToLatest ? await getLatestVersion(manifestUrl) : versionInput;
|
||||||
version4 = versionInput === "latest" || resolveVersionSpecifierToLatest ? await getLatestKnownVersion(manifestUrl) : versionInput;
|
|
||||||
} else {
|
|
||||||
version4 = versionInput === "latest" || resolveVersionSpecifierToLatest ? await getLatestVersion() : versionInput;
|
|
||||||
}
|
|
||||||
if (isExplicitVersion(version4)) {
|
if (isExplicitVersion(version4)) {
|
||||||
debug(`Version ${version4} is an explicit version.`);
|
debug(`Version ${version4} is an explicit version.`);
|
||||||
if (resolveVersionSpecifierToLatest) {
|
if (resolveVersionSpecifierToLatest && !pep440.satisfies(version4, versionInput)) {
|
||||||
if (!pep440.satisfies(version4, versionInput)) {
|
throw new Error(`No version found for ${versionInput}`);
|
||||||
throw new Error(`No version found for ${versionInput}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return version4;
|
return version4;
|
||||||
}
|
}
|
||||||
@@ -96827,10 +96674,10 @@ async function getAvailableVersions(manifestUrl) {
|
|||||||
info(
|
info(
|
||||||
`Getting available versions from manifest-file ${manifestUrl} ...`
|
`Getting available versions from manifest-file ${manifestUrl} ...`
|
||||||
);
|
);
|
||||||
return await getAllVersions2(manifestUrl);
|
} else {
|
||||||
|
info(`Getting available versions from ${VERSIONS_MANIFEST_URL} ...`);
|
||||||
}
|
}
|
||||||
info(`Getting available versions from ${VERSIONS_NDJSON_URL} ...`);
|
return await getAllVersions(manifestUrl);
|
||||||
return await getAllVersions();
|
|
||||||
}
|
}
|
||||||
function maxSatisfying2(versions, version4) {
|
function maxSatisfying2(versions, version4) {
|
||||||
const maxSemver = evaluateVersions(versions, version4);
|
const maxSemver = evaluateVersions(versions, version4);
|
||||||
@@ -97024,7 +96871,7 @@ function detectEmptyWorkdir() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function setupUv(platform2, arch3, checkSum2, githubToken2) {
|
async function setupUv(platform2, arch3, checkSum2, githubToken2) {
|
||||||
const resolvedVersion = await determineVersion(manifestFile);
|
const resolvedVersion = await determineVersion();
|
||||||
const toolCacheResult = tryGetFromToolCache(arch3, resolvedVersion);
|
const toolCacheResult = tryGetFromToolCache(arch3, resolvedVersion);
|
||||||
if (toolCacheResult.installedPath) {
|
if (toolCacheResult.installedPath) {
|
||||||
info(`Found uv in tool-cache for ${toolCacheResult.version}`);
|
info(`Found uv in tool-cache for ${toolCacheResult.version}`);
|
||||||
@@ -97033,28 +96880,29 @@ async function setupUv(platform2, arch3, checkSum2, githubToken2) {
|
|||||||
version: toolCacheResult.version
|
version: toolCacheResult.version
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const downloadVersionResult = manifestFile !== void 0 ? await downloadVersionFromManifest(
|
const downloadResult = await downloadVersion(
|
||||||
manifestFile,
|
|
||||||
platform2,
|
platform2,
|
||||||
arch3,
|
arch3,
|
||||||
resolvedVersion,
|
resolvedVersion,
|
||||||
checkSum2,
|
checkSum2,
|
||||||
githubToken2
|
githubToken2,
|
||||||
) : await downloadVersionFromNdjson(
|
manifestFile
|
||||||
platform2,
|
|
||||||
arch3,
|
|
||||||
resolvedVersion,
|
|
||||||
checkSum2,
|
|
||||||
githubToken2
|
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
uvDir: downloadVersionResult.cachedToolDir,
|
uvDir: downloadResult.cachedToolDir,
|
||||||
version: downloadVersionResult.version
|
version: downloadResult.version
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function determineVersion(manifestFile2) {
|
async function determineVersion() {
|
||||||
|
return await resolveVersion(
|
||||||
|
getRequestedVersion(),
|
||||||
|
manifestFile,
|
||||||
|
resolutionStrategy
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function getRequestedVersion() {
|
||||||
if (version3 !== "") {
|
if (version3 !== "") {
|
||||||
return await resolveVersion(version3, manifestFile2, resolutionStrategy);
|
return version3;
|
||||||
}
|
}
|
||||||
if (versionFile !== "") {
|
if (versionFile !== "") {
|
||||||
const versionFromFile = getUvVersionFromFile(versionFile);
|
const versionFromFile = getUvVersionFromFile(versionFile);
|
||||||
@@ -97063,11 +96911,7 @@ async function determineVersion(manifestFile2) {
|
|||||||
`Could not determine uv version from file: ${versionFile}`
|
`Could not determine uv version from file: ${versionFile}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return await resolveVersion(
|
return versionFromFile;
|
||||||
versionFromFile,
|
|
||||||
manifestFile2,
|
|
||||||
resolutionStrategy
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const versionFromUvToml = getUvVersionFromFile(
|
const versionFromUvToml = getUvVersionFromFile(
|
||||||
`${workingDirectory}${path15.sep}uv.toml`
|
`${workingDirectory}${path15.sep}uv.toml`
|
||||||
@@ -97080,11 +96924,7 @@ async function determineVersion(manifestFile2) {
|
|||||||
"Could not determine uv version from uv.toml or pyproject.toml. Falling back to latest."
|
"Could not determine uv version from uv.toml or pyproject.toml. Falling back to latest."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return await resolveVersion(
|
return versionFromUvToml || versionFromPyproject || "latest";
|
||||||
versionFromUvToml || versionFromPyproject || "latest",
|
|
||||||
manifestFile2,
|
|
||||||
resolutionStrategy
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function addUvToPathAndOutput(cachedPath) {
|
function addUvToPathAndOutput(cachedPath) {
|
||||||
setOutput("uv-path", `${cachedPath}${path15.sep}uv`);
|
setOutput("uv-path", `${cachedPath}${path15.sep}uv`);
|
||||||
|
|||||||
98
dist/update-known-checksums/index.cjs
generated
vendored
98
dist/update-known-checksums/index.cjs
generated
vendored
@@ -19064,8 +19064,8 @@ var require_semver = __commonJS({
|
|||||||
return exports2.compareBuild(b, a, loose);
|
return exports2.compareBuild(b, a, loose);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports2.gt = gt;
|
exports2.gt = gt2;
|
||||||
function gt(a, b, loose) {
|
function gt2(a, b, loose) {
|
||||||
return compare(a, b, loose) > 0;
|
return compare(a, b, loose) > 0;
|
||||||
}
|
}
|
||||||
exports2.lt = lt;
|
exports2.lt = lt;
|
||||||
@@ -19110,7 +19110,7 @@ var require_semver = __commonJS({
|
|||||||
case "!=":
|
case "!=":
|
||||||
return neq(a, b, loose);
|
return neq(a, b, loose);
|
||||||
case ">":
|
case ">":
|
||||||
return gt(a, b, loose);
|
return gt2(a, b, loose);
|
||||||
case ">=":
|
case ">=":
|
||||||
return gte(a, b, loose);
|
return gte(a, b, loose);
|
||||||
case "<":
|
case "<":
|
||||||
@@ -19608,7 +19608,7 @@ var require_semver = __commonJS({
|
|||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case "":
|
case "":
|
||||||
case ">=":
|
case ">=":
|
||||||
if (!minver || gt(minver, compver)) {
|
if (!minver || gt2(minver, compver)) {
|
||||||
minver = compver;
|
minver = compver;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -19649,7 +19649,7 @@ var require_semver = __commonJS({
|
|||||||
var gtfn, ltefn, ltfn, comp, ecomp;
|
var gtfn, ltefn, ltfn, comp, ecomp;
|
||||||
switch (hilo) {
|
switch (hilo) {
|
||||||
case ">":
|
case ">":
|
||||||
gtfn = gt;
|
gtfn = gt2;
|
||||||
ltefn = lte2;
|
ltefn = lte2;
|
||||||
ltfn = lt;
|
ltfn = lt;
|
||||||
comp = ">";
|
comp = ">";
|
||||||
@@ -19658,7 +19658,7 @@ var require_semver = __commonJS({
|
|||||||
case "<":
|
case "<":
|
||||||
gtfn = lt;
|
gtfn = lt;
|
||||||
ltefn = gte;
|
ltefn = gte;
|
||||||
ltfn = gt;
|
ltfn = gt2;
|
||||||
comp = "<";
|
comp = "<";
|
||||||
ecomp = "<=";
|
ecomp = "<=";
|
||||||
break;
|
break;
|
||||||
@@ -44945,7 +44945,7 @@ function info(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/update-known-checksums.ts
|
// src/update-known-checksums.ts
|
||||||
var semver = __toESM(require_semver(), 1);
|
var semver2 = __toESM(require_semver(), 1);
|
||||||
|
|
||||||
// src/download/checksum/known-checksums.ts
|
// src/download/checksum/known-checksums.ts
|
||||||
var KNOWN_CHECKSUMS = {
|
var KNOWN_CHECKSUMS = {
|
||||||
@@ -49410,8 +49410,11 @@ async function updateChecksums(filePath, checksumEntries) {
|
|||||||
await import_node_fs.promises.writeFile(filePath, content);
|
await import_node_fs.promises.writeFile(filePath, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// src/download/manifest.ts
|
||||||
|
var semver = __toESM(require_semver(), 1);
|
||||||
|
|
||||||
// src/utils/constants.ts
|
// src/utils/constants.ts
|
||||||
var VERSIONS_NDJSON_URL = "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
var VERSIONS_MANIFEST_URL = "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
||||||
|
|
||||||
// src/utils/fetch.ts
|
// src/utils/fetch.ts
|
||||||
var import_undici2 = __toESM(require_undici2(), 1);
|
var import_undici2 = __toESM(require_undici2(), 1);
|
||||||
@@ -49431,72 +49434,87 @@ var fetch = async (url, opts) => await (0, import_undici2.fetch)(url, {
|
|||||||
...opts
|
...opts
|
||||||
});
|
});
|
||||||
|
|
||||||
// src/download/versions-client.ts
|
// src/download/manifest.ts
|
||||||
var cachedVersionData = /* @__PURE__ */ new Map();
|
var cachedManifestData = /* @__PURE__ */ new Map();
|
||||||
async function fetchVersionData(url = VERSIONS_NDJSON_URL) {
|
async function fetchManifest(manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const cachedVersions = cachedVersionData.get(url);
|
const cachedVersions = cachedManifestData.get(manifestUrl);
|
||||||
if (cachedVersions !== void 0) {
|
if (cachedVersions !== void 0) {
|
||||||
debug(`Using cached NDJSON version data from ${url}`);
|
debug(`Using cached manifest data from ${manifestUrl}`);
|
||||||
return cachedVersions;
|
return cachedVersions;
|
||||||
}
|
}
|
||||||
info(`Fetching version data from ${url} ...`);
|
info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||||
const response = await fetch(url, {});
|
const response = await fetch(manifestUrl, {});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to fetch version data: ${response.status} ${response.statusText}`
|
`Failed to fetch manifest data: ${response.status} ${response.statusText}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const body = await response.text();
|
const body = await response.text();
|
||||||
const versions = parseVersionData(body, url);
|
const versions = parseManifest(body, manifestUrl);
|
||||||
cachedVersionData.set(url, versions);
|
cachedManifestData.set(manifestUrl, versions);
|
||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
function parseVersionData(data, sourceDescription) {
|
function parseManifest(data, sourceDescription) {
|
||||||
|
const trimmed = data.trim();
|
||||||
|
if (trimmed === "") {
|
||||||
|
throw new Error(`Manifest at ${sourceDescription} is empty.`);
|
||||||
|
}
|
||||||
|
if (trimmed.startsWith("[")) {
|
||||||
|
throw new Error(
|
||||||
|
`Legacy JSON array manifests are no longer supported in ${sourceDescription}. Use the astral-sh/versions manifest format instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
const versions = [];
|
const versions = [];
|
||||||
for (const [index, line] of data.split("\n").entries()) {
|
for (const [index, line] of data.split("\n").entries()) {
|
||||||
const trimmed = line.trim();
|
const record = line.trim();
|
||||||
if (trimmed === "") {
|
if (record === "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let parsed;
|
let parsed;
|
||||||
try {
|
try {
|
||||||
parsed = JSON.parse(trimmed);
|
parsed = JSON.parse(record);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to parse version data from ${sourceDescription} at line ${index + 1}: ${error.message}`
|
`Failed to parse manifest data from ${sourceDescription} at line ${index + 1}: ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isNdjsonVersion(parsed)) {
|
if (!isManifestVersion(parsed)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid NDJSON record in ${sourceDescription} at line ${index + 1}.`
|
`Invalid manifest record in ${sourceDescription} at line ${index + 1}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
versions.push(parsed);
|
versions.push(parsed);
|
||||||
}
|
}
|
||||||
if (versions.length === 0) {
|
if (versions.length === 0) {
|
||||||
throw new Error(`No version data found in ${sourceDescription}.`);
|
throw new Error(`No manifest data found in ${sourceDescription}.`);
|
||||||
}
|
}
|
||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
async function getLatestVersion() {
|
async function getLatestVersion(manifestUrl = VERSIONS_MANIFEST_URL) {
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest(manifestUrl);
|
||||||
const latestVersion = versions[0]?.version;
|
const [firstVersion, ...remainingVersions] = versions.map(
|
||||||
if (!latestVersion) {
|
(versionData) => versionData.version
|
||||||
throw new Error("No versions found in NDJSON data");
|
);
|
||||||
|
if (firstVersion === void 0) {
|
||||||
|
throw new Error("No versions found in manifest data");
|
||||||
}
|
}
|
||||||
debug(`Latest version from NDJSON: ${latestVersion}`);
|
const latestVersion = remainingVersions.reduce(
|
||||||
|
(latest, current) => semver.gt(current, latest) ? current : latest,
|
||||||
|
firstVersion
|
||||||
|
);
|
||||||
|
debug(`Latest version from manifest: ${latestVersion}`);
|
||||||
return latestVersion;
|
return latestVersion;
|
||||||
}
|
}
|
||||||
function isNdjsonVersion(value) {
|
function isManifestVersion(value) {
|
||||||
if (!isRecord(value)) {
|
if (!isRecord(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return value.artifacts.every(isNdjsonArtifact);
|
return value.artifacts.every(isManifestArtifact);
|
||||||
}
|
}
|
||||||
function isNdjsonArtifact(value) {
|
function isManifestArtifact(value) {
|
||||||
if (!isRecord(value)) {
|
if (!isRecord(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -49518,14 +49536,14 @@ async function run() {
|
|||||||
}
|
}
|
||||||
const latestVersion = await getLatestVersion();
|
const latestVersion = await getLatestVersion();
|
||||||
const latestKnownVersion = getLatestKnownVersionFromChecksums();
|
const latestKnownVersion = getLatestKnownVersionFromChecksums();
|
||||||
if (semver.lte(latestVersion, latestKnownVersion)) {
|
if (semver2.lte(latestVersion, latestKnownVersion)) {
|
||||||
info(
|
info(
|
||||||
`Latest release (${latestVersion}) is not newer than the latest known version (${latestKnownVersion}). Skipping update.`
|
`Latest release (${latestVersion}) is not newer than the latest known version (${latestKnownVersion}). Skipping update.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest();
|
||||||
const checksumEntries = extractChecksumsFromNdjson(versions);
|
const checksumEntries = extractChecksumsFromManifest(versions);
|
||||||
await updateChecksums(checksumFilePath, checksumEntries);
|
await updateChecksums(checksumFilePath, checksumEntries);
|
||||||
setOutput("latest-version", latestVersion);
|
setOutput("latest-version", latestVersion);
|
||||||
}
|
}
|
||||||
@@ -49537,7 +49555,7 @@ function getLatestKnownVersionFromChecksums() {
|
|||||||
versions.add(version);
|
versions.add(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const latestVersion = [...versions].sort(semver.rcompare)[0];
|
const latestVersion = [...versions].sort(semver2.rcompare)[0];
|
||||||
if (!latestVersion) {
|
if (!latestVersion) {
|
||||||
throw new Error("Could not determine latest known version from checksums.");
|
throw new Error("Could not determine latest known version from checksums.");
|
||||||
}
|
}
|
||||||
@@ -49546,7 +49564,7 @@ function getLatestKnownVersionFromChecksums() {
|
|||||||
function extractVersionFromChecksumKey(key) {
|
function extractVersionFromChecksumKey(key) {
|
||||||
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
||||||
}
|
}
|
||||||
function extractChecksumsFromNdjson(versions) {
|
function extractChecksumsFromManifest(versions) {
|
||||||
const checksums = [];
|
const checksums = [];
|
||||||
for (const version of versions) {
|
for (const version of versions) {
|
||||||
for (const artifact of version.artifacts) {
|
for (const artifact of version.artifacts) {
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ are automatically verified by this action. The sha256 hashes can be found on the
|
|||||||
## Manifest file
|
## Manifest file
|
||||||
|
|
||||||
By default, setup-uv reads version metadata from
|
By default, setup-uv reads version metadata from
|
||||||
[`astral-sh/versions`](https://github.com/astral-sh/versions) (NDJSON format).
|
[`astral-sh/versions`](https://github.com/astral-sh/versions).
|
||||||
|
|
||||||
The `manifest-file` input lets you override that source with your own URL, for example to test
|
The `manifest-file` input lets you override that source with your own URL, for example to test
|
||||||
custom uv builds or alternate download locations.
|
custom uv builds or alternate download locations.
|
||||||
|
|
||||||
### Format
|
### Format
|
||||||
|
|
||||||
The manifest file must be in NDJSON format, where each line is a JSON object representing a version and its artifacts. For example:
|
The manifest file must use the same format as `astral-sh/versions`: one JSON object per line, where each object represents a version and its artifacts. The versions must be sorted in descending order. For example:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"version":"0.10.7","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://example.com/uv-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"..."}]}
|
{"version":"0.10.7","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://example.com/uv-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"..."}]}
|
||||||
@@ -37,23 +37,6 @@ setup-uv currently only supports `default` as the `variant`.
|
|||||||
|
|
||||||
The `archive_format` field is currently ignored.
|
The `archive_format` field is currently ignored.
|
||||||
|
|
||||||
### Legacy format: JSON array (deprecated)
|
|
||||||
|
|
||||||
The previous JSON array format is still supported for compatibility, but deprecated and will be
|
|
||||||
removed in a future major release.
|
|
||||||
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"version": "0.7.13",
|
|
||||||
"artifactName": "uv-aarch64-apple-darwin.tar.gz",
|
|
||||||
"arch": "aarch64",
|
|
||||||
"platform": "apple-darwin",
|
|
||||||
"downloadUrl": "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-aarch64-apple-darwin.tar.gz"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Use a custom manifest file
|
- name: Use a custom manifest file
|
||||||
uses: astral-sh/setup-uv@v7
|
uses: astral-sh/setup-uv@v7
|
||||||
|
|||||||
@@ -8,20 +8,11 @@ import {
|
|||||||
ASTRAL_MIRROR_PREFIX,
|
ASTRAL_MIRROR_PREFIX,
|
||||||
GITHUB_RELEASES_PREFIX,
|
GITHUB_RELEASES_PREFIX,
|
||||||
TOOL_CACHE_NAME,
|
TOOL_CACHE_NAME,
|
||||||
VERSIONS_NDJSON_URL,
|
VERSIONS_MANIFEST_URL,
|
||||||
} from "../utils/constants";
|
} from "../utils/constants";
|
||||||
import type { Architecture, Platform } from "../utils/platforms";
|
import type { Architecture, Platform } from "../utils/platforms";
|
||||||
import { validateChecksum } from "./checksum/checksum";
|
import { validateChecksum } from "./checksum/checksum";
|
||||||
import {
|
import { getAllVersions, getArtifact, getLatestVersion } from "./manifest";
|
||||||
getAllVersions as getAllManifestVersions,
|
|
||||||
getLatestKnownVersion as getLatestVersionInManifest,
|
|
||||||
getManifestArtifact,
|
|
||||||
} from "./version-manifest";
|
|
||||||
import {
|
|
||||||
getAllVersions as getAllVersionsFromNdjson,
|
|
||||||
getArtifact as getArtifactFromNdjson,
|
|
||||||
getLatestVersion as getLatestVersionFromNdjson,
|
|
||||||
} from "./versions-client";
|
|
||||||
|
|
||||||
export function tryGetFromToolCache(
|
export function tryGetFromToolCache(
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
@@ -38,36 +29,42 @@ export function tryGetFromToolCache(
|
|||||||
return { installedPath, version: resolvedVersion };
|
return { installedPath, version: resolvedVersion };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadVersionFromNdjson(
|
export async function downloadVersion(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
version: string,
|
version: string,
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
|
manifestUrl?: string,
|
||||||
): Promise<{ version: string; cachedToolDir: string }> {
|
): Promise<{ version: string; cachedToolDir: string }> {
|
||||||
const artifact = await getArtifactFromNdjson(version, arch, platform);
|
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
||||||
|
|
||||||
if (!artifact) {
|
if (!artifact) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not find artifact for version ${version}, arch ${arch}, platform ${platform} in ${VERSIONS_NDJSON_URL} .`,
|
getMissingArtifactMessage(version, arch, platform, manifestUrl),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mirrorUrl = rewriteToMirror(artifact.url);
|
// For the default astral-sh/versions source, checksum validation relies on
|
||||||
const downloadUrl = mirrorUrl ?? artifact.url;
|
// user input or the built-in KNOWN_CHECKSUMS table, not manifest sha256 values.
|
||||||
|
const checksum =
|
||||||
|
manifestUrl === undefined
|
||||||
|
? checkSum
|
||||||
|
: resolveChecksum(checkSum, artifact.checksum);
|
||||||
|
|
||||||
|
const mirrorUrl = rewriteToMirror(artifact.downloadUrl);
|
||||||
|
const downloadUrl = mirrorUrl ?? artifact.downloadUrl;
|
||||||
// Don't send the GitHub token to the Astral mirror.
|
// Don't send the GitHub token to the Astral mirror.
|
||||||
const downloadToken = mirrorUrl !== undefined ? undefined : githubToken;
|
const downloadToken = mirrorUrl !== undefined ? undefined : githubToken;
|
||||||
|
|
||||||
// For the default astral-sh/versions source, checksum validation relies on
|
|
||||||
// user input or the built-in KNOWN_CHECKSUMS table, not NDJSON sha256 values.
|
|
||||||
try {
|
try {
|
||||||
return await downloadVersion(
|
return await downloadArtifact(
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
`uv-${arch}-${platform}`,
|
`uv-${arch}-${platform}`,
|
||||||
platform,
|
platform,
|
||||||
arch,
|
arch,
|
||||||
version,
|
version,
|
||||||
checkSum,
|
checksum,
|
||||||
downloadToken,
|
downloadToken,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -79,13 +76,13 @@ export async function downloadVersionFromNdjson(
|
|||||||
`Failed to download from mirror, falling back to GitHub Releases: ${(err as Error).message}`,
|
`Failed to download from mirror, falling back to GitHub Releases: ${(err as Error).message}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return await downloadVersion(
|
return await downloadArtifact(
|
||||||
artifact.url,
|
artifact.downloadUrl,
|
||||||
`uv-${arch}-${platform}`,
|
`uv-${arch}-${platform}`,
|
||||||
platform,
|
platform,
|
||||||
arch,
|
arch,
|
||||||
version,
|
version,
|
||||||
checkSum,
|
checksum,
|
||||||
githubToken,
|
githubToken,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -99,41 +96,11 @@ export function rewriteToMirror(url: string): string | undefined {
|
|||||||
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ASTRAL_MIRROR_PREFIX + url.slice(GITHUB_RELEASES_PREFIX.length);
|
return ASTRAL_MIRROR_PREFIX + url.slice(GITHUB_RELEASES_PREFIX.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadVersionFromManifest(
|
async function downloadArtifact(
|
||||||
manifestUrl: string,
|
|
||||||
platform: Platform,
|
|
||||||
arch: Architecture,
|
|
||||||
version: string,
|
|
||||||
checkSum: string | undefined,
|
|
||||||
githubToken: string,
|
|
||||||
): Promise<{ version: string; cachedToolDir: string }> {
|
|
||||||
const artifact = await getManifestArtifact(
|
|
||||||
manifestUrl,
|
|
||||||
version,
|
|
||||||
arch,
|
|
||||||
platform,
|
|
||||||
);
|
|
||||||
if (!artifact) {
|
|
||||||
throw new Error(
|
|
||||||
`manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await downloadVersion(
|
|
||||||
artifact.downloadUrl,
|
|
||||||
`uv-${arch}-${platform}`,
|
|
||||||
platform,
|
|
||||||
arch,
|
|
||||||
version,
|
|
||||||
resolveChecksum(checkSum, artifact.checksum),
|
|
||||||
githubToken,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function downloadVersion(
|
|
||||||
downloadUrl: string,
|
downloadUrl: string,
|
||||||
artifactName: string,
|
artifactName: string,
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
@@ -177,13 +144,26 @@ async function downloadVersion(
|
|||||||
version,
|
version,
|
||||||
arch,
|
arch,
|
||||||
);
|
);
|
||||||
return { cachedToolDir, version: version };
|
return { cachedToolDir, version };
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMissingArtifactMessage(
|
||||||
|
version: string,
|
||||||
|
arch: Architecture,
|
||||||
|
platform: Platform,
|
||||||
|
manifestUrl?: string,
|
||||||
|
): string {
|
||||||
|
if (manifestUrl === undefined) {
|
||||||
|
return `Could not find artifact for version ${version}, arch ${arch}, platform ${platform} in ${VERSIONS_MANIFEST_URL} .`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveChecksum(
|
function resolveChecksum(
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
manifestChecksum?: string,
|
manifestChecksum: string,
|
||||||
): string | undefined {
|
): string {
|
||||||
return checkSum !== undefined && checkSum !== ""
|
return checkSum !== undefined && checkSum !== ""
|
||||||
? checkSum
|
? checkSum
|
||||||
: manifestChecksum;
|
: manifestChecksum;
|
||||||
@@ -199,31 +179,27 @@ export async function resolveVersion(
|
|||||||
resolutionStrategy: "highest" | "lowest" = "highest",
|
resolutionStrategy: "highest" | "lowest" = "highest",
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.debug(`Resolving version: ${versionInput}`);
|
core.debug(`Resolving version: ${versionInput}`);
|
||||||
let version: string;
|
|
||||||
const isSimpleMinimumVersionSpecifier =
|
const isSimpleMinimumVersionSpecifier =
|
||||||
versionInput.includes(">") && !versionInput.includes(",");
|
versionInput.includes(">") && !versionInput.includes(",");
|
||||||
const resolveVersionSpecifierToLatest =
|
const resolveVersionSpecifierToLatest =
|
||||||
isSimpleMinimumVersionSpecifier && resolutionStrategy === "highest";
|
isSimpleMinimumVersionSpecifier && resolutionStrategy === "highest";
|
||||||
|
|
||||||
if (resolveVersionSpecifierToLatest) {
|
if (resolveVersionSpecifierToLatest) {
|
||||||
core.info("Found minimum version specifier, using latest version");
|
core.info("Found minimum version specifier, using latest version");
|
||||||
}
|
}
|
||||||
if (manifestUrl !== undefined) {
|
|
||||||
version =
|
const version =
|
||||||
versionInput === "latest" || resolveVersionSpecifierToLatest
|
versionInput === "latest" || resolveVersionSpecifierToLatest
|
||||||
? await getLatestVersionInManifest(manifestUrl)
|
? await getLatestVersion(manifestUrl)
|
||||||
: versionInput;
|
: versionInput;
|
||||||
} else {
|
|
||||||
version =
|
|
||||||
versionInput === "latest" || resolveVersionSpecifierToLatest
|
|
||||||
? await getLatestVersionFromNdjson()
|
|
||||||
: versionInput;
|
|
||||||
}
|
|
||||||
if (tc.isExplicitVersion(version)) {
|
if (tc.isExplicitVersion(version)) {
|
||||||
core.debug(`Version ${version} is an explicit version.`);
|
core.debug(`Version ${version} is an explicit version.`);
|
||||||
if (resolveVersionSpecifierToLatest) {
|
if (
|
||||||
if (!pep440.satisfies(version, versionInput)) {
|
resolveVersionSpecifierToLatest &&
|
||||||
throw new Error(`No version found for ${versionInput}`);
|
!pep440.satisfies(version, versionInput)
|
||||||
}
|
) {
|
||||||
|
throw new Error(`No version found for ${versionInput}`);
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
@@ -249,11 +225,11 @@ async function getAvailableVersions(
|
|||||||
core.info(
|
core.info(
|
||||||
`Getting available versions from manifest-file ${manifestUrl} ...`,
|
`Getting available versions from manifest-file ${manifestUrl} ...`,
|
||||||
);
|
);
|
||||||
return await getAllManifestVersions(manifestUrl);
|
} else {
|
||||||
|
core.info(`Getting available versions from ${VERSIONS_MANIFEST_URL} ...`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Getting available versions from ${VERSIONS_NDJSON_URL} ...`);
|
return await getAllVersions(manifestUrl);
|
||||||
return await getAllVersionsFromNdjson();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function maxSatisfying(
|
function maxSatisfying(
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
export interface ManifestEntry {
|
|
||||||
arch: string;
|
|
||||||
platform: string;
|
|
||||||
version: string;
|
|
||||||
downloadUrl: string;
|
|
||||||
checksum?: string;
|
|
||||||
variant?: string;
|
|
||||||
archiveFormat?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LegacyManifestEntry {
|
|
||||||
arch: string;
|
|
||||||
platform: string;
|
|
||||||
version: string;
|
|
||||||
downloadUrl: string;
|
|
||||||
checksum?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const warnedLegacyManifestUrls = new Set<string>();
|
|
||||||
|
|
||||||
export function parseLegacyManifestEntries(
|
|
||||||
parsedEntries: unknown[],
|
|
||||||
manifestUrl: string,
|
|
||||||
): ManifestEntry[] {
|
|
||||||
warnAboutLegacyManifestFormat(manifestUrl);
|
|
||||||
|
|
||||||
return parsedEntries.map((entry, index) => {
|
|
||||||
if (!isLegacyManifestEntry(entry)) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid legacy manifest-file entry at index ${index} in ${manifestUrl}.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
arch: entry.arch,
|
|
||||||
checksum: entry.checksum,
|
|
||||||
downloadUrl: entry.downloadUrl,
|
|
||||||
platform: entry.platform,
|
|
||||||
version: entry.version,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearLegacyManifestWarnings(): void {
|
|
||||||
warnedLegacyManifestUrls.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
function warnAboutLegacyManifestFormat(manifestUrl: string): void {
|
|
||||||
if (warnedLegacyManifestUrls.has(manifestUrl)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
warnedLegacyManifestUrls.add(manifestUrl);
|
|
||||||
core.warning(
|
|
||||||
`manifest-file ${manifestUrl} uses the legacy JSON array format, which is deprecated. Please migrate to the astral-sh/versions NDJSON format before the next major release.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isLegacyManifestEntry(value: unknown): value is LegacyManifestEntry {
|
|
||||||
if (!isRecord(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const checksumIsValid =
|
|
||||||
typeof value.checksum === "string" || value.checksum === undefined;
|
|
||||||
|
|
||||||
return (
|
|
||||||
typeof value.arch === "string" &&
|
|
||||||
checksumIsValid &&
|
|
||||||
typeof value.downloadUrl === "string" &&
|
|
||||||
typeof value.platform === "string" &&
|
|
||||||
typeof value.version === "string"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
||||||
return typeof value === "object" && value !== null;
|
|
||||||
}
|
|
||||||
208
src/download/manifest.ts
Normal file
208
src/download/manifest.ts
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
import * as semver from "semver";
|
||||||
|
import { VERSIONS_MANIFEST_URL } from "../utils/constants";
|
||||||
|
import { fetch } from "../utils/fetch";
|
||||||
|
import { selectDefaultVariant } from "./variant-selection";
|
||||||
|
|
||||||
|
export interface ManifestArtifact {
|
||||||
|
platform: string;
|
||||||
|
variant?: string;
|
||||||
|
url: string;
|
||||||
|
archive_format: string;
|
||||||
|
sha256: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ManifestVersion {
|
||||||
|
version: string;
|
||||||
|
artifacts: ManifestArtifact[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ArtifactResult {
|
||||||
|
archiveFormat: string;
|
||||||
|
checksum: string;
|
||||||
|
downloadUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedManifestData = new Map<string, ManifestVersion[]>();
|
||||||
|
|
||||||
|
export async function fetchManifest(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<ManifestVersion[]> {
|
||||||
|
const cachedVersions = cachedManifestData.get(manifestUrl);
|
||||||
|
if (cachedVersions !== undefined) {
|
||||||
|
core.debug(`Using cached manifest data from ${manifestUrl}`);
|
||||||
|
return cachedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||||
|
const response = await fetch(manifestUrl, {});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch manifest data: ${response.status} ${response.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await response.text();
|
||||||
|
const versions = parseManifest(body, manifestUrl);
|
||||||
|
cachedManifestData.set(manifestUrl, versions);
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseManifest(
|
||||||
|
data: string,
|
||||||
|
sourceDescription: string,
|
||||||
|
): ManifestVersion[] {
|
||||||
|
const trimmed = data.trim();
|
||||||
|
if (trimmed === "") {
|
||||||
|
throw new Error(`Manifest at ${sourceDescription} is empty.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trimmed.startsWith("[")) {
|
||||||
|
throw new Error(
|
||||||
|
`Legacy JSON array manifests are no longer supported in ${sourceDescription}. Use the astral-sh/versions manifest format instead.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const versions: ManifestVersion[] = [];
|
||||||
|
|
||||||
|
for (const [index, line] of data.split("\n").entries()) {
|
||||||
|
const record = line.trim();
|
||||||
|
if (record === "") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed: unknown;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(record);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to parse manifest data from ${sourceDescription} at line ${index + 1}: ${(error as Error).message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isManifestVersion(parsed)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid manifest record in ${sourceDescription} at line ${index + 1}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
versions.push(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versions.length === 0) {
|
||||||
|
throw new Error(`No manifest data found in ${sourceDescription}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLatestVersion(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<string> {
|
||||||
|
const versions = await fetchManifest(manifestUrl);
|
||||||
|
const [firstVersion, ...remainingVersions] = versions.map(
|
||||||
|
(versionData) => versionData.version,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (firstVersion === undefined) {
|
||||||
|
throw new Error("No versions found in manifest data");
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestVersion = remainingVersions.reduce(
|
||||||
|
(latest, current) => (semver.gt(current, latest) ? current : latest),
|
||||||
|
firstVersion,
|
||||||
|
);
|
||||||
|
|
||||||
|
core.debug(`Latest version from manifest: ${latestVersion}`);
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllVersions(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<string[]> {
|
||||||
|
const versions = await fetchManifest(manifestUrl);
|
||||||
|
return versions.map((versionData) => versionData.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArtifact(
|
||||||
|
version: string,
|
||||||
|
arch: string,
|
||||||
|
platform: string,
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<ArtifactResult | undefined> {
|
||||||
|
const versions = await fetchManifest(manifestUrl);
|
||||||
|
const versionData = versions.find(
|
||||||
|
(candidate) => candidate.version === version,
|
||||||
|
);
|
||||||
|
if (!versionData) {
|
||||||
|
core.debug(`Version ${version} not found in manifest ${manifestUrl}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetPlatform = `${arch}-${platform}`;
|
||||||
|
const matchingArtifacts = versionData.artifacts.filter(
|
||||||
|
(candidate) => candidate.platform === targetPlatform,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingArtifacts.length === 0) {
|
||||||
|
core.debug(
|
||||||
|
`Artifact for ${targetPlatform} not found in version ${version}. Available platforms: ${versionData.artifacts
|
||||||
|
.map((candidate) => candidate.platform)
|
||||||
|
.join(", ")}`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const artifact = selectDefaultVariant(
|
||||||
|
matchingArtifacts,
|
||||||
|
`Multiple artifacts found for ${targetPlatform} in version ${version}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
archiveFormat: artifact.archive_format,
|
||||||
|
checksum: artifact.sha256,
|
||||||
|
downloadUrl: artifact.url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearManifestCache(manifestUrl?: string): void {
|
||||||
|
if (manifestUrl === undefined) {
|
||||||
|
cachedManifestData.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedManifestData.delete(manifestUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isManifestVersion(value: unknown): value is ManifestVersion {
|
||||||
|
if (!isRecord(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.artifacts.every(isManifestArtifact);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isManifestArtifact(value: unknown): value is ManifestArtifact {
|
||||||
|
if (!isRecord(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const variantIsValid =
|
||||||
|
typeof value.variant === "string" || value.variant === undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
typeof value.archive_format === "string" &&
|
||||||
|
typeof value.platform === "string" &&
|
||||||
|
typeof value.sha256 === "string" &&
|
||||||
|
typeof value.url === "string" &&
|
||||||
|
variantIsValid
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return typeof value === "object" && value !== null;
|
||||||
|
}
|
||||||
@@ -1,169 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
import * as semver from "semver";
|
|
||||||
import { fetch } from "../utils/fetch";
|
|
||||||
import {
|
|
||||||
clearLegacyManifestWarnings,
|
|
||||||
type ManifestEntry,
|
|
||||||
parseLegacyManifestEntries,
|
|
||||||
} from "./legacy-version-manifest";
|
|
||||||
import { selectDefaultVariant } from "./variant-selection";
|
|
||||||
import { type NdjsonVersion, parseVersionData } from "./versions-client";
|
|
||||||
|
|
||||||
export interface ManifestArtifact {
|
|
||||||
downloadUrl: string;
|
|
||||||
checksum?: string;
|
|
||||||
archiveFormat?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachedManifestEntries = new Map<string, ManifestEntry[]>();
|
|
||||||
|
|
||||||
export async function getLatestKnownVersion(
|
|
||||||
manifestUrl: string,
|
|
||||||
): Promise<string> {
|
|
||||||
const versions = await getAllVersions(manifestUrl);
|
|
||||||
const latestVersion = versions.reduce((latest, current) =>
|
|
||||||
semver.gt(current, latest) ? current : latest,
|
|
||||||
);
|
|
||||||
|
|
||||||
return latestVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAllVersions(manifestUrl: string): Promise<string[]> {
|
|
||||||
const manifestEntries = await getManifestEntries(manifestUrl);
|
|
||||||
return [...new Set(manifestEntries.map((entry) => entry.version))];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getManifestArtifact(
|
|
||||||
manifestUrl: string,
|
|
||||||
version: string,
|
|
||||||
arch: string,
|
|
||||||
platform: string,
|
|
||||||
): Promise<ManifestArtifact | undefined> {
|
|
||||||
const manifestEntries = await getManifestEntries(manifestUrl);
|
|
||||||
const entry = selectManifestEntry(
|
|
||||||
manifestEntries,
|
|
||||||
manifestUrl,
|
|
||||||
version,
|
|
||||||
arch,
|
|
||||||
platform,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!entry) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
archiveFormat: entry.archiveFormat,
|
|
||||||
checksum: entry.checksum,
|
|
||||||
downloadUrl: entry.downloadUrl,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearManifestCache(): void {
|
|
||||||
cachedManifestEntries.clear();
|
|
||||||
clearLegacyManifestWarnings();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getManifestEntries(
|
|
||||||
manifestUrl: string,
|
|
||||||
): Promise<ManifestEntry[]> {
|
|
||||||
const cachedEntries = cachedManifestEntries.get(manifestUrl);
|
|
||||||
if (cachedEntries !== undefined) {
|
|
||||||
core.debug(`Using cached manifest-file from: ${manifestUrl}`);
|
|
||||||
return cachedEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Fetching manifest-file from: ${manifestUrl}`);
|
|
||||||
const response = await fetch(manifestUrl, {});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to fetch manifest-file: ${response.status} ${response.statusText}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.text();
|
|
||||||
const parsedEntries = parseManifestEntries(data, manifestUrl);
|
|
||||||
cachedManifestEntries.set(manifestUrl, parsedEntries);
|
|
||||||
|
|
||||||
return parsedEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseManifestEntries(
|
|
||||||
data: string,
|
|
||||||
manifestUrl: string,
|
|
||||||
): ManifestEntry[] {
|
|
||||||
const trimmed = data.trim();
|
|
||||||
if (trimmed === "") {
|
|
||||||
throw new Error(`manifest-file at ${manifestUrl} is empty.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedAsJson = tryParseJson(trimmed);
|
|
||||||
if (Array.isArray(parsedAsJson)) {
|
|
||||||
return parseLegacyManifestEntries(parsedAsJson, manifestUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
const versions = parseVersionData(trimmed, manifestUrl);
|
|
||||||
return mapNdjsonVersionsToManifestEntries(versions, manifestUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapNdjsonVersionsToManifestEntries(
|
|
||||||
versions: NdjsonVersion[],
|
|
||||||
manifestUrl: string,
|
|
||||||
): ManifestEntry[] {
|
|
||||||
const manifestEntries: ManifestEntry[] = [];
|
|
||||||
|
|
||||||
for (const versionData of versions) {
|
|
||||||
for (const artifact of versionData.artifacts) {
|
|
||||||
const [arch, ...platformParts] = artifact.platform.split("-");
|
|
||||||
if (arch === undefined || platformParts.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid artifact platform '${artifact.platform}' in manifest-file ${manifestUrl}.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
manifestEntries.push({
|
|
||||||
arch,
|
|
||||||
archiveFormat: artifact.archive_format,
|
|
||||||
checksum: artifact.sha256,
|
|
||||||
downloadUrl: artifact.url,
|
|
||||||
platform: platformParts.join("-"),
|
|
||||||
variant: artifact.variant,
|
|
||||||
version: versionData.version,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return manifestEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectManifestEntry(
|
|
||||||
manifestEntries: ManifestEntry[],
|
|
||||||
manifestUrl: string,
|
|
||||||
version: string,
|
|
||||||
arch: string,
|
|
||||||
platform: string,
|
|
||||||
): ManifestEntry | undefined {
|
|
||||||
const matches = manifestEntries.filter(
|
|
||||||
(candidate) =>
|
|
||||||
candidate.version === version &&
|
|
||||||
candidate.arch === arch &&
|
|
||||||
candidate.platform === platform,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (matches.length === 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return selectDefaultVariant(
|
|
||||||
matches,
|
|
||||||
`manifest-file ${manifestUrl} contains multiple artifacts for version ${version}, arch ${arch}, platform ${platform}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function tryParseJson(value: string): unknown {
|
|
||||||
try {
|
|
||||||
return JSON.parse(value);
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
import { VERSIONS_NDJSON_URL } from "../utils/constants";
|
|
||||||
import { fetch } from "../utils/fetch";
|
|
||||||
import { selectDefaultVariant } from "./variant-selection";
|
|
||||||
|
|
||||||
export interface NdjsonArtifact {
|
|
||||||
platform: string;
|
|
||||||
variant?: string;
|
|
||||||
url: string;
|
|
||||||
archive_format: string;
|
|
||||||
sha256: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NdjsonVersion {
|
|
||||||
version: string;
|
|
||||||
artifacts: NdjsonArtifact[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ArtifactResult {
|
|
||||||
url: string;
|
|
||||||
sha256: string;
|
|
||||||
archiveFormat: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachedVersionData = new Map<string, NdjsonVersion[]>();
|
|
||||||
|
|
||||||
export async function fetchVersionData(
|
|
||||||
url: string = VERSIONS_NDJSON_URL,
|
|
||||||
): Promise<NdjsonVersion[]> {
|
|
||||||
const cachedVersions = cachedVersionData.get(url);
|
|
||||||
if (cachedVersions !== undefined) {
|
|
||||||
core.debug(`Using cached NDJSON version data from ${url}`);
|
|
||||||
return cachedVersions;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Fetching version data from ${url} ...`);
|
|
||||||
const response = await fetch(url, {});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to fetch version data: ${response.status} ${response.statusText}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await response.text();
|
|
||||||
const versions = parseVersionData(body, url);
|
|
||||||
cachedVersionData.set(url, versions);
|
|
||||||
return versions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseVersionData(
|
|
||||||
data: string,
|
|
||||||
sourceDescription: string,
|
|
||||||
): NdjsonVersion[] {
|
|
||||||
const versions: NdjsonVersion[] = [];
|
|
||||||
|
|
||||||
for (const [index, line] of data.split("\n").entries()) {
|
|
||||||
const trimmed = line.trim();
|
|
||||||
if (trimmed === "") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsed: unknown;
|
|
||||||
try {
|
|
||||||
parsed = JSON.parse(trimmed);
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to parse version data from ${sourceDescription} at line ${index + 1}: ${(error as Error).message}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isNdjsonVersion(parsed)) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid NDJSON record in ${sourceDescription} at line ${index + 1}.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
versions.push(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versions.length === 0) {
|
|
||||||
throw new Error(`No version data found in ${sourceDescription}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return versions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getLatestVersion(): Promise<string> {
|
|
||||||
const versions = await fetchVersionData();
|
|
||||||
const latestVersion = versions[0]?.version;
|
|
||||||
if (!latestVersion) {
|
|
||||||
throw new Error("No versions found in NDJSON data");
|
|
||||||
}
|
|
||||||
|
|
||||||
core.debug(`Latest version from NDJSON: ${latestVersion}`);
|
|
||||||
return latestVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAllVersions(): Promise<string[]> {
|
|
||||||
const versions = await fetchVersionData();
|
|
||||||
return versions.map((versionData) => versionData.version);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getArtifact(
|
|
||||||
version: string,
|
|
||||||
arch: string,
|
|
||||||
platform: string,
|
|
||||||
): Promise<ArtifactResult | undefined> {
|
|
||||||
const versions = await fetchVersionData();
|
|
||||||
const versionData = versions.find(
|
|
||||||
(candidate) => candidate.version === version,
|
|
||||||
);
|
|
||||||
if (!versionData) {
|
|
||||||
core.debug(`Version ${version} not found in NDJSON data`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetPlatform = `${arch}-${platform}`;
|
|
||||||
const matchingArtifacts = versionData.artifacts.filter(
|
|
||||||
(candidate) => candidate.platform === targetPlatform,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (matchingArtifacts.length === 0) {
|
|
||||||
core.debug(
|
|
||||||
`Artifact for ${targetPlatform} not found in version ${version}. Available platforms: ${versionData.artifacts
|
|
||||||
.map((candidate) => candidate.platform)
|
|
||||||
.join(", ")}`,
|
|
||||||
);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const artifact = selectArtifact(matchingArtifacts, version, targetPlatform);
|
|
||||||
|
|
||||||
return {
|
|
||||||
archiveFormat: artifact.archive_format,
|
|
||||||
sha256: artifact.sha256,
|
|
||||||
url: artifact.url,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearCache(url?: string): void {
|
|
||||||
if (url === undefined) {
|
|
||||||
cachedVersionData.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedVersionData.delete(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectArtifact(
|
|
||||||
artifacts: NdjsonArtifact[],
|
|
||||||
version: string,
|
|
||||||
targetPlatform: string,
|
|
||||||
): NdjsonArtifact {
|
|
||||||
return selectDefaultVariant(
|
|
||||||
artifacts,
|
|
||||||
`Multiple artifacts found for ${targetPlatform} in version ${version}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isNdjsonVersion(value: unknown): value is NdjsonVersion {
|
|
||||||
if (!isRecord(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value.artifacts.every(isNdjsonArtifact);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isNdjsonArtifact(value: unknown): value is NdjsonArtifact {
|
|
||||||
if (!isRecord(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const variantIsValid =
|
|
||||||
typeof value.variant === "string" || value.variant === undefined;
|
|
||||||
|
|
||||||
return (
|
|
||||||
typeof value.archive_format === "string" &&
|
|
||||||
typeof value.platform === "string" &&
|
|
||||||
typeof value.sha256 === "string" &&
|
|
||||||
typeof value.url === "string" &&
|
|
||||||
variantIsValid
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
||||||
return typeof value === "object" && value !== null;
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,7 @@ import * as core from "@actions/core";
|
|||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import { restoreCache } from "./cache/restore-cache";
|
import { restoreCache } from "./cache/restore-cache";
|
||||||
import {
|
import {
|
||||||
downloadVersionFromManifest,
|
downloadVersion,
|
||||||
downloadVersionFromNdjson,
|
|
||||||
resolveVersion,
|
resolveVersion,
|
||||||
tryGetFromToolCache,
|
tryGetFromToolCache,
|
||||||
} from "./download/download-version";
|
} from "./download/download-version";
|
||||||
@@ -132,7 +131,7 @@ async function setupUv(
|
|||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
): Promise<{ uvDir: string; version: string }> {
|
): Promise<{ uvDir: string; version: string }> {
|
||||||
const resolvedVersion = await determineVersion(manifestFile);
|
const resolvedVersion = await determineVersion();
|
||||||
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
||||||
if (toolCacheResult.installedPath) {
|
if (toolCacheResult.installedPath) {
|
||||||
core.info(`Found uv in tool-cache for ${toolCacheResult.version}`);
|
core.info(`Found uv in tool-cache for ${toolCacheResult.version}`);
|
||||||
@@ -142,36 +141,34 @@ async function setupUv(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadVersionResult =
|
const downloadResult = await downloadVersion(
|
||||||
manifestFile !== undefined
|
platform,
|
||||||
? await downloadVersionFromManifest(
|
arch,
|
||||||
manifestFile,
|
resolvedVersion,
|
||||||
platform,
|
checkSum,
|
||||||
arch,
|
githubToken,
|
||||||
resolvedVersion,
|
manifestFile,
|
||||||
checkSum,
|
);
|
||||||
githubToken,
|
|
||||||
)
|
|
||||||
: await downloadVersionFromNdjson(
|
|
||||||
platform,
|
|
||||||
arch,
|
|
||||||
resolvedVersion,
|
|
||||||
checkSum,
|
|
||||||
githubToken,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uvDir: downloadVersionResult.cachedToolDir,
|
uvDir: downloadResult.cachedToolDir,
|
||||||
version: downloadVersionResult.version,
|
version: downloadResult.version,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineVersion(
|
async function determineVersion(): Promise<string> {
|
||||||
manifestFile: string | undefined,
|
return await resolveVersion(
|
||||||
): Promise<string> {
|
getRequestedVersion(),
|
||||||
|
manifestFile,
|
||||||
|
resolutionStrategy,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRequestedVersion(): string {
|
||||||
if (versionInput !== "") {
|
if (versionInput !== "") {
|
||||||
return await resolveVersion(versionInput, manifestFile, resolutionStrategy);
|
return versionInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versionFileInput !== "") {
|
if (versionFileInput !== "") {
|
||||||
const versionFromFile = getUvVersionFromFile(versionFileInput);
|
const versionFromFile = getUvVersionFromFile(versionFileInput);
|
||||||
if (versionFromFile === undefined) {
|
if (versionFromFile === undefined) {
|
||||||
@@ -179,28 +176,23 @@ async function determineVersion(
|
|||||||
`Could not determine uv version from file: ${versionFileInput}`,
|
`Could not determine uv version from file: ${versionFileInput}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return await resolveVersion(
|
return versionFromFile;
|
||||||
versionFromFile,
|
|
||||||
manifestFile,
|
|
||||||
resolutionStrategy,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionFromUvToml = getUvVersionFromFile(
|
const versionFromUvToml = getUvVersionFromFile(
|
||||||
`${workingDirectory}${path.sep}uv.toml`,
|
`${workingDirectory}${path.sep}uv.toml`,
|
||||||
);
|
);
|
||||||
const versionFromPyproject = getUvVersionFromFile(
|
const versionFromPyproject = getUvVersionFromFile(
|
||||||
`${workingDirectory}${path.sep}pyproject.toml`,
|
`${workingDirectory}${path.sep}pyproject.toml`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (versionFromUvToml === undefined && versionFromPyproject === undefined) {
|
if (versionFromUvToml === undefined && versionFromPyproject === undefined) {
|
||||||
core.info(
|
core.info(
|
||||||
"Could not determine uv version from uv.toml or pyproject.toml. Falling back to latest.",
|
"Could not determine uv version from uv.toml or pyproject.toml. Falling back to latest.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return await resolveVersion(
|
|
||||||
versionFromUvToml || versionFromPyproject || "latest",
|
return versionFromUvToml || versionFromPyproject || "latest";
|
||||||
manifestFile,
|
|
||||||
resolutionStrategy,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addUvToPathAndOutput(cachedPath: string): void {
|
function addUvToPathAndOutput(cachedPath: string): void {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import {
|
|||||||
updateChecksums,
|
updateChecksums,
|
||||||
} from "./download/checksum/update-known-checksums";
|
} from "./download/checksum/update-known-checksums";
|
||||||
import {
|
import {
|
||||||
fetchVersionData,
|
fetchManifest,
|
||||||
getLatestVersion,
|
getLatestVersion,
|
||||||
type NdjsonVersion,
|
type ManifestVersion,
|
||||||
} from "./download/versions-client";
|
} from "./download/manifest";
|
||||||
|
|
||||||
const VERSION_IN_CHECKSUM_KEY_PATTERN =
|
const VERSION_IN_CHECKSUM_KEY_PATTERN =
|
||||||
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;
|
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;
|
||||||
@@ -32,8 +32,8 @@ async function run(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const versions = await fetchVersionData();
|
const versions = await fetchManifest();
|
||||||
const checksumEntries = extractChecksumsFromNdjson(versions);
|
const checksumEntries = extractChecksumsFromManifest(versions);
|
||||||
await updateChecksums(checksumFilePath, checksumEntries);
|
await updateChecksums(checksumFilePath, checksumEntries);
|
||||||
|
|
||||||
core.setOutput("latest-version", latestVersion);
|
core.setOutput("latest-version", latestVersion);
|
||||||
@@ -61,8 +61,8 @@ function extractVersionFromChecksumKey(key: string): string | undefined {
|
|||||||
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractChecksumsFromNdjson(
|
function extractChecksumsFromManifest(
|
||||||
versions: NdjsonVersion[],
|
versions: ManifestVersion[],
|
||||||
): ChecksumEntry[] {
|
): ChecksumEntry[] {
|
||||||
const checksums: ChecksumEntry[] = [];
|
const checksums: ChecksumEntry[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export const TOOL_CACHE_NAME = "uv";
|
export const TOOL_CACHE_NAME = "uv";
|
||||||
export const STATE_UV_PATH = "uv-path";
|
export const STATE_UV_PATH = "uv-path";
|
||||||
export const STATE_UV_VERSION = "uv-version";
|
export const STATE_UV_VERSION = "uv-version";
|
||||||
export const VERSIONS_NDJSON_URL =
|
export const VERSIONS_MANIFEST_URL =
|
||||||
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
||||||
|
|
||||||
/** GitHub Releases URL prefix for uv artifacts. */
|
/** GitHub Releases URL prefix for uv artifacts. */
|
||||||
|
|||||||
Reference in New Issue
Block a user