Skip to content

Commit ac88861

Browse files
authored
Pip compile check mode (#1950)
* nox pip-compile: support check mode Support a custom --check flag to fail if pip-compile made any changes so we can check that that lockfiles are in sync with the input (.in) files. * ci: remove push trigger for pip-compile workflows Now that we have the pip-compile-check job, this is redundant. PR checks will fail if lockfiles are out-of-sync, so there's no need to run the complete pip-compile workflow that performs a full update of the dependencies. Complete updates are still performed on a weekly basis.
1 parent e455e4f commit ac88861

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

.github/workflows/pip-compile-dev.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ name: "Refresh dev dependencies"
1212
labels:
1313
required: false
1414
type: string
15-
push:
16-
branches:
17-
- devel
18-
paths:
19-
- .github/workflows/reusable-pip-compile.yml
20-
- ".github/workflows/pip-compile-dev.yml"
21-
- "tests/*.in"
2215

2316
jobs:
2417
refresh:

.github/workflows/pip-compile-docs.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ name: "Refresh docs build dependencies"
1818
labels:
1919
required: false
2020
type: string
21-
push:
22-
branches:
23-
- devel
24-
paths:
25-
- .github/workflows/reusable-pip-compile.yml
26-
- ".github/workflows/pip-compile-docs.yml"
27-
- "tests/*.in"
2821

2922
jobs:
3023
refresh:

.github/workflows/reusable-nox.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
include:
14+
# Inputs:
15+
# session: name of session
16+
# python-versions: comma-separated list of Python versions to install
17+
# extra-args (optional): extra arguments to pass to nox session.
1418
- session: static
1519
python-versions: "3.11"
1620
- session: formatters_check
@@ -25,6 +29,9 @@ jobs:
2529
python-versions: "3.11"
2630
- session: "actionlint"
2731
python-versions: "3.11"
32+
- session: "pip-compile"
33+
extra-args: "--check"
34+
python-versions: "3.11"
2835
name: "Run nox ${{ matrix.session }} session"
2936
steps:
3037
- name: Check out repo
@@ -38,4 +45,6 @@ jobs:
3845
nox -e clone-core
3946
- name: "Run nox -e ${{ matrix.session }}"
4047
run: |
41-
nox -e "${{ matrix.session }}"
48+
# Using GHA expression interpolation is fine here,
49+
# as we control all the inputs.
50+
nox -e "${{ matrix.session }}" -- ${{ matrix.extra-args }}

noxfile.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,14 @@ def pip_compile(session: nox.Session, req: str):
162162

163163
# Use --upgrade by default unless a user passes -P.
164164
args = list(session.posargs)
165-
if not any(
165+
166+
# Support a custom --check flag to fail if pip-compile made any changes
167+
# so we can check that that lockfiles are in sync with the input (.in) files.
168+
check_mode = "--check" in args
169+
if check_mode:
170+
# Remove from args, as pip-compile doesn't actually support --check.
171+
args.remove("--check")
172+
elif not any(
166173
arg.startswith(("-P", "--upgrade-package", "--no-upgrade")) for arg in args
167174
):
168175
args.append("--upgrade")
@@ -176,6 +183,9 @@ def pip_compile(session: nox.Session, req: str):
176183
)
177184
# fmt: on
178185

186+
if check_mode and session.run("git", "diff", "tests", silent=True, external=True):
187+
session.error("Check mode: files were changed")
188+
179189

180190
@nox.session(name="clone-core")
181191
def clone_core(session: nox.Session):

0 commit comments

Comments
 (0)