diff --git a/.github/workflows/publish-python-sdk-release.yml b/.github/workflows/publish-python-sdk-release.yml new file mode 100644 index 00000000..2151a120 --- /dev/null +++ b/.github/workflows/publish-python-sdk-release.yml @@ -0,0 +1,126 @@ +name: Publish Python SDK on Release + +on: + release: + types: [published] + +permissions: + contents: read + id-token: write + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install uv + uses: astral-sh/setup-uv@v2 + + - name: Install dev dependencies with uv + working-directory: python-sdk + run: | + uv sync --group dev + + - name: Install python-sdk package (editable) + working-directory: python-sdk + run: | + uv pip install -e . + + - name: Run tests with pytest and coverage + working-directory: python-sdk + run: | + uv run pytest --cov=exospherehost --cov-report=xml --cov-report=term-missing -v --junitxml=pytest-report.xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: exospherehost/exospherehost + files: python-sdk/coverage.xml + flags: python-sdk-unittests + name: python-sdk-coverage-report + fail_ci_if_error: true + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: python-sdk-test-results + path: python-sdk/pytest-report.xml + retention-days: 30 + + publish: + runs-on: ubuntu-latest + needs: test + defaults: + run: + working-directory: python-sdk + + steps: + - uses: actions/checkout@v4 + + - uses: astral-sh/setup-uv@v6 + name: Install uv + + - run: uv python install + + - run: uv sync --locked --dev + + - name: Update version to release tag + run: | + # Extract version from tag (remove 'v' or 'V' prefix if present) + RELEASE_VERSION="${{ github.ref_name }}" + + # Handle empty or invalid tags + if [[ -z "$RELEASE_VERSION" ]]; then + echo "ERROR: Release tag is empty" + exit 1 + fi + + # Remove 'v' or 'V' prefix (case insensitive) + if [[ $RELEASE_VERSION =~ ^[vV] ]]; then + RELEASE_VERSION="${RELEASE_VERSION#?}" # Remove first character + fi + + # Validate the extracted version is not empty + if [[ -z "$RELEASE_VERSION" ]]; then + echo "ERROR: Invalid tag format - version part is empty" + exit 1 + fi + + # Update the version file + echo "version = \"$RELEASE_VERSION\"" > exospherehost/_version.py + + echo "Updated version to $RELEASE_VERSION for release" + + - name: Verify version format + run: | + python -c " + import sys + sys.path.append('.') + from exospherehost._version import version + import re + + # Check if version matches semantic versioning pattern + if not re.match(r'^\d+\.\d+\.\d+$', version): + print(f'ERROR: Version {version} does not match semantic versioning pattern (x.y.z)') + sys.exit(1) + + # Ensure it's not a beta version (should not contain 'b') + if 'b' in version: + print(f'ERROR: Release version {version} contains beta indicator. Release versions should not be beta.') + sys.exit(1) + + print(f'Version {version} is valid for release publishing') + " + + - run: uv build + + - run: uv publish \ No newline at end of file diff --git a/.github/workflows/publish-python-sdk.yml b/.github/workflows/publish-python-sdk.yml index 0cbc2b3e..a4e358ce 100644 --- a/.github/workflows/publish-python-sdk.yml +++ b/.github/workflows/publish-python-sdk.yml @@ -25,9 +25,7 @@ jobs: python-version: '3.12' - name: Install uv - uses: astral-sh/setup-uv@v2 - with: - cache: true + uses: astral-sh/setup-uv@v6 - name: Install dev dependencies with uv working-directory: python-sdk @@ -79,6 +77,18 @@ jobs: - run: uv sync --locked --dev + - name: Check version for beta indicator + run: | + python -c " + import sys + sys.path.append('.') + from exospherehost._version import version + if 'b' not in version: + print(f'ERROR: Version {version} does not contain beta indicator (b). Major releases are only allowed through GitHub releases.') + sys.exit(1) + print(f'Version {version} is valid for PyPI publishing (contains beta indicator)') + " + - run: uv build - run: uv publish