Skip to content

Commit

Permalink
πŸ› fix uv version implementation (#15)
Browse files Browse the repository at this point in the history
* Add version support

* Add `venv` creation and activation support (#7)

* 🎨 Fix import statement in main.ts

* πŸ“ Remove unused scripts from package.json

* ✨ Add check-dist.yml workflow for transpiled JavaScript

* ⬆️  Bump the npm-development group with 1 update (#8)

Bumps the npm-development group with 1 update: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node).

Updates `@types/node` from 20.11.19 to 20.11.20
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm-development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* πŸ”₯ remove preview version

* βœ… remove preview tests

* πŸ“ update documentation

* ✨ Remove unused code

* πŸ› Remove lint and coverage scripts from "all" script

* ⬆️ Bump the npm-development group with 1 update (#11)

Bumps the npm-development group with 1 update: [eslint](https://github.com/eslint/eslint).


Updates `eslint` from 8.56.0 to 8.57.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.56.0...v8.57.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm-development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ⬆️ Bump the npm-production group with 1 update (#12)

Bumps the npm-production group with 1 update: [@types/semver](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/semver).


Updates `@types/semver` from 7.5.7 to 7.5.8
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/semver)

---
updated-dependencies:
- dependency-name: "@types/semver"
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump the npm-development group with 2 updates (#13)

Bumps the npm-development group with 2 updates: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) and [eslint-plugin-github](https://github.com/github/eslint-plugin-github).


Updates `@types/node` from 20.11.20 to 20.11.24
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Updates `eslint-plugin-github` from 4.10.1 to 4.10.2
- [Release notes](https://github.com/github/eslint-plugin-github/releases)
- [Commits](github/eslint-plugin-github@v4.10.1...v4.10.2)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm-development
- dependency-name: eslint-plugin-github
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm-development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor UV installation script and add version support

* Add warning if no version provided

* Fix CI

* Fix no version case in CI

* Use uv v.0.1.12 in CI

* Update UV installer script URL

* Fix UV installation command for Windows

* Update UV installation command for Windows

* Add .ps1 extension to downloaded file

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Yasser Tahiri <yasserth19@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add support for creating and activating virtual environments

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Aymane Boumaaza <aymaneboumaaza@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 7, 2024
1 parent c405c66 commit 4a6cab9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 47 deletions.
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

0 comments on commit 4a6cab9

Please sign in to comment.