diff --git a/.github/workflows/release-build.yaml b/.github/workflows/release-build.yaml index eb8b559..b7e318b 100644 --- a/.github/workflows/release-build.yaml +++ b/.github/workflows/release-build.yaml @@ -1,35 +1,76 @@ -name: Release workflow - Build and Publish Package +# This workflow will upload a Python Package to PyPI when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +name: Upload Python Package on: - push: - branches: - - main - paths: - - 'version.py' # Only run when the version is bumped + release: + types: [published] + +permissions: + contents: read jobs: - build-and-publish: - runs-on: ubuntu-22.04 - permissions: - id-token: write - contents: read + release-build: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + steps: - name: Checkout uses: actions/checkout@v4 + with: + # Fetch sufficient history for setuptools-scm to find tags + # Using 50 commits should cover most scenarios while being faster than full history + fetch-depth: 50 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: "3.12" - - name: Install dependencies + - name: Get version from setuptools-scm + id: get_version run: | - python -m pip install --upgrade pip - python -m pip install setuptools wheel twine + python -m pip install setuptools-scm + version=$(python -m setuptools_scm) + echo "version=$version" >> $GITHUB_OUTPUT + echo "Package version: $version" - - name: Build package + - name: Build release distributions run: | - python setup.py sdist bdist_wheel + python -m pip install build + python -m build + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ - - name: Publish package to PyPI + pypi-publish: + runs-on: ubuntu-latest + needs: + - release-build + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + # Dedicated environments with protections for publishing are strongly recommended. + # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules + environment: + name: pypi + # PyPI project URL with the exact version (e.g., 1.3.3 or 1.3.3b3) + url: https://pypi.org/project/oscar-python/${{ needs.release-build.outputs.version }}/ + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ diff --git a/.github/workflows/release-version.yaml b/.github/workflows/release-version.yaml deleted file mode 100644 index e348a60..0000000 --- a/.github/workflows/release-version.yaml +++ /dev/null @@ -1,119 +0,0 @@ -name: Release workflow - Increase Version - -on: - release: - types: [created] -# schedule: -# - cron: '0 0 1 * *' # Runs at 00:00 on the 1st of every month - workflow_dispatch: - inputs: - version_type: - description: 'Type of version increment (patch, minor, major)' - required: true - default: 'patch' - -jobs: - release: - runs-on: ubuntu-22.04 - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all history for tags - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install setuptools wheel twine - - - name: Check for changes inside oscar_python directory - id: check_changes - run: | - # Get the latest release tag - latest_release=$(git describe --tags --abbrev=0 2>/dev/null || echo "") - - if [ -z "$latest_release" ]; then - echo "No previous release found - treating as first release" - echo "changes_detected=true" >> $GITHUB_ENV - else - echo "Latest release: $latest_release" - # Check if there are changes in oscar_python directory since last release - if git log $latest_release..HEAD --pretty=format: --name-only | grep -q '^oscar_python/'; then - echo "Changes detected in oscar_python directory since $latest_release" - echo "changes_detected=true" >> $GITHUB_ENV - else - echo "No changes detected in oscar_python directory since $latest_release" - echo "changes_detected=false" >> $GITHUB_ENV - fi - fi - - - name: Get current version - if: env.changes_detected == 'true' - id: get_version - run: | - current_version=$(python setup.py --version) - echo "Current version: $current_version" - IFS='.' read -r -a version_parts <<< "$current_version" - major=${version_parts[0]} - minor=${version_parts[1]} - patch=${version_parts[2]} - version_type="${{ github.event.inputs.version_type }}" - if [ "$version_type" == "major" ]; then - new_major=$((major + 1)) - new_version="$new_major.0.0" - elif [ "$version_type" == "minor" ]; then - new_minor=$((minor + 1)) - new_version="$major.$new_minor.0" - else - new_patch=$((patch + 1)) - new_version="$major.$minor.$new_patch" - fi - echo "New version: $new_version" - echo "::set-output name=new_version::$new_version" - - - name: Create GitHub Release - if: env.changes_detected == 'true' - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ steps.get_version.outputs.new_version }} - release_name: Release ${{ steps.get_version.outputs.new_version }} - draft: false - prerelease: false - - - name: Update version.py - if: env.changes_detected == 'true' - run: | - echo "__version__ = '$new_version'" > version.py - env: - new_version: ${{ steps.get_version.outputs.new_version }} - - - name: Commit version change and push to a new branch - if: env.changes_detected == 'true' - run: | - git config --global user.name 'github-actions' - git config --global user.email 'github-actions@github.com' - git checkout -b bump-version-${{ steps.get_version.outputs.new_version }} - git add version.py - git commit -m "Bump version to $new_version" - git push origin bump-version-${{ steps.get_version.outputs.new_version }} - env: - new_version: ${{ steps.get_version.outputs.new_version }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Create Pull Request - if: env.changes_detected == 'true' - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: bump-version-${{ steps.get_version.outputs.new_version }} - title: "Bump version to ${{ steps.get_version.outputs.new_version }}" - body: "Automated version bump and release workflow" - base: main diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1af594f..7dd6c36 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -2,9 +2,9 @@ name: tests on: push: - branches: ["main"] + branches: ["main", "devel"] pull_request: - branches: ["main"] + branches: ["main", "devel"] jobs: test: @@ -19,7 +19,9 @@ jobs: python-version: '3.12' - name: Install dependencies - run: python -m pip install pytest pytest-cov webdavclient3 requests boto3 pyyaml aiohttp liboidcagent + run: | + python -m pip install --upgrade pip + python -m pip install -e .[dev] - name: Run tests run: python -m pytest tests --cov=oscar_python diff --git a/README.md b/README.md index 360646f..9625397 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Python OSCAR client -[![Build](https://github.com/grycap/oscar_python/actions/workflows/release-build.yaml/badge.svg)](https://github.com/grycap/oscar_python/actions/workflows/release-build.yaml) -![PyPI](https://img.shields.io/pypi/v/oscar_python) +[![Tests](https://github.com/grycap/oscar_python/actions/workflows/tests.yaml/badge.svg?branch=main)](https://github.com/grycap/oscar_python/actions/workflows/tests.yaml) +[![PyPI](https://img.shields.io/pypi/v/oscar-python)](https://pypi.org/project/oscar-python/) This package provides a client to interact with OSCAR (https://oscar.grycap.net) clusters and services. It is available on Pypi with the name [oscar-python](https://pypi.org/project/oscar-python/). diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0725c79 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools>=64", "setuptools-scm>=8"] +build-backend = "setuptools.build_meta" + +[project] +name = "oscar-python" +dynamic = ["version"] +description = "Python client for OSCAR clusters" +readme = "README.md" +requires-python = ">=3.8" +license = {text = "Apache-2.0"} +authors = [{name = "GRyCAP - I3M - UPV"}] +keywords = ["oscar", "faas", "serverless"] + +dependencies = [ + "requests", + "webdavclient3>=3.14.6", + "boto3", + "pyyaml", + "aiohttp", + "liboidcagent", +] + +[project.optional-dependencies] +dev = [ + "pytest", + "pytest-cov", +] + +[project.urls] +Homepage = "https://github.com/grycap/oscar-python" +Repository = "https://github.com/grycap/oscar-python" + +[tool.setuptools] +packages = ["oscar_python"] + +[tool.setuptools_scm] +# Automatically get version from git tags \ No newline at end of file diff --git a/setup.py b/setup.py index a3b6b30..0ea8fbc 100644 --- a/setup.py +++ b/setup.py @@ -12,38 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import setup, find_namespace_packages +"""Minimal setup.py for backward compatibility. +All configuration is now in pyproject.toml. +""" -# Load readme -with open('README.md', mode='r', encoding='utf-8') as f: - readme = f.read() +from setuptools import setup -# Load version -with open('version.py', mode='r', encoding='utf-8') as f: - exec(f.read()) - - -setup(name='oscar_python', - version=__version__, - description='OSCAR API for python', - long_description=readme, - long_description_content_type='text/markdown', - url='https://github.com/grycap/oscar_python', - author='GRyCAP - Universitat Politecnica de Valencia', - author_email='calarcon@i3m.upv.es', - license='Apache 2.0', - packages=find_namespace_packages(), - install_requires=[ - 'webdavclient3 == 3.14.6', - 'requests', - 'boto3', - 'setuptools >= 40.8.0', - 'pyyaml', - 'aiohttp', - 'liboidcagent', - ], - classifiers=[ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: Apache Software License' - ], - zip_safe=False) +setup() diff --git a/version.py b/version.py deleted file mode 100644 index 4aff280..0000000 --- a/version.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) GRyCAP - I3M - UPV -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Stores the package version.""" - - -__version__ = '1.3.2'