Skip to content

Commit

Permalink
[feat] windows support #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Gr1N committed Jul 11, 2021
1 parent f1a6bff commit af78a07
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 12 additions & 23 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"];
}
}


Expand Down
40 changes: 12 additions & 28 deletions src/find.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<void> {
// 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) {
Expand All @@ -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"]
}
}

0 comments on commit af78a07

Please sign in to comment.