Skip to content

Commit bbf99c2

Browse files
authored
Improve test workflow, add sync option, and enhance requirements checking (#1)
1 parent 7f6c752 commit bbf99c2

4 files changed

Lines changed: 179 additions & 59 deletions

File tree

.github/workflows/test.yml

Lines changed: 123 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ jobs:
2727
]
2828
EOF
2929
30+
- name: Install uv
31+
run: |
32+
curl -LsSf https://astral.sh/uv/install.sh | sh
33+
export PATH="$HOME/.local/bin:$PATH"
34+
3035
- name: Generate lock file
3136
working-directory: test-project
3237
run: |
33-
curl -LsSf https://astral.sh/uv/install.sh | sh
34-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
38+
export PATH="$HOME/.local/bin:$PATH"
3539
uv sync
3640
3741
- name: Test basic usage
@@ -58,19 +62,25 @@ jobs:
5862
]
5963
EOF
6064
61-
- name: Generate lock and requirements files
65+
- name: Install uv
6266
working-directory: test-project
6367
run: |
6468
curl -LsSf https://astral.sh/uv/install.sh | sh
65-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
69+
export PATH="$HOME/.local/bin:$PATH"
70+
71+
- name: Generate lock and requirements files
72+
working-directory: test-project
73+
run: |
74+
export PATH="$HOME/.local/bin:$PATH"
6675
uv sync
6776
uv pip compile pyproject.toml -o requirements.txt
6877
6978
- name: Test with requirements
7079
uses: ./
7180
with:
7281
pyproject-path: test-project/pyproject.toml
73-
requirements-path: test-project/requirements.txt
82+
requirements-path: requirements.txt
83+
requirements-command: uv pip compile pyproject.toml -o requirements.txt
7484

7585
test-custom-requirements:
7686
runs-on: ubuntu-latest
@@ -91,27 +101,30 @@ jobs:
91101
]
92102
EOF
93103
94-
- name: Generate lock and platform-specific requirements
104+
- name: Install uv
95105
working-directory: test-project
96106
run: |
97107
curl -LsSf https://astral.sh/uv/install.sh | sh
98-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
108+
export PATH="$HOME/.local/bin:$PATH"
109+
- name: Generate lock and platform-specific requirements
110+
working-directory: test-project
111+
run: |
112+
export PATH="$HOME/.local/bin:$PATH"
99113
uv sync
100114
uv pip compile --python-platform=linux pyproject.toml -o requirements-linux.txt
101115
102116
- name: Test with custom requirements command
103117
uses: ./
104118
with:
105119
pyproject-path: test-project/pyproject.toml
106-
requirements-path: test-project/requirements-linux.txt
120+
requirements-path: requirements-linux.txt
107121
requirements-command: uv pip compile --python-platform=linux pyproject.toml -o requirements-linux.txt
108122

