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