python-packages/.gitea/workflows/build_changed.yml

64 lines
3.5 KiB
YAML
Raw Normal View History

2023-08-09 19:42:39 -07:00
name: Build Changed
run-name: build_and_upload_changed_packages
on: push
2023-08-09 19:28:14 -07:00
2023-08-09 19:42:39 -07:00
jobs:
build_and_upload_changed_packages:
2023-08-09 19:48:35 -07:00
runs-on: ubuntu-latest
2023-08-09 19:52:52 -07:00
container: catthehacker/ubuntu:act-latest
2023-08-09 19:42:39 -07:00
steps:
2023-08-09 19:52:52 -07:00
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
2023-08-09 19:50:24 -07:00
- run: pip3 install -U pip
2023-08-09 19:42:39 -07:00
- run: pip install twine build toml
# Determine the list of changed files using git
2023-08-09 19:56:01 -07:00
- run: echo "Checking for changed packages"
2023-08-09 19:42:39 -07:00
- name: Loop through each package directory, check if version has changed, build if changed, and then upload
run: |
2023-08-09 19:56:01 -07:00
git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA > changed_files.txt
2023-08-09 19:42:39 -07:00
for package_dir in ./*; do
if [ -d "$package_dir" ]; then
package_name=$(basename $package_dir)
if grep -q "$package_name" changed_files.txt; 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
2023-08-09 19:28:14 -07:00
2023-08-09 19:42:39 -07:00
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
2023-08-09 19:28:14 -07:00
fi
2023-08-09 19:42:39 -07:00
done