Skip to content

Commit a72a82e

Browse files
committed
Fix CI
1 parent 45bc150 commit a72a82e

File tree

5 files changed

+316
-60
lines changed

5 files changed

+316
-60
lines changed

.github/workflows/nox.yaml

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,52 @@ on:
88
workflow_dispatch:
99

1010

11+
# Limit this workflow to a single run at a time per-branch to avoid wasting worker resources
1112
concurrency:
1213
group: ${{ github.workflow }}-${{ github.ref }}
1314
cancel-in-progress: true
1415

1516

17+
# env:
18+
# hardlinks don't work in containers and just spam the logs with warning messages
19+
# UV_LINK_MODE: copy
20+
UV_DISABLE_UPDATE: 1
21+
22+
23+
1624
jobs:
17-
nox:
25+
# JOB: NOX-OTHER
26+
nox-other:
1827
runs-on: ubuntu-latest
1928

29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
session: [precommit, audit]
33+
2034
steps:
21-
- name: Checkout Code
22-
uses: actions/checkout@v4
35+
- uses: level12/coppy/gh-actions/nox-run@main
36+
with:
37+
nox-session: ${{ matrix.session }}
38+
39+
# JOB: NOX-PYTEST
40+
nox-pytest:
41+
runs-on: ubuntu-latest
2342

24-
- name: Add ~/bin to PATH
25-
run: echo "PATH=/home/runner/bin:$PATH" >> $GITHUB_ENV
43+
steps:
44+
- uses: level12/coppy/gh-actions/uv-prep@main
45+
46+
- name: Add our user to test user group
47+
run: |
48+
uv run --no-dev tasks/test-user-prep.py
49+
50+
- name: Finish prepping test user
51+
run: |
52+
id
53+
ls -l /home
54+
ls -la /home/coppy-tests
55+
uv run --no-dev tasks/test-user-prep.py
2656
27-
- name: Prep
57+
- name: Run pytest
2858
run: |
29-
# Mise
30-
mkdir ~/bin
31-
curl -LsS https://mise.jdx.dev/mise-latest-linux-x64 > ~/bin/mise
32-
chmod +x ~/bin/mise
33-
34-
# build the image used to test
35-
mise docker-build
36-
37-
# uv
38-
mise use -g ubi:astral-sh/uv
39-
mkdir -p /home/runner/.local/share/uv/python/
40-
41-
# Prep mise
42-
mise trust
43-
mise install
44-
45-
# Uncomment to help troubleshooting
46-
# - name: Debug info
47-
# run: |
48-
# # Python versions
49-
# echo "Python versions:"
50-
# mise exec -- python --version
51-
# mise exec -- uv run python --version
52-
53-
# # Path
54-
# echo "Path:"
55-
# echo $PATH
56-
57-
# mise demo --no-bootstrap --no-nox
58-
# mise sandbox --doctor
59-
60-
- name: nox
61-
run: mise exec -- uv run --frozen --only-group nox nox
59+
uv run --frozen --only-group nox -- nox -s pytest

noxfile.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,59 @@
77
nox.options.default_venv_backend = 'uv'
88

99

10-
def uv_sync(session, group: str, project: bool = False):
11-
# NOTE: not sure why, but sys.path doesn't get correctly configured to include the coppy pkg's
12-
# `src` directory when using '--only-group'. But, in a templated generated app, like the
13-
# coppy demo, '--only-group' works just fine. I spent some time trying to debug but am punting
14-
# for now since the problem/solution seem convoluted to me.
15-
groups_args = ('--no-default-groups', '--group') if project else ('--only-group',)
16-
session.run('uv', 'sync', '--active', '--frozen', *groups_args, group)
17-
18-
1910
@nox.session
20-
def tests(session: nox.Session):
21-
uv_sync(session, 'tests', project=True)
11+
def pytest(session: nox.Session):
12+
uv_sync(session)
13+
# TODO: no coverage because the far majority of the code in this project is just for testing.
14+
# But it wouldn't hurt to add it.
2215
session.run(
2316
'pytest',
2417
'-ra',
2518
'--tb=native',
2619
'--strict-markers',
27-
f'--junit-xml={package_path}/ci/test-reports/{session.name}.pytests.xml',
2820
'tests',
2921
*session.posargs,
3022
)
3123

3224

3325
@nox.session
34-
def standards(session: nox.Session):
26+
def precommit(session: nox.Session):
3527
uv_sync(session, 'pre-commit')
3628
session.run(
3729
'pre-commit',
3830
'run',
3931
'--all-files',
4032
)
33+
34+
35+
@nox.session
36+
def audit(session: nox.Session):
37+
# Much faster to install the deps first and have pip-audit run against the venv
38+
uv_sync(session)
39+
session.run(
40+
'pip-audit',
41+
'--desc',
42+
'--skip-editable',
43+
)
44+
45+
46+
def uv_sync(session: nox.Session, *groups, project=False, extra=None):
47+
# If no group given, assume group shares name of session.
48+
if not groups:
49+
groups = (session.name,)
50+
51+
# At least pytest needs the project installed.
52+
project_args = () if project or session.name.startswith('pytest') else ('--no-install-project',)
53+
54+
group_args = [arg for group in groups for arg in ('--group', group)]
55+
extra_args = ('--extra', extra) if extra else ()
56+
run_args = (
57+
'uv',
58+
'sync',
59+
'--active',
60+
'--no-default-groups',
61+
*project_args,
62+
*group_args,
63+
*extra_args,
64+
)
65+
session.run(*run_args)

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ coppy = 'coppy.cli:cli'
2626

2727
[dependency-groups]
2828
dev = [
29-
{include-group = "tests"},
29+
{include-group = "pytest"},
3030
{include-group = "pre-commit"},
3131
{include-group = "nox"},
3232
"hatch>=1.14.0",
@@ -39,9 +39,13 @@ pre-commit = [
3939
'pre-commit-uv>=4.1.4',
4040
]
4141
# Used by nox
42-
tests = [
42+
pytest = [
4343
'pytest>=8.3.4',
4444
]
45+
# Used by nox
46+
audit = [
47+
'pip-audit',
48+
]
4549
# Used by CI
4650
nox = [
4751
'nox>=2025.2.9',

tasks/test-user-prep.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ def main(systemd_skip: bool, systemd_force: bool, reinstall: bool):
4141

4242
if not coppy_user.is_current:
4343
curr_user = User.current()
44-
# This would clear them all (i.e. fix a mistake if you have one)
45-
utils.sub_run('sudo', 'setfacl', '-R', '-b', coppy_user_home)
46-
# utils.sudo_run('setfacl', '-R', '-m', f'u:{curr_user.name}:rwX', coppy_user_home)
47-
# utils.sudo_run('setfacl', '-R', '-d', '-m', f'u:{curr_user.name}:rwX', coppy_user_home)
44+
4845
if coppy_user.name not in curr_user.groups():
4946
log.info(f'Adding your user to the user group: {coppy_user.name}')
5047
utils.sudo_run('usermod', '-aG', coppy_user.name, curr_user.name)
5148
log.warning(
5249
f'Please logout and then back in to enable access to the {coppy_user.name} group.',
5350
)
51+
return
5452
else:
5553
log.info(f'Your user is already in the group: {coppy_user.name}')
5654

0 commit comments

Comments
 (0)