109-
test-failure:
123+
test-requirements-failure:
110124
runs-on: ubuntu-latest
111125
steps:
112126
- uses: actions/checkout@v4
113-
114-
- name: Create test project
127+
- name: Setup test project
115128
run: |
116129
mkdir -p test-project
117130
cat > test-project/pyproject.toml << EOF
@@ -124,21 +137,110 @@ jobs:
124137
"pytest>=7.4.0",
125138
]
126139
EOF
127-
128-
- name: Generate lock file
140+
- name: Install uv
141+
run: |
142+
curl -LsSf https://astral.sh/uv/install.sh | sh
143+
export PATH="$HOME/.local/bin:$PATH"
144+
- name: Generate requirements.txt
129145
working-directory: test-project
146+
run: |
147+
export PATH="$HOME/.local/bin:$PATH"
148+
uv pip compile pyproject.toml -o requirements.txt
149+
- name: Modify pyproject.toml
150+
run: |
151+
sed -i 's/pytest>=7.4.0/pytest>=7.5.0/' test-project/pyproject.toml
152+
- uses: ./
153+
with:
154+
pyproject-path: test-project/pyproject.toml
155+
requirements-path: requirements.txt
156+
requirements-command: uv pip compile pyproject.toml -o requirements.txt
157+
158+
test-uv-lock-failure:
159+
runs-on: ubuntu-latest
160+
steps:
161+
- uses: actions/checkout@v4
162+
- name: Setup test project
163+
run: |
164+
mkdir -p test-project
165+
cat > test-project/pyproject.toml << EOF
166+
[project]
167+
name = "test-project"
168+
version = "0.1.0"
169+
requires-python = ">=3.9"
170+
dependencies = [
171+
"requests>=2.31.0",
172+
"pytest>=7.4.0",
173+
]
174+
EOF
175+
- name: Install uv
130176
run: |
131177
curl -LsSf https://astral.sh/uv/install.sh | sh
132-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
178+
export PATH="$HOME/.local/bin:$PATH"
179+
- name: Generate uv.lock
180+
working-directory: test-project
181+
run: |
182+
export PATH="$HOME/.local/bin:$PATH"
133183
uv sync
134-
135-
- name: Modify pyproject.toml to cause failure
184+
- name: Modify pyproject.toml
185+
run: |
186+
sed -i 's/pytest>=7.4.0/pytest>=7.5.0/' test-project/pyproject.toml
187+
- name: Update uv.lock
136188
working-directory: test-project
137189
run: |
138-
sed -i 's/requests>=2.31.0/requests>=2.32.0/' pyproject.toml
139-
140-
- name: Test failure case
190+
export PATH="$HOME/.local/bin:$PATH"
191+
uv sync
192+
- uses: ./
193+
with:
194+
pyproject-path: test-project/pyproject.toml
195+
requirements-path: requirements.txt
196+
requirements-command: uv pip compile pyproject.toml -o requirements.txt -- --platform linux
197+
198+
test-multiple-requirements:
199+
runs-on: ubuntu-latest
200+
steps:
201+
- uses: actions/checkout@v4
202+
- name: Create test project
203+
run: |
204+
mkdir -p test-project
205+
cat > test-project/pyproject.toml << EOF
206+
[project]
207+
name = "test-project"
208+
version = "0.1.0"
209+
requires-python = ">=3.9"
210+
dependencies = [
211+
"requests>=2.31.0",
212+
"pytest>=7.4.0",
213+
]
214+
EOF
215+
- name: Install uv
216+
working-directory: test-project
217+
run: |
218+
curl -LsSf https://astral.sh/uv/install.sh | sh
219+
export PATH="$HOME/.local/bin:$PATH"
220+
- name: Print uv version
221+
working-directory: test-project
222+
run: |
223+
export PATH="$HOME/.local/bin:$PATH"
224+
uv --version
225+
- name: Generate requirements-linux.txt
226+
working-directory: test-project
227+
run: |
228+
export PATH="$HOME/.local/bin:$PATH"
229+
uv pip compile --python-platform=linux pyproject.toml -o requirements-linux.txt
230+
- name: Generate requirements-win.txt
231+
working-directory: test-project
232+
run: |
233+
export PATH="$HOME/.local/bin:$PATH"
234+
uv pip compile --python-platform=windows pyproject.toml -o requirements-win.txt
235+
- name: Check Linux Requirements
141236
uses: ./
142-
continue-on-error: true
143237
with:
144-
pyproject-path: test-project/pyproject.toml
238+
pyproject-path: test-project/pyproject.toml
239+
requirements-command: uv pip compile --python-platform=linux pyproject.toml -o requirements-linux.txt
240+
requirements-path: requirements-linux.txt
241+
- name: Check Windows Requirements
242+
uses: ./
243+
with:
244+
pyproject-path: test-project/pyproject.toml
245+
requirements-command: uv pip compile --python-platform=windows pyproject.toml -o requirements-win.txt
246+
requirements-path: requirements-win.txt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
- name: Check Windows Requirements
9191
uses: hbelmiro/uv-lock-check@v1
9292
with:
93-
requirements-command: 'uv pip compile --python-platform=win32 pyproject.toml -o requirements-win.txt'
93+
requirements-command: 'uv pip compile --python-platform=windows pyproject.toml -o requirements-win.txt'
9494
requirements-path: 'requirements-win.txt'
9595
```
9696

action.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ inputs:
1717
description: 'Complete uv command to generate requirements.txt (e.g., "uv pip compile --python-platform=linux pyproject.toml -o requirements-linux.txt")'
1818
required: false
1919
default: 'uv pip compile pyproject.toml -o requirements.txt'
20+
run-sync:
21+
description: 'Whether to run uv sync to update uv.lock and requirements.txt'
22+
required: false
23+
default: 'false'
2024

2125
runs:
2226
using: "composite"
@@ -54,6 +58,16 @@ runs:
5458
curl -LsSf https://astral.sh/uv/install.sh | sh
5559
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
5660
61+
- name: Run uv sync
62+
if: inputs.run-sync == 'true'
63+
shell: bash
64+
working-directory: ${{ env.PYPROJECT_DIR }}
65+
run: |
66+
uv sync
67+
if [ -f "${{ env.REQUIREMENTS_PATH }}" ]; then
68+
${{ inputs.requirements-command }}
69+
fi
70+
5771
- name: Verify files
5872
shell: bash
5973
working-directory: ${{ env.PYPROJECT_DIR }}

verify.sh

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
# Exit on error, unset var, or pipefail
44
set -euo pipefail
55

6-
echo "Checking if uv.lock matches pyproject.toml..."
6+
# Debug information
7+
echo "Debug: Current directory: $(pwd)"
8+
echo "Debug: REQUIREMENTS_PATH: $REQUIREMENTS_PATH"
9+
echo "Debug: REQUIREMENTS_COMMAND: $REQUIREMENTS_COMMAND"
710

811
# Check if pyproject.toml exists
912
if [ ! -f "pyproject.toml" ]; then
1013
echo "Error: pyproject.toml not found"
1114
exit 1
1215
fi
1316

14-
# Check if uv.lock exists
15-
if [ ! -f "uv.lock" ]; then
16-
echo "Error: uv.lock not found"
17-
exit 1
18-
fi
19-
20-
# Run uv sync to update the lock file
21-
echo "Running uv sync to check for any differences..."
22-
uv sync
23-
24-
# Check if there are any differences in uv.lock
25-
if ! git diff --quiet -- uv.lock || ! git diff --cached --quiet -- uv.lock; then
26-
echo "Error: uv.lock is out of sync with pyproject.toml"
27-
echo "Please run 'uv sync' locally and commit the changes"
28-
exit 1
17+
# Check uv.lock if it exists
18+
if [ -f "uv.lock" ]; then
19+
echo "Checking if uv.lock matches pyproject.toml..."
20+
echo "Running uv sync to check for any differences..."
21+
if ! uv sync; then
22+
echo "❌ uv.lock is out of sync with pyproject.toml"
23+
exit 1
24+
fi
25+
echo "✅ uv.lock is in sync with pyproject.toml"
2926
fi
3027

31-
echo "✅ uv.lock is in sync with pyproject.toml"
32-
33-
# Check requirements.txt if it exists
34-
if [ -f "$REQUIREMENTS_PATH" ]; then
35-
echo "Checking if requirements.txt matches pyproject.toml..."
36-
37-
# Create a temporary requirements file
38-
TEMP_REQUIREMENTS=$(mktemp)
28+
# Check if requirements.txt exists and matches pyproject.toml
29+
if [ -n "${REQUIREMENTS_PATH:-}" ]; then
30+
# Get the basename of the requirements path
31+
REQUIREMENTS_FILE=$(basename "$REQUIREMENTS_PATH")
32+
echo "Debug: Looking for requirements file: $REQUIREMENTS_FILE"
3933

40-
# Generate requirements using the provided command
41-
echo "Generating requirements using command: $REQUIREMENTS_COMMAND"
42-
eval "$REQUIREMENTS_COMMAND" -o "$TEMP_REQUIREMENTS"
43-
44-
# Compare the generated requirements with the existing one
45-
if ! diff -q "$TEMP_REQUIREMENTS" "$REQUIREMENTS_PATH" > /dev/null; then
46-
echo "Error: requirements.txt is out of sync with pyproject.toml"
47-
echo "Please run '$REQUIREMENTS_COMMAND' locally and commit the changes"
34+
if [ -f "$REQUIREMENTS_FILE" ]; then
35+
echo "Checking if requirements.txt matches pyproject.toml..."
36+
# Generate a temporary requirements file
37+
TEMP_REQUIREMENTS=$(mktemp)
38+
eval "$REQUIREMENTS_COMMAND" > "$TEMP_REQUIREMENTS"
39+
40+
# Compare the files
41+
if ! diff -q "$REQUIREMENTS_FILE" "$TEMP_REQUIREMENTS" > /dev/null; then
42+
echo "❌ requirements.txt is out of sync with pyproject.toml"
43+
echo "Run the following command to update requirements.txt:"
44+
echo "$REQUIREMENTS_COMMAND"
45+
rm "$TEMP_REQUIREMENTS"
46+
exit 1
47+
fi
4848
rm "$TEMP_REQUIREMENTS"
49-
exit 1
49+
echo "✅ requirements.txt is in sync with pyproject.toml"
50+
else
51+
echo "⚠️ requirements.txt not found at $REQUIREMENTS_FILE. Skipping requirements check."
52+
echo "If you want to check requirements.txt, generate it with:"
53+
echo "$REQUIREMENTS_COMMAND"
54+
# Do not exit with error, just skip
5055
fi
51-
52-
rm "$TEMP_REQUIREMENTS"
53-
echo "✅ requirements.txt is in sync with pyproject.toml"
56+
else
57+
echo "No requirements.txt specified, skipping requirements check."
5458
fi

0 commit comments

Comments
 (0)