python-packages/.gitea/workflows/build_changed.yml
2023-08-09 20:02:45 -07:00

64 lines
3.5 KiB
YAML

name: Build Changed
run-name: build_and_upload_changed_packages
on: push
jobs:
build_and_upload_changed_packages:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
- run: pip3 install -U pip
- run: pip install twine build toml
# Determine the list of changed files using git
- run: echo "Checking for changed packages"
- name: Loop through each package directory, check if version has changed, build if changed, and then upload
run: |
echo "Starting check"
for package_dir in ./*; do
if [ -d "$package_dir" ]; then
package_name=$(basename $package_dir)
if git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep -q "$package_name"; then
echo "Checking version for: $package_name"
if [ -f "$package_dir/pyproject.toml" ]; then
current_version=$(python -c "import toml; data = toml.load('$package_dir/pyproject.toml'); print(data['project']['version']) if 'project' in data and 'version' in data['project'] else print(None)")
echo "Current version: $current_version"
if [ "$current_version" = "None" ]; then
current_version=$(grep -oP '(?<=version=\")[^\"]+' $package_dir/setup.py)
last_version="$(git cat-file -p "$CI_COMMIT_BEFORE_SHA:$package_dir/setup.py" | grep -oP '(?<=version=\")[^\"]+')"
else
last_version=$(git cat-file -p "$CI_COMMIT_BEFORE_SHA:$package_dir/pyproject.toml" | python -c "import sys, toml; data = toml.loads(sys.stdin.read()); print(data['project']['version']) if 'project' in data and 'version' in data['project'] else print(None)")
fi
echo "Previous version: $last_version"
elif [ -f "$package_dir/setup.py" ]; then
current_version=$(grep -oP '(?<=version=\")[^\"]+' $package_dir/setup.py)
last_version=$(git cat-file "$CI_COMMIT_BEFORE_SHA:$package_dir/setup.py" | grep -oP '(?<=version=\")[^\"]+')
else
echo "No recognizable version information in $package_name. Skipping."
continue
fi
if [ "$current_version" != "$last_version" ]; then
echo "Version updated... proceeding with build"
# Create ~/.config/pip directory if it doesn't exist
mkdir -p ~/.config/pip
# Create ~/.config/pip/pip.conf file with specific configuration
echo "[global]" > ~/.config/pip/pip.conf
echo "timeout = 60" >> ~/.config/pip/pip.conf
echo "extra-index-url = https://sudacode:$GITEA_TOKEN@gitea.suda.codes/api/packages/sudacode/pypi/simple" >> ~/.config/pip/pip.conf
echo "Building and uploading $package_name (version $current_version) as it has changes..."
cd $package_dir
python -m build
twine upload --repository-url https://gitea.suda.codes/api/packages/sudacode/pypi --username sudacode --password $GITEA_TOKEN dist/*
cd -
else
echo "Skipping $package_name as the version has not changed."
fi
fi
fi
done