From 73d4caa4850a08c952ff5f23165cd409a57fb4b7 Mon Sep 17 00:00:00 2001 From: Nikita Grishko Date: Sun, 11 Jul 2021 11:07:35 +0200 Subject: [PATCH] [feat] windows support #19 --- .github/workflows/default.yml | 3 ++- README.md | 4 ++++ dist/index.js | 35 +++++++++++------------------- src/find.ts | 40 +++++++++++------------------------ 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 0d85296..bfbc42b 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -24,12 +24,13 @@ jobs: # run action on a clean machine without building to check that it works as expected test-integration: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: python-version: [3.6, 3.7, 3.8, 3.9] poetry-version: [1.1.7, 1.2.0a1] + os: [ubuntu-latest, windows-latest] fail-fast: true diff --git a/README.md b/README.md index 53f57a2..e6f1366 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ This action supports versions of: ## Changelog +### v6 + +- Support Windows platform #19 + ### v5 - **Breaking Change**, support new Poetry installation script. According to the official documentation it's primarily designed to work with Poetry 1.2 and higher. It also works with earlier versions of Poetry but some features may be unsupported like `self update` #16 diff --git a/dist/index.js b/dist/index.js index 81d3dd1..dd56855 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28,33 +28,17 @@ const path_1 = __importDefault(__nccwpck_require__(5622)); const GET_POETRY_URL = "https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py"; function findPoetry(inputs) { return __awaiter(this, void 0, void 0, function* () { - // If Poetry version is specified then we try to find a cached version and if it found - // then we add it to the jobs PATH (should work only in case of private runners) - if (inputs.version) { - const poetryFoundPath = tool_cache_1.find("poetry", inputs.version); - if (poetryFoundPath) { - core_1.addPath(getPoetryBin(poetryFoundPath)); - return; - } - } // Download get-poetry.py const getPoetryPath = yield tool_cache_1.downloadTool(GET_POETRY_URL); // Run Poetry installation script - yield exec_1.exec("python", [getPoetryPath, ...getPoetryArgs(inputs)]); - // If Poetry installed with specified version then add it to the cache and to the jobs - // PATH, otherwise, just add it to the jobs PATH - const poetryPath = path_1.default.join(os_1.default.homedir(), ".local", "share", "pypoetry"); - if (inputs.version) { - const poetryCachedPath = yield tool_cache_1.cacheDir(poetryPath, "poetry", inputs.version); - core_1.addPath(getPoetryBin(poetryCachedPath)); - } - else { - core_1.addPath(getPoetryBin(poetryPath)); - } + yield exec_1.exec("python", [getPoetryPath, ...getPoetryInstallArgs(inputs)]); + // Add Poetry executable to the PATH + const poetryPath = path_1.default.join(os_1.default.homedir(), ...getPoetryPathArgs()); + core_1.addPath(poetryPath); }); } exports.findPoetry = findPoetry; -function getPoetryArgs(inputs) { +function getPoetryInstallArgs(inputs) { const args = ["--yes"]; if (inputs.preview) { args.push("--preview"); @@ -64,8 +48,13 @@ function getPoetryArgs(inputs) { } return args; } -function getPoetryBin(poetryPath) { - return path_1.default.join(poetryPath, "bin"); +function getPoetryPathArgs() { + if (os_1.default.platform() === "win32") { + return ["AppData", "Roaming", "Python", "Scripts"]; + } + else { + return [".local", "share", "pypoetry", "bin"]; + } } diff --git a/src/find.ts b/src/find.ts index ee14f13..90d502e 100644 --- a/src/find.ts +++ b/src/find.ts @@ -1,6 +1,6 @@ import { addPath } from "@actions/core" import { exec } from "@actions/exec" -import { cacheDir, downloadTool, find } from "@actions/tool-cache" +import { downloadTool } from "@actions/tool-cache" import { Inputs } from "./inputs" import os from "os" import path from "path" @@ -9,38 +9,18 @@ const GET_POETRY_URL = "https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py" export async function findPoetry(inputs: Inputs): Promise { - // If Poetry version is specified then we try to find a cached version and if it found - // then we add it to the jobs PATH (should work only in case of private runners) - if (inputs.version) { - const poetryFoundPath = find("poetry", inputs.version) - if (poetryFoundPath) { - addPath(getPoetryBin(poetryFoundPath)) - return - } - } - // Download get-poetry.py const getPoetryPath = await downloadTool(GET_POETRY_URL) // Run Poetry installation script - await exec("python", [getPoetryPath, ...getPoetryArgs(inputs)]) + await exec("python", [getPoetryPath, ...getPoetryInstallArgs(inputs)]) - // If Poetry installed with specified version then add it to the cache and to the jobs - // PATH, otherwise, just add it to the jobs PATH - const poetryPath = path.join(os.homedir(), ".local", "share", "pypoetry") - if (inputs.version) { - const poetryCachedPath = await cacheDir( - poetryPath, - "poetry", - inputs.version - ) - addPath(getPoetryBin(poetryCachedPath)) - } else { - addPath(getPoetryBin(poetryPath)) - } + // Add Poetry executable to the PATH + const poetryPath = path.join(os.homedir(), ...getPoetryPathArgs()) + addPath(poetryPath) } -function getPoetryArgs(inputs: Inputs): string[] { +function getPoetryInstallArgs(inputs: Inputs): string[] { const args: string[] = ["--yes"] if (inputs.preview) { @@ -53,6 +33,10 @@ function getPoetryArgs(inputs: Inputs): string[] { return args } -function getPoetryBin(poetryPath: string): string { - return path.join(poetryPath, "bin") +function getPoetryPathArgs(): string[] { + if (os.platform() === "win32") { + return ["AppData", "Roaming", "Python", "Scripts"] + } else { + return [".local", "share", "pypoetry", "bin"] + } }