FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add latest-known version selector by eifinger · Pull Request #993 · astral-sh/setup-uv · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cjs  (2) .md  (2) .ts  (5) .yml  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
- name: Install uv with all available options
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
# The version of uv to install (default: searches for version in config files, then latest)
# The version of uv to install, e.g., "0.5.0", "latest", or "latest-known" (default: searches for version in config files, then latest)
version: ""

# Path to a file containing the version of uv to install, e.g., uv.toml, pyproject.toml, .tool-versions, requirements.txt or uv.lock (default: searches uv.toml then pyproject.toml)
Expand Down
20 changes: 20 additions & 0 deletions __tests__/download/checksum/known-version.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, it, jest } from "@jest/globals";

jest.unstable_mockModule(
"../../../src/download/checksum/known-checksums",
() => ({
KNOWN_CHECKSUMS: {
"aarch64-apple-darwin-1.9.0": "checksum",
"x86_64-unknown-linux-gnu-1.8.0": "checksum",
"x86_64-unknown-linux-gnu-1.10.0": "checksum",
},
}),
);

const { getLatestKnownVersion } = await import(
"../../../src/download/checksum/known-version"
);

it("returns the highest version with a built-in checksum", () => {
expect(getLatestKnownVersion()).toBe("1.10.0");
});
17 changes: 17 additions & 0 deletions __tests__/download/download-version.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ jest.unstable_mockModule("../../src/download/checksum/checksum", () => ({
validateChecksum: mockValidateChecksum,
}));

const mockGetLatestKnownVersion = jest.fn(() => "0.9.25");

jest.unstable_mockModule("../../src/download/checksum/known-version", () => ({
getLatestKnownVersion: mockGetLatestKnownVersion,
}));

const { downloadVersion, resolveVersion, rewriteToMirror } = await import(
"../../src/download/download-version"
);
Expand All @@ -72,6 +78,7 @@ describe("download-version", () => {
mockGetFirstMatchingVersion.mockReset();
mockGetArtifact.mockReset();
mockValidateChecksum.mockReset();
mockGetLatestKnownVersion.mockClear();

mockDownloadTool.mockResolvedValue("/tmp/downloaded");
mockExtractTar.mockResolvedValue("/tmp/extracted");
Expand All @@ -90,6 +97,16 @@ describe("download-version", () => {
expect(mockGetLatestVersion).toHaveBeenCalledWith(undefined);
});

it("resolves latest-known without reading the manifest", async () => {
const version = await resolveVersion("latest-known", undefined);

expect(version).toBe("0.9.25");
expect(mockGetLatestKnownVersion).toHaveBeenCalledTimes(1);
expect(mockGetLatestVersion).not.toHaveBeenCalled();
expect(mockGetAllVersions).not.toHaveBeenCalled();
expect(mockGetFirstMatchingVersion).not.toHaveBeenCalled();
});

it("stops at the first matching version in the default manifest", async () => {
mockGetFirstMatchingVersion.mockImplementation(
(predicate: (version: string) => boolean) =>
Expand Down
2 changes: 1 addition & 1 deletion action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description:
author: "astral-sh"
inputs:
version:
description: "The version of uv to install e.g., `0.5.0` Defaults to the version in pyproject.toml or 'latest'."
description: "The version of uv to install, e.g., `0.5.0`, `latest`, or `latest-known`. Defaults to the version in pyproject.toml or `latest`."
default: ""
version-file:
description: "Path to a file containing the version of uv to install, e.g., uv.toml, pyproject.toml, .tool-versions, requirements.txt or uv.lock. Defaults to searching for uv.toml and if not found pyproject.toml."
Expand Down
47 changes: 34 additions & 13 deletions dist/setup/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions dist/update-known-checksums/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions docs/advanced-version-configuration.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ This document covers advanced options for configuring which version of uv to ins
version: "latest"
```

## Install the latest version with a checksum verified by this action

Use `latest-known` to install the newest uv version whose checksums were bundled with the version of setup-uv used by your workflow. Version resolution is performed locally without fetching the latest release, so updating setup-uv also updates the version selected by `latest-known`.

When `manifest-file` is set, `latest-known` still selects a version from setup-uv's bundled checksum table, but the artifact and checksum come from the custom manifest.

```yaml
- name: Install the latest version of uv known to setup-uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "latest-known"
```

## Install a specific version

```yaml
Expand Down
23 changes: 23 additions & 0 deletions src/download/checksum/known-version.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as semver from "semver";
import { KNOWN_CHECKSUMS } from "./known-checksums";

const VERSION_IN_CHECKSUM_KEY_PATTERN =
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;

export function getLatestKnownVersion(): string {
const versions = new Set<string>();

for (const key of Object.keys(KNOWN_CHECKSUMS)) {
const version = key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
if (version !== undefined) {
versions.add(version);
}
}

const latestVersion = [...versions].sort(semver.rcompare)[0];
if (!latestVersion) {
throw new Error("Could not determine latest known version from checksums.");
}

return latestVersion;
}
29 changes: 2 additions & 27 deletions src/update-known-checksums.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@actions/core";
import * as semver from "semver";
import { KNOWN_CHECKSUMS } from "./download/checksum/known-checksums";
import { getLatestKnownVersion } from "./download/checksum/known-version";
import {
type ChecksumEntry,
updateChecksums,
Expand All @@ -12,9 +12,6 @@ import {
} from "./download/manifest";
import * as log from "./utils/logging";

const VERSION_IN_CHECKSUM_KEY_PATTERN =
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;

async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0];
if (!checksumFilePath) {
Expand All @@ -24,7 +21,7 @@ async function run(): Promise<void> {
}

const latestVersion = await getLatestVersion();
const latestKnownVersion = getLatestKnownVersionFromChecksums();
const latestKnownVersion = getLatestKnownVersion();

if (semver.lte(latestVersion, latestKnownVersion)) {
log.info(
Expand All @@ -40,28 +37,6 @@ async function run(): Promise<void> {
core.setOutput("latest-version", latestVersion);
}

function getLatestKnownVersionFromChecksums(): string {
const versions = new Set<string>();

for (const key of Object.keys(KNOWN_CHECKSUMS)) {
const version = extractVersionFromChecksumKey(key);
if (version !== undefined) {
versions.add(version);
}
}

const latestVersion = [...versions].sort(semver.rcompare)[0];
if (!latestVersion) {
throw new Error("Could not determine latest known version from checksums.");
}

return latestVersion;
}

function extractVersionFromChecksumKey(key: string): string | undefined {
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
}

function extractChecksumsFromManifest(
versions: ManifestVersion[],
): ChecksumEntry[] {
Expand Down
5 changes: 5 additions & 0 deletions src/version/resolve.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as pep440 from "@renovatebot/pep440";
import * as semver from "semver";
import { getLatestKnownVersion } from "../download/checksum/known-version";
import {
getAllVersions,
getFirstMatchingVersion,
Expand Down Expand Up @@ -143,6 +144,10 @@ export async function resolveVersion(
): Promise<string> {
core.debug(`Resolving version: ${versionInput}`);

if (versionInput.trim() === "latest-known") {
return getLatestKnownVersion();
}

const context: ConcreteVersionResolutionContext = {
manifestUrl,
parsedSpecifier: parseVersionSpecifier(versionInput),
Expand Down
Loading

Back | FazBrowse Home | New Git URL