Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script tidup #96

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
id: uv-sync
# a new commit will not trigger this workflow again
run: |
./scripts/uv-sync.sh
./scripts/_piptools_to_uv.sh
- name: Commit file
uses: ryancyq/github-signed-commit@v1
env:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Test
run: uv run pytest -v
- name: Generate Requirements
run: ./scripts/generate_requirements.sh
run: ./scripts/_generate_requirements.sh
- id: 'deploy'
uses: 'google-github-actions/[email protected]'
with:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ dev-dependencies = [
"pytest-freezegun>=0.4.2",
]

# Note - scripts/uv-sync.sh will append here, it assumes tool.uv is the last section
# Note - scripts/_piptools_to_uv.sh will append here, it assumes tool.uv is the last section
7 changes: 7 additions & 0 deletions scripts/_common_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bash safe mode, this file is expected to be sourced
# source ./scripts/_common_init.sh

set -e
set -u
set -o pipefail

5 changes: 5 additions & 0 deletions scripts/_generate_requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# generate requirements with hashes, for use by cloud function deploy

uv export --output-file=requirements.txt --quiet
31 changes: 31 additions & 0 deletions scripts/_piptools_to_uv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Sync requirements.txt to uv
# This is only intended to be run from within the uv-sync action, and note that the pyproject change
# it makes isn't intended to be checked in

# adapted from https://github.com/win845/uv-light/blob/b4fabd9fc4fca621dd91bfe0a90e6ce6f17dd5ce/bin/uv-sync.sh

source ./scripts/_common_init.sh

AUTHOR_NAME=$(git log -1 --pretty=format:"%an")

if [[ "$AUTHOR_NAME" == *dependabot* ]] ; then
# Read requirements.txt, exclude comments, and format as TOML array
constraints=$(grep -vE '^\s*#' requirements.txt | awk '{print " \""$0"\","}')

echo
# Append constraint-dependencies to pyproject.toml
cat <<EOF >> pyproject.toml

### generated scripts/uv-sync.sh , but not intended to be checked in! ###
constraint-dependencies = [
$constraints
]
EOF

echo "Lock uv with a new requirements.txt as constraint"
uv lock
fi

./scripts/_uv_to_piptools.sh
27 changes: 27 additions & 0 deletions scripts/_uv_to_piptools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Generate requirements.txt in the same format as pip-tools,
# from the current uv config

# adapted from https://github.com/win845/uv-light/blob/b4fabd9fc4fca621dd91bfe0a90e6ce6f17dd5ce/bin/uv-sync.sh

source ./scripts/_common_init.sh

PYTHON_VERSION=$(cat .python-version)

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
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -o nounset
source ./scripts/_common_init.sh

./scripts/generate_requirements.sh
gcloud functions deploy update2 --gen2 --runtime=python312 --region=us-central1 \
Expand Down
3 changes: 0 additions & 3 deletions scripts/generate_requirements.sh

This file was deleted.

54 changes: 0 additions & 54 deletions scripts/uv-sync.sh

This file was deleted.

11 changes: 11 additions & 0 deletions scripts/uv_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Update python package versions

# adapted from https://github.com/win845/uv-light/blob/b4fabd9fc4fca621dd91bfe0a90e6ce6f17dd5ce/bin/uv-sync.sh

source ./scripts/_common_init.sh

uv lock --upgrade

./scripts/_uv_to_piptools.sh
Loading