name: Reusable Package Publish Workflow on: workflow_call: inputs: package_name: description: "Name of the package (e.g. computer, agent)" required: true type: string package_dir: description: "Directory containing the package relative to workspace root (e.g. libs/python/computer)" required: true type: string version: description: "Version to publish" required: true type: string base_package_name: description: "PyPI package name (e.g. cua-agent)" required: true type: string secrets: PYPI_TOKEN: required: true outputs: version: description: "The version that was published" value: ${{ jobs.build-and-publish.outputs.version }} jobs: build-and-publish: runs-on: macos-latest permissions: contents: read outputs: version: ${{ steps.set-version.outputs.version }} steps: - uses: actions/checkout@v4 with: ref: main fetch-depth: 0 # Full history for release creation - name: Ensure latest main branch run: | git fetch origin main git reset --hard origin/main echo "Current HEAD commit:" git log -1 --oneline - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.11" - name: Create root pdm.lock file run: | # Create an empty pdm.lock file in the root touch pdm.lock - name: Install PDM uses: pdm-project/setup-pdm@v3 with: python-version: "3.11" cache: true - name: Set version id: set-version run: | echo "VERSION=${{ inputs.version }}" >> $GITHUB_ENV echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT - name: Verify version consistency run: | # Install toml parser pip install toml # Verify version matches using script (exits with error if mismatch) python ${GITHUB_WORKSPACE}/.github/scripts/get_pyproject_version.py \ ${GITHUB_WORKSPACE}/${{ inputs.package_dir }}/pyproject.toml \ ${{ inputs.version }} - name: Initialize PDM in package directory run: | # Make sure we're working with a properly initialized PDM project cd ${{ inputs.package_dir }} # Create pdm.lock if it doesn't exist if [ ! -f "pdm.lock" ]; then echo "No pdm.lock found, initializing PDM project..." pdm lock fi - name: Build and publish env: PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} run: | cd ${{ inputs.package_dir }} # Build with PDM pdm build echo "Publishing ${{ inputs.base_package_name }} ${VERSION}" # Install and use twine directly instead of PDM publish echo "Installing twine for direct publishing..." pip install twine echo "Publishing to PyPI using twine..." TWINE_USERNAME="__token__" TWINE_PASSWORD="$PYPI_TOKEN" python -m twine upload dist/*