From 7bd747c85d391feffa5a57cf79e697ab1400a642 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Mon, 1 Mar 2021 10:52:04 +0800 Subject: [PATCH] initial commit --- .github/workflows/ci.yml | 14 ++++++++++++++ .gitignore | 3 +++ .pdm.toml | 2 ++ README.md | 3 ++- action.yml | 21 +++++++++++++++++++++ index.js | 30 ++++++++++++++++++++++++++++++ package.json | 23 +++++++++++++++++++++++ pyproject.toml | 22 ++++++++++++++++++++++ 8 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 .pdm.toml create mode 100644 action.yml create mode 100644 index.js create mode 100644 package.json create mode 100644 pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cd8005e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,14 @@ +on: [push] + +jobs: + Testing: + runs-on: ubuntu-latest + name: Test the action + steps: + - name: Setup PDM + uses: ./ + with: + python-version: 3.6 + # Use the output from the `hello` step + - name: Get the project info + run: pdm info diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fff78c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +yarn.lock +__pypackages__/ diff --git a/.pdm.toml b/.pdm.toml new file mode 100644 index 0000000..00c4908 --- /dev/null +++ b/.pdm.toml @@ -0,0 +1,2 @@ +[python] +path = "/Users/fming/Library/PythonUp/cmd/python3.8" diff --git a/README.md b/README.md index 52eb042..c37ddd1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# pdm-action +# Setup PDM for GitHub Action + The GitHub Action for using pdm as the package manager diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..5809f25 --- /dev/null +++ b/action.yml @@ -0,0 +1,21 @@ +--- +name: 'Setup PDM' +description: 'Set up a specific version of PDM and uses a given Python version to work on' +author: 'Frost Ming' +inputs: + python-version: + description: "Version range or exact version of a Python version to use, using SemVer's version range syntax." + default: '3.x' + architecture: + description: 'The target architecture (x86, x64) of the Python interpreter.' + token: + description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user. + default: ${{ github.token }} + version: + description: The version of PDM to install. +runs: + using: 'node12' + main: 'index.js' +branding: + icon: 'code' + color: 'green' diff --git a/index.js b/index.js new file mode 100644 index 0000000..a606fe3 --- /dev/null +++ b/index.js @@ -0,0 +1,30 @@ +import * as core from "@actions/core"; +import * as exec from "@actions/exec"; +import * as setupPython from "setup-python/dist"; +import * as os from "os"; +import { exec as execChild } from "child_process"; + +const INSTALL_VERSION = "3.8"; + +async function run() { + const arch = core.getInput("architecture") || os.arch(); + const pdmVersion = core.getInput("version"); + const pdmPackage = pdmVersion ? `pdm==${pdmVersion}` : "pdm"; + try { + await setupPython.findPythonVersion(INSTALL_VERSION, arch); + await exec.exec("python", ["-m", "pip", "install", "-U", pdmPackage]); + const installed = await setupPython.findPythonVersion( + core.getInput("python-version"), + arch + ); + await exec.exec("pdm", ["use", "-f", installed.version]); + const pdmVersionOutput = (await execChild("pdm --version")).stdout; + core.info( + `Successfully setup ${pdmVersionOutput} with Python ${installed.version}` + ); + } catch (error) { + core.setFailed(error.message); + } +} + +run(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..6e99599 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "pdm-action", + "version": "1.0.0", + "description": "The GitHub Action for using pdm as the package manager", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pdm-project/pdm-action.git" + }, + + "dependencies": { + "@actions/core": "^1.2.6", + "@actions/exec": "^1.0.4", + "setup-python": "actions/setup-python" + }, + "devDependencies": { + "@types/node": "^14.14.31", + "typescript": "^4.2.2" + } +} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..15b14ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[project] +name = "" +version = "" +description = "" +authors = [ + {name = "Frost Ming", email = "mianghong@gmail.com"}, +] +dependencies = [] +dev-dependencies = [] +requires-python = ">=3.8" +dynamic = ["classifiers"] +license = {text = "MIT"} + +[project.urls] +homepage = "" + +[tool] +[tool.pdm] + +[build-system] +requires = ["pdm-pep517"] +build-backend = "pdm.pep517.api"