|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +PYTHON_VERSION=$(cat .python-version) |
| 5 | +BRANCH_NAME=${GITHUB_REF#refs/heads/} |
| 6 | +AUTHOR_NAME=$(git log -1 --pretty=format:"%an") |
| 7 | +AUTHOR_EMAIL=$(git log -1 --pretty=format:"%ae") |
| 8 | + |
| 9 | +if [[ "$AUTHOR_NAME" == *dependabot* ]] ; then |
| 10 | + # Read requirements.txt, exclude comments, and format as TOML array |
| 11 | + constraints=$(grep -vE '^\s*#' requirements.txt | awk '{print " \""$0"\","}') |
| 12 | + |
| 13 | + # Append constraint-dependencies to pyproject.toml |
| 14 | + cat <<EOF >> pyproject.toml |
| 15 | +
|
| 16 | +[tool.uv] |
| 17 | +constraint-dependencies = [ |
| 18 | +$constraints |
| 19 | +] |
| 20 | +EOF |
| 21 | + |
| 22 | + echo "Lock uv with a new requirements.txt as constraint" |
| 23 | + uv lock |
| 24 | +fi |
| 25 | + |
| 26 | +echo "Export uv.lock to requirements.txt" |
| 27 | +uv export --no-hashes -o requirements.txt |
| 28 | + |
| 29 | +# Add pip-compile like comment to the top of requirements.txt |
| 30 | +# for dependabot to detect a pip-compile workflow |
| 31 | +cat << EOF | cat - requirements.txt > temp && mv temp requirements.txt |
| 32 | +# |
| 33 | +# This file is autogenerated by pip-compile with Python $PYTHON_VERSION |
| 34 | +# by the following command: |
| 35 | +# |
| 36 | +# pip-compile pyproject.toml |
| 37 | +# |
| 38 | +# |
| 39 | +# The above comment was added for dependabot to support uv. |
| 40 | +# |
| 41 | +EOF |
| 42 | + |
| 43 | +git add uv.lock requirements.txt |
| 44 | +if ! git diff --cached --quiet; then |
| 45 | + git config --global user.name "$AUTHOR_NAME" |
| 46 | + git config --global user.email "$AUTHOR_EMAIL" |
| 47 | + git commit -m "Sync uv.lock and requirements.txt" |
| 48 | + git push origin $BRANCH_NAME |
| 49 | + echo "push changes" |
| 50 | +fi |
0 commit comments