Fix windows action (#11)
This commit is contained in:
parent
3b04047282
commit
06d2d28e10
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -7,8 +7,8 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-beta - 3.10.0"]
|
python-version: [3.7, 3.8, 3.9, "3.10"]
|
||||||
os: ["ubuntu-latest", "windows-latest"]
|
os: ["windows-latest", "ubuntu-latest"]
|
||||||
name: Test the action
|
name: Test the action
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -17,13 +17,16 @@ inputs:
|
|||||||
version:
|
version:
|
||||||
description: The version of PDM to install.
|
description: The version of PDM to install.
|
||||||
required: false
|
required: false
|
||||||
|
ref:
|
||||||
|
description: The Ref of GitHub Repository
|
||||||
|
required: false
|
||||||
prerelease:
|
prerelease:
|
||||||
description: Allow prerelease versions to be installed
|
description: Allow prerelease versions to be installed
|
||||||
default: 'false'
|
default: "false"
|
||||||
required: false
|
required: false
|
||||||
enable-pep582:
|
enable-pep582:
|
||||||
description: "Enable PEP 582 package loading globally."
|
description: "Enable PEP 582 package loading globally."
|
||||||
default: 'true'
|
default: "true"
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: "node12"
|
using: "node12"
|
||||||
|
1791
dist/setup-pdm.js
vendored
1791
dist/setup-pdm.js
vendored
File diff suppressed because it is too large
Load Diff
@ -1,59 +1,79 @@
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec"
|
import * as exec from "@actions/exec";
|
||||||
import * as setupPython from "setup-python/src/find-python"
|
import * as setupPython from "setup-python/src/find-python";
|
||||||
import { IS_WINDOWS } from "setup-python/src/utils"
|
import { IS_WINDOWS } from "setup-python/src/utils";
|
||||||
import * as os from "os"
|
import * as os from "os";
|
||||||
import { exec as execChild } from "child_process"
|
import { exec as execChild } from "child_process";
|
||||||
import path from "path"
|
import { promises as fs } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
const INSTALL_VERSION = "3.8"
|
const INSTALL_VERSION = "3.8";
|
||||||
|
const GITHUB_REPO = "https://github.com/pdm-project/pdm.git";
|
||||||
|
|
||||||
function getPep582Path(): string {
|
function getPep582Path(): string {
|
||||||
const installDir = process.env.pythonLocation || ""
|
const installDir = process.env.pythonLocation || "";
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
return path.resolve(installDir, "Lib/site-packages/pdm/pep582")
|
return path.resolve(installDir, "Lib/site-packages/pdm/pep582");
|
||||||
} else {
|
} else {
|
||||||
return path.resolve(installDir, "lib", `python${INSTALL_VERSION}`, "site-packages/pdm/pep582")
|
return path.resolve(
|
||||||
|
installDir,
|
||||||
|
"lib",
|
||||||
|
`python${INSTALL_VERSION}`,
|
||||||
|
"site-packages/pdm/pep582"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
const arch = core.getInput("architecture") || os.arch()
|
const arch = core.getInput("architecture") || os.arch();
|
||||||
const pdmVersion = core.getInput("version")
|
const pdmVersion = core.getInput("version");
|
||||||
const pdmPackage = pdmVersion ? `pdm==${pdmVersion}` : "pdm"
|
const ref = core.getInput("ref");
|
||||||
const cmdArgs = ["-m", "pip", "install", "-U", pdmPackage, "toml"]
|
const pdmPackage = pdmVersion
|
||||||
|
? `pdm==${pdmVersion}`
|
||||||
|
: ref
|
||||||
|
? `pdm @ git+${GITHUB_REPO}@${ref}`
|
||||||
|
: "pdm";
|
||||||
|
const cmdArgs = ["-m", "pip", "install", "-U", pdmPackage];
|
||||||
if (core.getInput("prerelease") === "true") {
|
if (core.getInput("prerelease") === "true") {
|
||||||
cmdArgs.push("--pre")
|
cmdArgs.push("--pre");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let installedPython = await setupPython.findPythonVersion(INSTALL_VERSION, arch)
|
let installedPython = await setupPython.findPythonVersion(
|
||||||
await exec.exec("python", cmdArgs)
|
INSTALL_VERSION,
|
||||||
|
arch
|
||||||
|
);
|
||||||
|
await exec.exec("python", cmdArgs);
|
||||||
if (core.getInput("enable-pep582") === "true") {
|
if (core.getInput("enable-pep582") === "true") {
|
||||||
core.exportVariable("PYTHONPATH", getPep582Path())
|
core.exportVariable("PYTHONPATH", getPep582Path());
|
||||||
}
|
}
|
||||||
if (core.getInput("python-version") !== INSTALL_VERSION) {
|
if (core.getInput("python-version") !== INSTALL_VERSION) {
|
||||||
installedPython = await setupPython.findPythonVersion(core.getInput("python-version"), arch)
|
installedPython = await setupPython.findPythonVersion(
|
||||||
|
core.getInput("python-version"),
|
||||||
|
arch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const pythonBin = path.join(
|
const pythonBin = path
|
||||||
process.env.pythonLocation as string,
|
.join(
|
||||||
IS_WINDOWS ? "python.exe" : "bin/python"
|
process.env.pythonLocation as string,
|
||||||
)
|
IS_WINDOWS ? "python.exe" : "bin/python"
|
||||||
await exec.exec("pdm", ["use", "-f", pythonBin])
|
)
|
||||||
const pdmVersionOutput = (await execChild("pdm --version")).stdout
|
.replace(/\\/g, "/");
|
||||||
|
await fs.writeFile(".pdm.toml", `[python]\npath="${pythonBin}"\n`);
|
||||||
|
const pdmVersionOutput = (await execChild("pdm --version")).stdout;
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
// See https://github.com/actions/virtual-environments/issues/2803
|
// See https://github.com/actions/virtual-environments/issues/2803
|
||||||
core.exportVariable("LD_PRELOAD", "/lib/x86_64-linux-gnu/libgcc_s.so.1")
|
core.exportVariable("LD_PRELOAD", "/lib/x86_64-linux-gnu/libgcc_s.so.1");
|
||||||
}
|
}
|
||||||
core.info(
|
core.info(
|
||||||
`Successfully setup ${pdmVersionOutput && pdmVersionOutput.read()} with Python ${
|
`Successfully setup ${
|
||||||
installedPython.version
|
pdmVersionOutput && pdmVersionOutput.read()
|
||||||
}`
|
} with Python ${installedPython.version}`
|
||||||
)
|
);
|
||||||
const matchersPath = path.join(__dirname, "..", ".github")
|
const matchersPath = path.join(__dirname, "..", ".github");
|
||||||
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)
|
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user