Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support python-version-file input #48

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [windows-latest, ubuntu-latest, macos-latest]
name: Test the action
steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Include the action in your workflow yaml:

```yaml
steps:
- uses: actions/checkout@v3
- name: Setup PDM
uses: pdm-project/setup-pdm@v3
- uses: actions/checkout@v3
- name: Setup PDM
uses: pdm-project/setup-pdm@v3
# You are now able to use PDM in your workflow
- name: Install dependencies
run: pdm install
- name: Install dependencies
run: pdm install
```

You don't need `actions/setup-python` actually.
Expand Down
56 changes: 29 additions & 27 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---
name: "Setup PDM"
description: "Set up a specific version of PDM and uses a given Python version to work on"
author: "Frost Ming"
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"
description: 'Version range or exact version of a Python version to use, using SemVer''s version range syntax.'
default: 3.x
required: false
python-version-file:
description: 'File containing the Python version to use. Example: .python-version'
architecture:
description: "The target architecture (x86, x64) of the Python interpreter."
description: 'The target architecture (x86, x64) of the Python interpreter.'
required: false
allow-python-prereleases:
description: "Allow prerelease versions of Python to be installed."
default: "false"
description: Allow prerelease versions of Python to be installed.
default: 'false'
required: false
token:
description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.
Expand All @@ -23,39 +25,39 @@ inputs:
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: "false"
description: Enable PEP 582 package loading globally.
default: 'false'
required: false
cache:
description: "Cache PDM installation."
default: "false"
description: Cache PDM installation.
default: 'false'
required: false
cache-dependency-path:
description: "The dependency file(s) to cache."
default: "pdm.lock"
description: The dependency file(s) to cache.
default: pdm.lock
required: false
update-python:
description: "Whether to update the environment with the requested Python"
default: "true"
description: Whether to update the environment with the requested Python
default: 'true'
outputs:
python-version:
description: "The installed Python or PyPy version. Useful when given a version range as input."
description: The installed Python or PyPy version. Useful when given a version range as input.
python-path:
description: "The absolute path to the Python or PyPy executable."
description: The absolute path to the Python or PyPy executable.
pdm-version:
description: "The installed PDM version."
description: The installed PDM version.
pdm-bin:
description: "The absolute path to the PDM executable."
description: The absolute path to the PDM executable.
cache-hit:
description: "Whether or not there was a cache hit."
description: Whether or not there was a cache hit.
runs:
using: "node20"
main: "dist/setup-pdm.js"
post: "dist/cache-save.js"
using: node20
main: dist/setup-pdm.js
post: dist/cache-save.js
post-if: success()
branding:
icon: "code"
color: "green"
icon: code
color: green
9 changes: 9 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import esbuild from 'esbuild'

esbuild.build({
platform: 'node',
target: 'node20',
bundle: true,
entryPoints: ['src/setup-pdm.ts', 'src/cache-save.ts'],
outdir: 'dist',
})
11 changes: 4 additions & 7 deletions dist/cache-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -74831,15 +74831,14 @@ var require_cache2 = __commonJS({
});

// src/cache-save.ts
var import_node_fs = __toESM(require("node:fs"));
var core = __toESM(require_core());
var cache = __toESM(require_cache2());
var import_fs = __toESM(require("fs"));
async function run() {
try {
const cache2 = core.getBooleanInput("cache");
if (cache2) {
if (cache2)
await saveCache2();
}
} catch (error) {
const err = error;
core.setFailed(err.message);
Expand All @@ -74848,9 +74847,8 @@ async function run() {
async function saveCache2() {
const cachePaths = JSON.parse(core.getState("cache-paths"));
core.debug(`paths for caching are ${cachePaths.join(", ")}`);
if (cachePaths.every((path) => !import_fs.default.existsSync(path))) {
if (cachePaths.every((path) => !import_node_fs.default.existsSync(path)))
throw new Error(`Cache folder path is retrieved for pdm but doesn't exist on disk: ${cachePaths.join(", ")}`);
}
const primaryKey = core.getState("cache-primary-key");
const matchedKey = core.getState("cache-matched-key");
if (!primaryKey) {
Expand All @@ -74861,9 +74859,8 @@ async function saveCache2() {
return;
}
const cacheId = await cache.saveCache(cachePaths, primaryKey);
if (cacheId == -1) {
if (cacheId === -1)
return;
}
core.info(`Cache saved with the key: ${primaryKey}`);
}
run();
Expand Down
Loading
Loading