Skip to content

Commit

Permalink
feat(action): do not depend on pipx in Nox action (#768)
Browse files Browse the repository at this point in the history
* chore(ci): test action on macos-14

* temp: python 3.8 & 3.9 missing on macos-14

* temp: don't use pipx

* fix: use local python and try step shell

* Update action.yml

* Update action.yml

* Apply suggestions from code review

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
  • Loading branch information
mayeut and henryiii authored Mar 29, 2024
1 parent 08813c3 commit efc17bb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_default_tests

action-all-tests:
runs-on: windows-latest
steps:
Expand All @@ -43,3 +44,12 @@ jobs:
with:
python-versions: "3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, pypy-2.7, pypy-3.7, pypy-3.8, pypy-3.9, pypy-3.10"
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_all_tests

action-macos14-tests:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: ./
with:
python-versions: "3.10, 3.11, 3.12, pypy-3.8, pypy-3.9, pypy-3.10"
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_macos_14
44 changes: 42 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,45 @@ runs:
allow-prereleases: true

- name: "Install nox"
run: pipx install --python "${{ steps.allpython.outputs.python-path }}" '${{ github.action_path }}'
shell: bash
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
run([sys.executable, "-m", "pip", "--python", context.env_exe, "install", 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}"
17 changes: 16 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def github_actions_default_tests(session: nox.Session) -> None:
_check_python_version(session)


# The following sessions are only to be run in CI to check the nox GHA action
@nox.session(
python=[
"3.7",
Expand All @@ -192,3 +191,19 @@ def github_actions_default_tests(session: nox.Session) -> None:
def github_actions_all_tests(session: nox.Session) -> None:
"""Check all versions installed by the nox GHA Action"""
_check_python_version(session)


@nox.session(
python=[
"3.10",
"3.11",
"3.12",
"pypy3.8",
"pypy3.9",
"pypy3.10",
]
)
def github_actions_macos_14(session: nox.Session) -> None:
"""Check default versions installed by the nox GHA Action"""
assert sys.version_info[:2] == (3, 11)
_check_python_version(session)

0 comments on commit efc17bb

Please sign in to comment.