Skip to content

Commit 2510b04

Browse files
authored
Fixed parsing error when Python version is defined with tilde (#6)
1 parent 0f61aba commit 2510b04

5 files changed

Lines changed: 129 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ jobs:
170170
with:
171171
pyproject-path: ./test-fixtures/requirements-out-of-sync/pyproject.toml
172172
requirements-path: ./test-fixtures/requirements-out-of-sync/requirements.txt
173-
requirements-command: uv sync --directory ./test-fixtures/requirements-out-of-sync
173+
requirements-command: uv pip compile ./test-fixtures/requirements-out-of-sync/pyproject.toml -o ./test-fixtures/requirements-out-of-sync/requirements.txt
174174
- name: Assert action failed
175175
run: |
176176
if [[ "${{ steps.action_step.outcome }}" == "success" ]]; then
@@ -245,7 +245,7 @@ jobs:
245245
with:
246246
pyproject-path: ./test-fixtures/uv-lock-out-of-sync/pyproject.toml
247247
requirements-path: ./test-fixtures/uv-lock-out-of-sync/requirements.txt
248-
requirements-command: uv sync --directory ./test-fixtures/uv-lock-out-of-sync
248+
requirements-command: uv pip compile ./test-fixtures/uv-lock-out-of-sync/pyproject.toml -o ./test-fixtures/uv-lock-out-of-sync/requirements.txt
249249
- name: Assert action failed
250250
run: |
251251
if [[ "${{ steps.action_step.outcome }}" == "success" ]]; then
@@ -254,3 +254,23 @@ jobs:
254254
else
255255
echo "Action failed as expected."
256256
fi
257+
258+
test-python-version-tilde:
259+
runs-on: ubuntu-latest
260+
steps:
261+
- uses: actions/checkout@v4
262+
- name: Install uv
263+
run: |
264+
curl -LsSf https://astral.sh/uv/install.sh | sh
265+
export PATH="$HOME/.local/bin:$PATH"
266+
- name: Debug - List test-fixtures/python-version-tilde
267+
run: |
268+
pwd
269+
ls -l ./test-fixtures/python-version-tilde
270+
cat ./test-fixtures/python-version-tilde/pyproject.toml
271+
- name: Run action
272+
id: action_step
273+
uses: ./
274+
with:
275+
pyproject-path: ./test-fixtures/python-version-tilde/pyproject.toml
276+
requirements-command: uv sync --directory ./test-fixtures/python-version-tilde

action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ runs:
3232
echo "Error: pyproject.toml not found at ${{ inputs.pyproject-path }}"
3333
exit 1
3434
fi
35-
PYTHON_VERSION=$(grep -m 1 'requires-python' "${{ inputs.pyproject-path }}" | sed -E 's/.*>=([0-9]+\.[0-9]+).*/\1/')
35+
PYTHON_VERSION=$(grep -m 1 'requires-python' "${{ inputs.pyproject-path }}" | grep -oE '[0-9]+\.[0-9]+')
3636
if [ -z "$PYTHON_VERSION" ]; then
3737
echo "Error: Could not find Python version in ${{ inputs.pyproject-path }}"
3838
exit 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "test-project"
3+
version = "0.1.0"
4+
requires-python = "~=3.11.0"
5+
dependencies = [
6+
"requests>=2.31.0",
7+
]

test-fixtures/python-version-tilde/uv.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

verify.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33
set -euo pipefail
44

5-
# Debug: Current directory
6-
pwd
5+
# Always resolve relative to the repo root (GITHUB_WORKSPACE or git rev-parse fallback)
6+
REPO_ROOT="${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel 2>/dev/null)}"
7+
if [[ "$SYNC_COMMAND" =~ --directory[=\ ]([^ ]+) ]]; then
8+
DIR_ARG="${BASH_REMATCH[1]}"
9+
# If DIR_ARG is not absolute, make it absolute relative to repo root
10+
if [[ ! "$DIR_ARG" = /* ]]; then
11+
ABS_DIR_ARG="$REPO_ROOT/$DIR_ARG"
12+
SYNC_COMMAND="${SYNC_COMMAND/--directory $DIR_ARG/--directory $ABS_DIR_ARG}"
13+
SYNC_COMMAND="${SYNC_COMMAND/--directory=$DIR_ARG/--directory=$ABS_DIR_ARG}"
14+
fi
15+
fi
716

17+
echo "Resolved SYNC_COMMAND: $SYNC_COMMAND"
818
echo "Running sync command: $SYNC_COMMAND"
919
eval "$SYNC_COMMAND"
1020

11-
git diff --exit-code
21+
# Check if any existing files have been modified
22+
if ! git diff --exit-code --quiet; then
23+
echo "❌ Existing files have been modified by sync:"
24+
git diff --name-only
25+
echo ""
26+
echo "This indicates that your lock files or requirements files are out of sync."
27+
echo "Please run the sync command and commit the changes."
28+
exit 1
29+
fi
1230

1331
echo "✅ All files are in sync"

0 commit comments

Comments
 (0)