Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
af1d6d34de chore(deps): bump github/codeql-action from 4.32.2 to 4.32.6
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.32.2 to 4.32.6.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](45cbd0c69e...0d579ffd05)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.32.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-13 10:54:56 +00:00
26 changed files with 231200 additions and 212367 deletions

View File

@@ -47,7 +47,7 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
source-root: src source-root: src
@@ -59,7 +59,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 uses: github/codeql-action/autobuild@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -73,4 +73,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6

View File

@@ -38,7 +38,7 @@ jobs:
npm run all npm run all
- name: Check all jobs are in all-tests-passed.needs - name: Check all jobs are in all-tests-passed.needs
run: | run: |
tsc --module nodenext --moduleResolution nodenext --target es2022 check-all-tests-passed-needs.ts tsc check-all-tests-passed-needs.ts
node check-all-tests-passed-needs.js node check-all-tests-passed-needs.js
working-directory: .github/scripts working-directory: .github/scripts
- name: Make sure no changes from linters are detected - name: Make sure no changes from linters are detected

View File

@@ -20,12 +20,11 @@ jobs:
persist-credentials: true persist-credentials: true
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with: with:
node-version-file: .nvmrc node-version: "20"
cache: npm
- name: Update known checksums - name: Update known checksums
id: update-known-checksums id: update-known-checksums
run: run:
node dist/update-known-checksums/index.cjs node dist/update-known-checksums/index.js
src/download/checksum/known-checksums.ts src/download/checksum/known-checksums.ts
- name: Check for changes - name: Check for changes
id: changes-exist id: changes-exist

View File

@@ -10,9 +10,4 @@ This repository is a TypeScript-based GitHub Action for installing `uv` in GitHu
- User-facing changes are usually multi-file changes. If you add or change inputs, outputs, or behavior, update `action.yml`, the implementation in `src/`, tests in `__tests__/`, relevant docs/README, and then re-package. - User-facing changes are usually multi-file changes. If you add or change inputs, outputs, or behavior, update `action.yml`, the implementation in `src/`, tests in `__tests__/`, relevant docs/README, and then re-package.
- The easiest areas to regress are version resolution and caching. When touching them, add or update tests for precedence, cache invalidation, and cross-platform path behavior. - The easiest areas to regress are version resolution and caching. When touching them, add or update tests for precedence, cache invalidation, and cross-platform path behavior.
- Workflow edits have extra CI-only checks (`actionlint` and `zizmor`); `npm run all` does not cover them. - Workflow edits have extra CI-only checks (`actionlint` and `zizmor`); `npm run all` does not cover them.
- Source is authored with bundler-friendly TypeScript, but published action artifacts in `dist/` are bundled as CommonJS for maximum GitHub Actions runtime compatibility with `@actions/*` dependencies.
- Keep these concerns separate when changing module formats:
- `src/` and tests may use modern ESM-friendly TypeScript patterns.
- `dist/` should prioritize runtime reliability over format purity.
- Do not switch published bundles to ESM without validating the actual committed artifacts under the target Node runtime.
- Before finishing, make sure validation does not leave generated or formatting-only diffs behind. - Before finishing, make sure validation does not leave generated or formatting-only diffs behind.

View File

