Skip to content

fix: use Path.replace() for Windows compatibility (#74) #42

fix: use Path.replace() for Windows compatibility (#74)

fix: use Path.replace() for Windows compatibility (#74) #42

Workflow file for this run

name: Build and Publish to PyPI
on:
push:
branches:
- test
- release
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-*'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
type: choice
options:
- test
- release
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
environment: ${{ steps.determine-env.outputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for hatch-vcs versioning
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
- name: Install build dependencies
run: |
uv pip install --system build hatch hatch-vcs twine
- name: Determine environment
id: determine-env
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/test" ]]; then
echo "environment=test" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/release" ]] || [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "environment=release" >> $GITHUB_OUTPUT
fi
- name: Get version and configure for environment
id: version
run: |
if [[ "${{ steps.determine-env.outputs.environment }}" == "test" ]]; then
# Test environment: use hatch to get automatic dev versioning
VERSION=$(hatch version)
echo "Development version: $VERSION"
else
# Production environment: get clean version from tags
VERSION=$(git describe --tags --exact-match 2>/dev/null | sed 's/^v//')
if [[ -z "$VERSION" ]]; then
echo "Error: Production releases require an exact git tag"
exit 1
fi
echo "Production version: $VERSION"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Build package
run: python -m build
- name: Check package
run: |
twine check dist/*
ls -lh dist/
echo "Package version: ${{ steps.version.outputs.version }}"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ steps.determine-env.outputs.environment }}
path: dist/
publish-test:
needs: build
if: needs.build.outputs.environment == 'test'
runs-on: ubuntu-latest
environment:
name: test
url: https://test.pypi.org/project/workato-platform-cli/
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist-test
path: dist/
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
print-hash: true
- name: Set up Python for testing
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
- name: Test installation
run: |
echo "Waiting for Test PyPI to process the package..."
sleep 30
echo "Attempting to install latest workato-platform-cli from TestPyPI"
uv pip install --system \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
workato-platform-cli || echo "Package not yet available on Test PyPI"
# Verify CLI if installation succeeded
workato --version || echo "CLI check skipped"
publish-release:
needs: build
if: needs.build.outputs.environment == 'release'
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/project/workato-platform-cli/
permissions:
id-token: write # Required for trusted publishing
contents: write # For creating GitHub releases
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist-release
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: dist/*
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}