Fix windows action (#11)

This commit is contained in:
Frost Ming 2022-02-15 14:39:24 +08:00 committed by GitHub
parent 3b04047282
commit 06d2d28e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1038 additions and 854 deletions

View File

@ -7,8 +7,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-beta - 3.10.0"]
os: ["ubuntu-latest", "windows-latest"]
python-version: [3.7, 3.8, 3.9, "3.10"]
os: ["windows-latest", "ubuntu-latest"]
name: Test the action
steps:
- uses: actions/checkout@v2

View File

@ -17,13 +17,16 @@ inputs:
version:
description: The version of PDM to install.
required: false
ref:
description: The Ref of GitHub Repository
required: false
prerelease:
description: Allow prerelease versions to be installed
default: 'false'
default: "false"
required: false
enable-pep582:
description: "Enable PEP 582 package loading globally."
default: 'true'
default: "true"
required: false
runs:
using: "node12"

1791
dist/setup-pdm.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +1,79 @@
import * as core from "@actions/core"
import * as exec from "@actions/exec"
import * as setupPython from "setup-python/src/find-python"
import { IS_WINDOWS } from "setup-python/src/utils"
import * as os from "os"
import { exec as execChild } from "child_process"
import path from "path"
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as setupPython from "setup-python/src/find-python";
import { IS_WINDOWS } from "setup-python/src/utils";
import * as os from "os";
import { exec as execChild } from "child_process";
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 {
const installDir = process.env.pythonLocation || ""
const installDir = process.env.pythonLocation || "";
if (IS_WINDOWS) {
return path.resolve(installDir, "Lib/site-packages/pdm/pep582")
return path.resolve(installDir, "Lib/site-packages/pdm/pep582");
} 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> {
const arch = core.getInput("architecture") || os.arch()
const pdmVersion = core.getInput("version")
const pdmPackage = pdmVersion ? `pdm==${pdmVersion}` : "pdm"
const cmdArgs = ["-m", "pip", "install", "-U", pdmPackage, "toml"]
const arch = core.getInput("architecture") || os.arch();
const pdmVersion = core.getInput("version");
const ref = core.getInput("ref");
const pdmPackage = pdmVersion
? `pdm==${pdmVersion}`
: ref
? `pdm @ git+${GITHUB_REPO}@${ref}`
: "pdm";
const cmdArgs = ["-m", "pip", "install", "-U", pdmPackage];
if (core.getInput("prerelease") === "true") {
cmdArgs.push("--pre")
cmdArgs.push("--pre");
}
try {
let installedPython = await setupPython.findPythonVersion(INSTALL_VERSION, arch)
await exec.exec("python", cmdArgs)
let installedPython = await setupPython.findPythonVersion(
INSTALL_VERSION,
arch
);
await exec.exec("python", cmdArgs);
if (core.getInput("enable-pep582") === "true") {
core.exportVariable("PYTHONPATH", getPep582Path())
core.exportVariable("PYTHONPATH", getPep582Path());
}
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(
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
const pythonBin = path
.join(
process.env.pythonLocation as string,
IS_WINDOWS ? "python.exe" : "bin/python"
)
.replace(/\\/g, "/");
await fs.writeFile(".pdm.toml", `[python]\npath="${pythonBin}"\n`);
const pdmVersionOutput = (await execChild("pdm --version")).stdout;
if (process.platform === "linux") {
// 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(
`Successfully setup ${pdmVersionOutput && pdmVersionOutput.read()} with Python ${
installedPython.version
}`
)
const matchersPath = path.join(__dirname, "..", ".github")
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)
`Successfully setup ${
pdmVersionOutput && pdmVersionOutput.read()
} with Python ${installedPython.version}`
);
const matchersPath = path.join(__dirname, "..", ".github");
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`);
} catch (error: any) {
core.setFailed(error.message)
core.setFailed(error.message);
}
}
run()
run();