@@ -1,10 +1,9 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import * as semver from "semver";
const mockInfo = jest.fn(); const mockInfo = jest.fn();
const mockWarning = jest.fn(); const mockWarning = jest.fn();
jest.unstable_mockModule("@actions/core", () => ({ jest.mock("@actions/core", () => ({
debug: jest.fn(), debug: jest.fn(),
info: mockInfo, info: mockInfo,
warning: mockWarning, warning: mockWarning,
@@ -19,17 +18,20 @@ const mockExtractZip = 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 mockCacheDir = jest.fn<any>(); const mockCacheDir = jest.fn<any>();
jest.unstable_mockModule("@actions/tool-cache", () => ({ jest.mock("@actions/tool-cache", () => {
const actual = jest.requireActual("@actions/tool-cache") as Record<
string,
unknown
>;
return {
...actual,
cacheDir: mockCacheDir, cacheDir: mockCacheDir,
downloadTool: mockDownloadTool, downloadTool: mockDownloadTool,
evaluateVersions: (versions: string[], range: string) =>
semver.maxSatisfying(versions, range) ?? "",
extractTar: mockExtractTar, extractTar: mockExtractTar,
extractZip: mockExtractZip, extractZip: mockExtractZip,
find: () => "", };
findAllVersions: () => [], });
isExplicitVersion: (version: string) => semver.valid(version) !== null,
}));
// 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 mockGetLatestVersionFromNdjson = jest.fn<any>();
@@ -38,7 +40,7 @@ const mockGetAllVersionsFromNdjson = 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 mockGetArtifactFromNdjson = jest.fn<any>();
jest.unstable_mockModule("../../src/download/versions-client", () => ({ jest.mock("../../src/download/versions-client", () => ({
getAllVersions: mockGetAllVersionsFromNdjson, getAllVersions: mockGetAllVersionsFromNdjson,
getArtifact: mockGetArtifactFromNdjson, getArtifact: mockGetArtifactFromNdjson,
getLatestVersion: mockGetLatestVersionFromNdjson, getLatestVersion: mockGetLatestVersionFromNdjson,
@@ -51,7 +53,7 @@ const mockGetLatestVersionInManifest = 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 mockGetManifestArtifact = jest.fn<any>(); const mockGetManifestArtifact = jest.fn<any>();
jest.unstable_mockModule("../../src/download/version-manifest", () => ({ jest.mock("../../src/download/version-manifest", () => ({
getAllVersions: mockGetAllManifestVersions, getAllVersions: mockGetAllManifestVersions,
getLatestKnownVersion: mockGetLatestVersionInManifest, getLatestKnownVersion: mockGetLatestVersionInManifest,
getManifestArtifact: mockGetManifestArtifact, getManifestArtifact: mockGetManifestArtifact,
@@ -60,15 +62,15 @@ jest.unstable_mockModule("../../src/download/version-manifest", () => ({
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests. // biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockValidateChecksum = jest.fn<any>(); const mockValidateChecksum = jest.fn<any>();
jest.unstable_mockModule("../../src/download/checksum/checksum", () => ({ jest.mock("../../src/download/checksum/checksum", () => ({
validateChecksum: mockValidateChecksum, validateChecksum: mockValidateChecksum,
})); }));
const { import {
downloadVersionFromManifest, downloadVersionFromManifest,
downloadVersionFromNdjson, downloadVersionFromNdjson,
resolveVersion, resolveVersion,
} = await import("../../src/download/download-version"); } from "../../src/download/download-version";
describe("download-version", () => { describe("download-version", () => {
beforeEach(() => { beforeEach(() => {

View File

@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals";
const mockWarning = jest.fn(); const mockWarning = jest.fn();
jest.unstable_mockModule("@actions/core", () => ({ jest.mock("@actions/core", () => ({
debug: jest.fn(), debug: jest.fn(),
info: jest.fn(), info: jest.fn(),
warning: mockWarning, warning: mockWarning,
@@ -10,16 +10,16 @@ jest.unstable_mockModule("@actions/core", () => ({
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests. // biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockFetch = jest.fn<any>(); const mockFetch = jest.fn<any>();
jest.unstable_mockModule("../../src/utils/fetch", () => ({ jest.mock("../../src/utils/fetch", () => ({
fetch: mockFetch, fetch: mockFetch,
})); }));
const { import {
clearManifestCache, clearManifestCache,
getAllVersions, getAllVersions,
getLatestKnownVersion, getLatestKnownVersion,
getManifestArtifact, getManifestArtifact,
} = await import("../../src/download/version-manifest"); } from "../../src/download/version-manifest";
const legacyManifestResponse = JSON.stringify([ const legacyManifestResponse = JSON.stringify([
{ {

View File

@@ -2,19 +2,18 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals";
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests. // biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockFetch = jest.fn<any>(); const mockFetch = jest.fn<any>();
jest.mock("../../src/utils/fetch", () => ({
jest.unstable_mockModule("../../src/utils/fetch", () => ({
fetch: mockFetch, fetch: mockFetch,
})); }));
const { import {
clearCache, clearCache,
fetchVersionData, fetchVersionData,
getAllVersions, getAllVersions,
getArtifact, getArtifact,
getLatestVersion, getLatestVersion,
parseVersionData, parseVersionData,
} = await import("../../src/download/versions-client"); } from "../../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"}]} 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"}]}`; {"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"}]}`;

View File

@@ -1,3 +1,14 @@
jest.mock("@actions/core", () => {
return {
debug: jest.fn(),
getBooleanInput: jest.fn(
(name: string) => (mockInputs[name] ?? "") === "true",
),
getInput: jest.fn((name: string) => mockInputs[name] ?? ""),
warning: jest.fn(),
};
});
import { import {
afterEach, afterEach,
beforeEach, beforeEach,
@@ -11,26 +22,6 @@ import {
let mockInputs: Record<string, string> = {}; let mockInputs: Record<string, string> = {};
const ORIGINAL_HOME = process.env.HOME; const ORIGINAL_HOME = process.env.HOME;
const mockDebug = jest.fn();
const mockGetBooleanInput = jest.fn(
(name: string) => (mockInputs[name] ?? "") === "true",
);
const mockGetInput = jest.fn((name: string) => mockInputs[name] ?? "");
const mockInfo = jest.fn();
const mockWarning = jest.fn();
jest.unstable_mockModule("@actions/core", () => ({
debug: mockDebug,
getBooleanInput: mockGetBooleanInput,
getInput: mockGetInput,
info: mockInfo,
warning: mockWarning,
}));
async function importInputsModule() {
return await import("../../src/utils/inputs");
}
describe("cacheDependencyGlob", () => { describe("cacheDependencyGlob", () => {
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
@@ -45,21 +36,21 @@ describe("cacheDependencyGlob", () => {
it("returns empty string when input not provided", async () => { it("returns empty string when input not provided", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe(""); expect(cacheDependencyGlob).toBe("");
}); });
it("resolves a single relative path", async () => { it("resolves a single relative path", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "requirements.txt"; mockInputs["cache-dependency-glob"] = "requirements.txt";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe("/workspace/requirements.txt"); expect(cacheDependencyGlob).toBe("/workspace/requirements.txt");
}); });
it("strips leading ./ from relative path", async () => { it("strips leading ./ from relative path", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "./uv.lock"; mockInputs["cache-dependency-glob"] = "./uv.lock";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe("/workspace/uv.lock"); expect(cacheDependencyGlob).toBe("/workspace/uv.lock");
}); });
@@ -67,7 +58,7 @@ describe("cacheDependencyGlob", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = mockInputs["cache-dependency-glob"] =
" ~/.cache/file1\n ./rel/file2 \nfile3.txt"; " ~/.cache/file1\n ./rel/file2 \nfile3.txt";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe( expect(cacheDependencyGlob).toBe(
[ [
"/home/testuser/.cache/file1", // expanded tilde, absolute path unchanged "/home/testuser/.cache/file1", // expanded tilde, absolute path unchanged
@@ -80,7 +71,7 @@ describe("cacheDependencyGlob", () => {
it("keeps absolute path unchanged in multiline input", async () => { it("keeps absolute path unchanged in multiline input", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "/abs/path.lock\nrelative.lock"; mockInputs["cache-dependency-glob"] = "/abs/path.lock\nrelative.lock";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe( expect(cacheDependencyGlob).toBe(
["/abs/path.lock", "/workspace/relative.lock"].join("\n"), ["/abs/path.lock", "/workspace/relative.lock"].join("\n"),
); );
@@ -89,7 +80,7 @@ describe("cacheDependencyGlob", () => {
it("handles exclusions in relative paths correct", async () => { it("handles exclusions in relative paths correct", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "!/abs/path.lock\n!relative.lock"; mockInputs["cache-dependency-glob"] = "!/abs/path.lock\n!relative.lock";
const { cacheDependencyGlob } = await importInputsModule(); const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe( expect(cacheDependencyGlob).toBe(
["!/abs/path.lock", "!/workspace/relative.lock"].join("\n"), ["!/abs/path.lock", "!/workspace/relative.lock"].join("\n"),
); );
@@ -113,7 +104,7 @@ describe("tool directories", () => {
mockInputs["tool-bin-dir"] = "~/tool-bin-dir"; mockInputs["tool-bin-dir"] = "~/tool-bin-dir";
mockInputs["tool-dir"] = "~/tool-dir"; mockInputs["tool-dir"] = "~/tool-dir";
const { toolBinDir, toolDir } = await importInputsModule(); const { toolBinDir, toolDir } = await import("../../src/utils/inputs");
expect(toolBinDir).toBe("/home/testuser/tool-bin-dir"); expect(toolBinDir).toBe("/home/testuser/tool-bin-dir");
expect(toolDir).toBe("/home/testuser/tool-dir"); expect(toolDir).toBe("/home/testuser/tool-dir");
@@ -136,7 +127,9 @@ describe("cacheLocalPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["cache-local-path"] = "~/uv-cache/cache-local-path"; mockInputs["cache-local-path"] = "~/uv-cache/cache-local-path";
const { CacheLocalSource, cacheLocalPath } = await importInputsModule(); const { CacheLocalSource, cacheLocalPath } = await import(
"../../src/utils/inputs"
);
expect(cacheLocalPath).toEqual({ expect(cacheLocalPath).toEqual({
path: "/home/testuser/uv-cache/cache-local-path", path: "/home/testuser/uv-cache/cache-local-path",
@@ -159,7 +152,7 @@ describe("venvPath", () => {
it("defaults to .venv in the working directory", async () => { it("defaults to .venv in the working directory", async () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
const { venvPath } = await importInputsModule(); const { venvPath } = await import("../../src/utils/inputs");
expect(venvPath).toBe("/workspace/.venv"); expect(venvPath).toBe("/workspace/.venv");
}); });
@@ -167,7 +160,7 @@ describe("venvPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["activate-environment"] = "true"; mockInputs["activate-environment"] = "true";
mockInputs["venv-path"] = "custom-venv"; mockInputs["venv-path"] = "custom-venv";
const { venvPath } = await importInputsModule(); const { venvPath } = await import("../../src/utils/inputs");
expect(venvPath).toBe("/workspace/custom-venv"); expect(venvPath).toBe("/workspace/custom-venv");
}); });
@@ -175,7 +168,7 @@ describe("venvPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["activate-environment"] = "true"; mockInputs["activate-environment"] = "true";
mockInputs["venv-path"] = "custom-venv/"; mockInputs["venv-path"] = "custom-venv/";
const { venvPath } = await importInputsModule(); const { venvPath } = await import("../../src/utils/inputs");
expect(venvPath).toBe("/workspace/custom-venv"); expect(venvPath).toBe("/workspace/custom-venv");
}); });
@@ -183,7 +176,7 @@ describe("venvPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["activate-environment"] = "true"; mockInputs["activate-environment"] = "true";
mockInputs["venv-path"] = "/tmp/custom-venv"; mockInputs["venv-path"] = "/tmp/custom-venv";
const { venvPath } = await importInputsModule(); const { venvPath } = await import("../../src/utils/inputs");
expect(venvPath).toBe("/tmp/custom-venv"); expect(venvPath).toBe("/tmp/custom-venv");
}); });
@@ -191,7 +184,7 @@ describe("venvPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["activate-environment"] = "true"; mockInputs["activate-environment"] = "true";
mockInputs["venv-path"] = "~/.venv"; mockInputs["venv-path"] = "~/.venv";
const { venvPath } = await importInputsModule(); const { venvPath } = await import("../../src/utils/inputs");
expect(venvPath).toBe("/home/testuser/.venv"); expect(venvPath).toBe("/home/testuser/.venv");
}); });
@@ -199,11 +192,18 @@ describe("venvPath", () => {
mockInputs["working-directory"] = "/workspace"; mockInputs["working-directory"] = "/workspace";
mockInputs["venv-path"] = "custom-venv"; mockInputs["venv-path"] = "custom-venv";
const { activateEnvironment, venvPath } = await importInputsModule(); const { activateEnvironment, venvPath } = await import(
"../../src/utils/inputs"
);
expect(activateEnvironment).toBe(false); expect(activateEnvironment).toBe(false);
expect(venvPath).toBe("/workspace/custom-venv"); expect(venvPath).toBe("/workspace/custom-venv");
expect(mockWarning).toHaveBeenCalledWith(
const mockedCore = jest.requireMock("@actions/core") as {
warning: jest.Mock;
};
expect(mockedCore.warning).toHaveBeenCalledWith(
"venv-path is only used when activate-environment is true", "venv-path is only used when activate-environment is true",
); );
}); });

View File

@@ -1,121 +1,113 @@
jest.mock("node:fs");
jest.mock("@actions/core", () => ({
warning: jest.fn(),
}));
import fs from "node:fs";
import * as core from "@actions/core";
import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { getUvVersionFromToolVersions } from "../../src/version/tool-versions-file";
const mockReadFileSync = jest.fn(); const mockedFs = fs as jest.Mocked<typeof fs>;
const mockWarning = jest.fn(); const mockedCore = core as jest.Mocked<typeof core>;
jest.unstable_mockModule("node:fs", () => ({
default: {
readFileSync: mockReadFileSync,
},
}));
jest.unstable_mockModule("@actions/core", () => ({
warning: mockWarning,
}));
async function getVersionFromToolVersions(filePath: string) {
const { getUvVersionFromToolVersions } = await import(
"../../src/version/tool-versions-file"
);
return getUvVersionFromToolVersions(filePath);
}
describe("getUvVersionFromToolVersions", () => { describe("getUvVersionFromToolVersions", () => {
beforeEach(() => { beforeEach(() => {
jest.resetModules();
jest.clearAllMocks(); jest.clearAllMocks();
}); });
it("should return undefined for non-.tool-versions files", async () => { it("should return undefined for non-.tool-versions files", () => {
const result = await getVersionFromToolVersions("package.json"); const result = getUvVersionFromToolVersions("package.json");
expect(result).toBeUndefined(); expect(result).toBeUndefined();
expect(mockReadFileSync).not.toHaveBeenCalled(); expect(mockedFs.readFileSync).not.toHaveBeenCalled();
}); });
it("should return version for valid uv entry", async () => { it("should return version for valid uv entry", () => {
const fileContent = "python 3.11.0\nuv 0.1.0\nnodejs 18.0.0"; const fileContent = "python 3.11.0\nuv 0.1.0\nnodejs 18.0.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.1.0"); expect(result).toBe("0.1.0");
expect(mockReadFileSync).toHaveBeenCalledWith(".tool-versions", "utf8"); expect(mockedFs.readFileSync).toHaveBeenCalledWith(
".tool-versions",
"utf8",
);
}); });
it("should return version for uv entry with v prefix", async () => { it("should return version for uv entry with v prefix", () => {
const fileContent = "uv v0.2.0"; const fileContent = "uv v0.2.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.2.0"); expect(result).toBe("0.2.0");
}); });
it("should handle whitespace around uv entry", async () => { it("should handle whitespace around uv entry", () => {
const fileContent = " uv 0.3.0 "; const fileContent = " uv 0.3.0 ";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.3.0"); expect(result).toBe("0.3.0");
}); });
it("should skip commented lines", async () => { it("should skip commented lines", () => {
const fileContent = "# uv 0.1.0\npython 3.11.0\nuv 0.2.0"; const fileContent = "# uv 0.1.0\npython 3.11.0\nuv 0.2.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.2.0"); expect(result).toBe("0.2.0");
}); });
it("should return first matching uv version", async () => { it("should return first matching uv version", () => {
const fileContent = "uv 0.1.0\npython 3.11.0\nuv 0.2.0"; const fileContent = "uv 0.1.0\npython 3.11.0\nuv 0.2.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.1.0"); expect(result).toBe("0.1.0");
}); });
it("should return undefined when no uv entry found", async () => { it("should return undefined when no uv entry found", () => {
const fileContent = "python 3.11.0\nnodejs 18.0.0"; const fileContent = "python 3.11.0\nnodejs 18.0.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined(); expect(result).toBeUndefined();
}); });
it("should return undefined for empty file", async () => { it("should return undefined for empty file", () => {
mockReadFileSync.mockReturnValue(""); mockedFs.readFileSync.mockReturnValue("");
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined(); expect(result).toBeUndefined();
}); });
it("should warn and return undefined for ref syntax", async () => { it("should warn and return undefined for ref syntax", () => {
const fileContent = "uv ref:main"; const fileContent = "uv ref:main";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions(".tool-versions"); const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined(); expect(result).toBeUndefined();
expect(mockWarning).toHaveBeenCalledWith( expect(mockedCore.warning).toHaveBeenCalledWith(
"The ref syntax of .tool-versions is not supported. Please use a released version instead.", "The ref syntax of .tool-versions is not supported. Please use a released version instead.",
); );
}); });
it("should handle file path with .tool-versions extension", async () => { it("should handle file path with .tool-versions extension", () => {
const fileContent = "uv 0.1.0"; const fileContent = "uv 0.1.0";
mockReadFileSync.mockReturnValue(fileContent); mockedFs.readFileSync.mockReturnValue(fileContent);
const result = await getVersionFromToolVersions("path/to/.tool-versions"); const result = getUvVersionFromToolVersions("path/to/.tool-versions");
expect(result).toBe("0.1.0"); expect(result).toBe("0.1.0");
expect(mockReadFileSync).toHaveBeenCalledWith( expect(mockedFs.readFileSync).toHaveBeenCalledWith(
"path/to/.tool-versions", "path/to/.tool-versions",
"utf8", "utf8",
); );

View File

@@ -102,8 +102,8 @@ outputs:
description: "A boolean value to indicate the Python cache entry was found" description: "A boolean value to indicate the Python cache entry was found"
runs: runs:
using: "node24" using: "node24"
main: "dist/setup/index.cjs" main: "dist/setup/index.js"
post: "dist/save-cache/index.cjs" post: "dist/save-cache/index.js"
post-if: success() post-if: success()
branding: branding:
icon: "package" icon: "package"

View File

@@ -1,5 +1,5 @@
{ {
"$schema": "https://biomejs.dev/schemas/2.4.7/schema.json", "$schema": "https://biomejs.dev/schemas/2.3.7/schema.json",
"assist": { "assist": {
"actions": { "actions": {
"source": { "source": {

63325
dist/save-cache/index.cjs generated vendored

File diff suppressed because one or more lines are too long

94304
dist/save-cache/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

97175
dist/setup/index.cjs generated vendored

File diff suppressed because one or more lines are too long

100695
dist/setup/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

49537
dist/update-known-checksums/index.cjs generated vendored

File diff suppressed because one or more lines are too long

33985
dist/update-known-checksums/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

9
jest.config.js Normal file
View File

@@ -0,0 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ["js", "ts"],
testMatch: ["**/*.test.ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
verbose: true,
};

View File

@@ -1,14 +0,0 @@
import { createDefaultEsmPreset } from "ts-jest";
const esmPreset = createDefaultEsmPreset({
tsconfig: "./tsconfig.json",
});
export default {
...esmPreset,
clearMocks: true,
moduleFileExtensions: ["js", "mjs", "ts"],
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
verbose: true,
};

4134
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,18 +2,16 @@
"name": "setup-uv", "name": "setup-uv",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"type": "module",
"description": "Set up your GitHub Actions workflow with a specific version of uv", "description": "Set up your GitHub Actions workflow with a specific version of uv",
"main": "dist/setup/index.cjs", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "tsc --noEmit", "build": "tsc",
"check": "biome check --write", "check": "biome check --write",
"package": "node scripts/build-dist.mjs", "package": "ncc build -o dist/setup src/setup-uv.ts && ncc build -o dist/save-cache src/save-cache.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
"test:unit": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js", "test": "jest",
"test": "npm run build && npm run test:unit",
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"", "act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
"update-known-checksums": "RUNNER_TEMP=known_versions node dist/update-known-checksums/index.cjs src/download/checksum/known-checksums.ts", "update-known-checksums": "RUNNER_TEMP=known_versions node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts",
"all": "npm run build && npm run check && npm run package && npm run test:unit" "all": "npm run build && npm run check && npm run package && npm test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -28,26 +26,25 @@
"author": "@eifinger", "author": "@eifinger",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^6.0.0", "@actions/cache": "^4.1.0",
"@actions/core": "^3.0.0", "@actions/core": "^1.11.1",
"@actions/exec": "^3.0.0", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.6.1", "@actions/glob": "^0.5.0",
"@actions/io": "^3.0.2", "@actions/io": "^1.1.3",
"@actions/tool-cache": "^4.0.0", "@actions/tool-cache": "^2.0.2",
"@renovatebot/pep440": "^4.2.2", "@renovatebot/pep440": "^4.2.1",
"smol-toml": "^1.6.0", "smol-toml": "^1.6.0",
"undici": "^7.24.2" "undici": "5.28.5"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "^2.4.7", "@biomejs/biome": "2.3.8",
"@types/js-yaml": "^4.0.9", "@types/js-yaml": "^4.0.9",
"@types/node": "^25.5.0", "@types/node": "^24.10.1",
"@types/semver": "^7.7.1", "@types/semver": "^7.7.1",
"@vercel/ncc": "^0.38.4", "@vercel/ncc": "^0.38.4",
"esbuild": "^0.27.4", "jest": "^30.2.0",
"jest": "^30.3.0", "js-yaml": "^4.1.0",
"js-yaml": "^4.1.1", "ts-jest": "^29.4.5",
"ts-jest": "^29.4.6",
"typescript": "^5.9.3" "typescript": "^5.9.3"
} }
} }

View File

@@ -1,33 +0,0 @@
import { rm } from "node:fs/promises";
import { build } from "esbuild";
const builds = [
{
entryPoints: ["src/setup-uv.ts"],
outfile: "dist/setup/index.cjs",
staleOutfiles: ["dist/setup/index.mjs"],
},
{
entryPoints: ["src/save-cache.ts"],
outfile: "dist/save-cache/index.cjs",
staleOutfiles: ["dist/save-cache/index.mjs"],
},
{
entryPoints: ["src/update-known-checksums.ts"],
outfile: "dist/update-known-checksums/index.cjs",
staleOutfiles: ["dist/update-known-checksums/index.mjs"],
},
];
for (const { staleOutfiles, ...options } of builds) {
await Promise.all(
staleOutfiles.map((outfile) => rm(outfile, { force: true })),
);
await build({
bundle: true,
format: "cjs",
platform: "node",
target: "node24",
...options,
});
}

View File

@@ -1,39 +1,5 @@
// AUTOGENERATED_DO_NOT_EDIT // AUTOGENERATED_DO_NOT_EDIT
export const KNOWN_CHECKSUMS: { [key: string]: string } = { export const KNOWN_CHECKSUMS: { [key: string]: string } = {
"aarch64-apple-darwin-0.10.10":
"8a09f0ef51ee7f7170731b4cb8bde5bf9ba6da5304f49a7df6cdab42a1f37b5d",
"aarch64-pc-windows-msvc-0.10.10":
"2c6fe113f14574bc27f085751c68d3485589fcc3c3c64ed85dd1eecc2f87cffc",
"aarch64-unknown-linux-gnu-0.10.10":
"2b80457b950deda12e8d5dc3b9b7494ac143eae47f1fb11b1c6e5a8495a6421e",
"aarch64-unknown-linux-musl-0.10.10":
"d08c08b82cdcaf2bd3d928ffe844d3558dda53f90066db6ef9174157cc763252",
"arm-unknown-linux-musleabihf-0.10.10":
"ccc3c4dd5eeea4b2be829ef9bc0b8d9882389c0f303f7ec5ba668065d57e2673",
"armv7-unknown-linux-gnueabihf-0.10.10":
"032786622b52f8d0232b5ad16e25342a64f9e43576652db7bf607231021902f3",
"armv7-unknown-linux-musleabihf-0.10.10":
"f6f67b190eb28b473917c97210f89fd11d9b9393d774acd093ea738fcee68864",
"i686-pc-windows-msvc-0.10.10":
"980d7ea368cc4883f572bb85c285a647eddfc23539064d2bfaf8fbfefcc2112b",
"i686-unknown-linux-gnu-0.10.10":
"5260fbef838f8cfec44697064a5cfae08a27c6ab7ed7feab7fc946827e896952",
"i686-unknown-linux-musl-0.10.10":
"a6683ade964f8d8623098ca0c96b4311d8388b44a56a386cd795974f39fb5bd2",
"powerpc64le-unknown-linux-gnu-0.10.10":
"78939dc4fc905aca8af4be19b6c6ecc306f04c6ca9f98d144372595d9397fd0d",
"riscv64gc-unknown-linux-gnu-0.10.10":
"5eff670bf80fce9d9e50df5b4d46c415a9c0324eadf7059d97c76f89ffc33c3f",
"s390x-unknown-linux-gnu-0.10.10":
"a32d2be5600f7f42f82596ffe9d3115f020974ca7fb4f15251c5625c5481ea5e",
"x86_64-apple-darwin-0.10.10":
"dd18420591d625f9b4ca2b57a7a6fe3cce43910f02e02d90e47a4101428de14a",
"x86_64-pc-windows-msvc-0.10.10":
"d31a30f1dfb96e630a08d5a9b3f3f551254b7ed6e9b7e495f46a4232661c7252",
"x86_64-unknown-linux-gnu-0.10.10":
"3e1027f26ce8c7e4c32e2277a7fed2cb410f2f1f9320d3df97653d40e21f415b",
"x86_64-unknown-linux-musl-0.10.10":
"74544e8755fbc27559e22e29fd561bdc48f91b8bd8323e760a1130f32433bea4",
"aarch64-apple-darwin-0.10.9": "aarch64-apple-darwin-0.10.9":
"a92f61e9ac9b0f29668c15f56152e4a60143fca148ff5bfadb86718472c3f376", "a92f61e9ac9b0f29668c15f56152e4a60143fca148ff5bfadb86718472c3f376",
"aarch64-pc-windows-msvc-0.10.9": "aarch64-pc-windows-msvc-0.10.9":

View File

@@ -38,8 +38,6 @@ import {
} from "./utils/platforms"; } from "./utils/platforms";
import { getUvVersionFromFile } from "./version/resolve"; import { getUvVersionFromFile } from "./version/resolve";
const sourceDir = __dirname;
async function getPythonVersion(): Promise<string> { async function getPythonVersion(): Promise<string> {
if (pythonVersion !== "") { if (pythonVersion !== "") {
return pythonVersion; return pythonVersion;
@@ -310,7 +308,7 @@ function setCacheDir(): void {
function addMatchers(): void { function addMatchers(): void {
if (addProblemMatchers) { if (addProblemMatchers) {
const matchersPath = path.join(sourceDir, "..", "..", ".github"); const matchersPath = path.join(__dirname, `..${path.sep}..`, ".github");
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`); core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`);
} }
} }

View File

@@ -18,7 +18,7 @@ async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0]; const checksumFilePath = process.argv.slice(2)[0];
if (!checksumFilePath) { if (!checksumFilePath) {
throw new Error( throw new Error(
"Missing checksum file path. Usage: node dist/update-known-checksums/index.cjs <checksum-file-path>", "Missing checksum file path. Usage: node dist/update-known-checksums/index.js <checksum-file-path>",
); );
} }

View File

@@ -1,12 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"esModuleInterop": true, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"isolatedModules": true, "module": "nodenext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"module": "esnext", "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"moduleResolution": "bundler", "outDir": "./lib" /* Redirect output structure to the directory. */,
"noImplicitAny": true, "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true, "strict": true /* Enable all strict type-checking options. */,
"target": "ES2022" "target": "ES2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
}, },
"include": ["src/**/*.ts"] "exclude": ["node_modules", "**/*.test.ts"]
} }