forked from wntrblm/nox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
78 lines (67 loc) · 2.52 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Setup Nox
description: "Prepares all python versions for nox"
inputs:
python-versions:
description: "comma-separated list of python versions to install"
required: false
default: "3.8, 3.9, 3.10, 3.11, 3.12, 3.13, pypy-3.10"
branding:
icon: package
color: blue
runs:
using: composite
steps:
- uses: actions/setup-python@v5
id: localpython
with:
python-version: "3.8 - 3.12"
update-environment: false
- name: "Validate input"
id: helper
run: >
'${{ steps.localpython.outputs.python-path }}' '${{ github.action_path }}/.github/action_helper.py' '${{ inputs.python-versions }}' >>${GITHUB_OUTPUT}
shell: bash
- uses: actions/setup-python@v5
id: allpython
with:
python-version: "${{ join(fromJSON(steps.helper.outputs.interpreters), '\n') }}"
allow-prereleases: true
- name: "Install nox"
run: |
import os
import shutil
import sys
import venv
from pathlib import Path
from subprocess import run
class EnvBuilder(venv.EnvBuilder):
def __init__(self):
super().__init__()
def setup_scripts(self, context):
pass
def post_setup(self, context):
super().post_setup(context)
self.bin_path = Path(context.env_exe).parent
if shutil.which("uv") is None:
run([sys.executable, "-m", "pip", "--python", context.env_exe, "install", r"${{ github.action_path }}"], check=True)
else:
run(["uv", "pip", "install", "--python", context.env_exe, r"${{ github.action_path }}"], check=True)
print("::group::Install nox")
nox_bin_path = Path(r"${{ runner.temp }}") / "nox"
if nox_bin_path.exists():
shutil.rmtree(nox_bin_path)
venv_path = Path(r"${{ runner.temp }}") / "nox-venv"
if venv_path.exists():
shutil.rmtree(venv_path)
builder = EnvBuilder()
builder.create(venv_path)
nox_path = [path for path in builder.bin_path.glob("nox*") if path.stem == "nox"][0]
nox_bin_path.mkdir()
try:
os.symlink(nox_path, nox_bin_path / nox_path.name)
except OSError:
shutil.copyfile(nox_path, nox_bin_path / nox_path.name)
with open(os.environ["GITHUB_PATH"], "at") as f:
f.write(f"{nox_bin_path}\n")
print("::endgroup::")
shell: "${{ steps.allpython.outputs.python-path }} -u {0}"