From 626a65668f80bfa138b93aacdbccb89856c9b3c3 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Wed, 9 Aug 2023 19:42:39 -0700 Subject: [PATCH] change build script to gitea syntax? --- .gitea/workflows/build_changed.yml | 108 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/.gitea/workflows/build_changed.yml b/.gitea/workflows/build_changed.yml index c4558db..c816a99 100644 --- a/.gitea/workflows/build_changed.yml +++ b/.gitea/workflows/build_changed.yml @@ -1,59 +1,57 @@ -stages: - - build_and_upload_changed_packages +name: Build Changed +run-name: build_and_upload_changed_packages +on: push -build_and_upload_changed_packages: - image: python:3.9 - stage: build_and_upload_changed_packages - script: - - pip install -U pip - - pip install twine build toml - # Determine the list of changed files using git - - git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA > changed_files.txt +jobs: + build_and_upload_changed_packages: + runs-on: python:3.9 + steps: + - run: pip install -U pip + - run: pip install twine build toml + # Determine the list of changed files using git + - run: git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA > changed_files.txt - # Loop through each package directory, check if version has changed, build if changed, and then upload - - | - 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)") + - name: Loop through each package directory, check if version has changed, build if changed, and then upload + run: | + 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 + + 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 - 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 - only: - - pushes - - merge_requests + done