Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix uv version implementation #15

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ jobs:
- "3.11"
- "3.12"
uv-version:
- "0.1.2"
- "0.1.12"
- ""
os:
- macos-latest
- ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion __tests__/input.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getInput } from '@actions/core'
import { getInputs, getVenvInput, getVersionInput } from '../src/inputs'

const TEST_ENV_VARS = {
Expand Down
54 changes: 33 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31858,40 +31858,51 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findUv = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const tool_cache_1 = __nccwpck_require__(7784);
const os_1 = __importDefault(__nccwpck_require__(2037));
const path_1 = __importDefault(__nccwpck_require__(1017));
const GET_UV_URL_OS = 'https://astral.sh/uv/install.sh';
const GET_UV_URL_WIN = 'https://astral.sh/uv/install.ps1';
async function findUv(inputs) {
const UV_UNIX_LATEST_URL = 'https://astral.sh/uv/install.sh';
const UV_WIN_LATEST_URL = 'https://astral.sh/uv/install.ps1';
async function findUv(version) {
const installScriptUrl = getInstallScriptUrl(version);
const uvInstallPath = await (0, tool_cache_1.downloadTool)(installScriptUrl);
await installUv(os_1.default.platform(), uvInstallPath);
// Add uv executable to the PATH
const uvPath = path_1.default.join(os_1.default.homedir(), ...getUvPathArgs());
(0, core_1.addPath)(uvPath);
}
exports.findUv = findUv;
function getInstallScriptUrl(version) {
let installScript;
if (os_1.default.platform() === 'win32') {
installScript = GET_UV_URL_WIN;
installScript =
version == null
? UV_WIN_LATEST_URL
: `https://github.com/astral-sh/uv/releases/download/${version}/uv-installer.ps1`;
}
else {
installScript = GET_UV_URL_OS;
installScript =
version == null
? UV_UNIX_LATEST_URL
: `https://github.com/astral-sh/uv/releases/download/${version}/uv-installer.sh`;
}
// Download uv installation script
const uvInstallPath = await (0, tool_cache_1.downloadTool)(installScript);
// Run uv installation script
if (os_1.default.platform() === 'win32') {
await (0, exec_1.exec)('powershell', [`irm ${installScript} | iex`]);
return installScript;
}
async function installUv(platform, uvInstallPath) {
if (platform === 'win32') {
await (0, io_1.mv)(uvInstallPath, uvInstallPath + '.ps1');
return await (0, exec_1.exec)('powershell', ['-File', `${uvInstallPath}.ps1`]);
}
else {
await (0, exec_1.exec)('sh', [uvInstallPath]);
return await (0, exec_1.exec)('sh', [uvInstallPath]);
}
// Add uv executable to the PATH
const uvPath = path_1.default.join(os_1.default.homedir(), ...getUvPathArgs());
(0, core_1.addPath)(uvPath);
}
exports.findUv = findUv;
function getUvPathArgs() {
switch (os_1.default.platform()) {
case 'win32':
return ['AppData', 'Roaming', 'uv'];
default:
return ['.local', 'bin'];
if (os_1.default.platform() === 'win32') {
return ['AppData', 'Roaming', 'uv'];
}
return ['.local', 'bin'];
}


Expand Down Expand Up @@ -31919,6 +31930,7 @@ exports.getInputs = getInputs;
function getVersionInput(name) {
const version = (0, core_1.getInput)(name);
if (!version) {
(0, core_1.warning)('Using latest version of uv because no version is provided');
return null;
}
const coerced = semver_1.default.coerce(version);
Expand Down Expand Up @@ -33888,7 +33900,7 @@ const venv_1 = __nccwpck_require__(667);
async function run() {
try {
const inputs = (0, inputs_1.getInputs)();
await (0, find_1.findUv)(inputs);
await (0, find_1.findUv)(inputs.version);
if (inputs.venv) {
await (0, venv_1.createVenv)(inputs.venv);
await (0, venv_1.activateVenv)(inputs.venv);
Expand Down
57 changes: 35 additions & 22 deletions src/find.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
import { addPath } from '@actions/core'
import { exec } from '@actions/exec'
import { mv } from '@actions/io'
import { downloadTool } from '@actions/tool-cache'
import { Inputs } from './inputs'
import os from 'os'
import path from 'path'

const GET_UV_URL_OS = 'https://astral.sh/uv/install.sh'
const GET_UV_URL_WIN = 'https://astral.sh/uv/install.ps1'
const UV_UNIX_LATEST_URL = 'https://astral.sh/uv/install.sh'

export async function findUv(inputs: Inputs): Promise<void> {
const UV_WIN_LATEST_URL = 'https://astral.sh/uv/install.ps1'

export async function findUv(version: string | null): Promise<void> {
const installScriptUrl = getInstallScriptUrl(version)
const uvInstallPath = await downloadTool(installScriptUrl)
await installUv(os.platform(), uvInstallPath)
// Add uv executable to the PATH
const uvPath = path.join(os.homedir(), ...getUvPathArgs())
addPath(uvPath)
}

function getInstallScriptUrl(version: string | null): string {
let installScript: string
if (os.platform() === 'win32') {
installScript = GET_UV_URL_WIN
installScript =
version == null
? UV_WIN_LATEST_URL
: `https://github.com/astral-sh/uv/releases/download/${version}/uv-installer.ps1`
} else {
installScript = GET_UV_URL_OS
installScript =
version == null
? UV_UNIX_LATEST_URL
: `https://github.com/astral-sh/uv/releases/download/${version}/uv-installer.sh`
}
return installScript
}

// Download uv installation script
const uvInstallPath = await downloadTool(installScript)

// Run uv installation script
if (os.platform() === 'win32') {
await exec('powershell', [`irm ${installScript} | iex`])
async function installUv(
platform: string,
uvInstallPath: string
): Promise<number> {
if (platform === 'win32') {
await mv(uvInstallPath, uvInstallPath + '.ps1')
return await exec('powershell', ['-File', `${uvInstallPath}.ps1`])
} else {
await exec('sh', [uvInstallPath])
return await exec('sh', [uvInstallPath])
}

// Add uv executable to the PATH
const uvPath = path.join(os.homedir(), ...getUvPathArgs())
addPath(uvPath)
}

function getUvPathArgs(): string[] {
switch (os.platform()) {
case 'win32':
return ['AppData', 'Roaming', 'uv']
default:
return ['.local', 'bin']
if (os.platform() === 'win32') {
return ['AppData', 'Roaming', 'uv']
}
return ['.local', 'bin']
}
3 changes: 2 additions & 1 deletion src/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInput } from '@actions/core'
import { getInput, warning } from '@actions/core'
import semver from 'semver'
export interface Inputs {
version: string | null
Expand All @@ -15,6 +15,7 @@ export function getInputs(): Inputs {
export function getVersionInput(name: string): string | null {
const version = getInput(name)
if (!version) {
warning('Using latest version of uv because no version is provided')
return null
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function run(): Promise<void> {
try {
const inputs = getInputs()

await findUv(inputs)
await findUv(inputs.version)
if (inputs.venv) {
await createVenv(inputs.venv)
await activateVenv(inputs.venv)
Expand Down
Loading