Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 64 additions & 7 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,86 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
# This workflow uploads a Python Package to PyPI when a GitHub release is created
# It works together with the copybara workflow that creates the release after code sync

name: Upload Python Package

on:
release:
types: [created]
types: [created, published]
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v2024.12.1)'
required: true
type: string
test_pypi:
description: 'Publish to Test PyPI instead of production'
required: false
type: boolean
default: false

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/zutil
permissions:
id-token: write
id-token: write # Required for trusted publishing

steps:
- uses: actions/checkout@v5
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name || inputs.tag }}

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.x"

- name: Extract version from tag
id: get_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
TEST_PYPI="${{ inputs.test_pypi }}"
else
TAG="${{ github.event.release.tag_name }}"
# Check if this is a test release (draft or prerelease)
if [ "${{ github.event.release.draft }}" = "true" ] || [ "${{ github.event.release.prerelease }}" = "true" ]; then
TEST_PYPI="true"
else
TEST_PYPI="false"
fi
fi
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
echo "test_pypi=$TEST_PYPI" >> $GITHUB_OUTPUT
echo "Building version from tag: $TAG (Test PyPI: $TEST_PYPI)"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel get-version --upgrade
- name: Build and publish

- name: Build package
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
RELEASE_VERSION: ${{ steps.get_version.outputs.tag_name }}
run: |
echo "📦 Building package for release: $RELEASE_VERSION"
python setup.py sdist bdist_wheel

- name: Verify package
run: |
echo "🔍 Checking built package"
pip install twine
python -m twine check dist/*

# Show package contents
echo "📋 Package contents:"
ls -la dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
repository-url: ${{ steps.get_version.outputs.test_pypi == 'true' && 'https://test.pypi.org/legacy/' || '' }}
131 changes: 131 additions & 0 deletions .github/workflows/zutil-pypi-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Create zUtil Release

on:
pull_request:
branches: [main]
types: [closed]
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v2024.12.1)'
required: true
type: string
test_mode:
description: 'Test mode - creates draft release and test tag'
required: false
type: boolean
default: false
pypi_test:
description: 'Publish to Test PyPI instead of production'
required: false
type: boolean
default: false

jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
if: |
(github.event.pull_request.merged == true &&
startsWith(github.head_ref, 'release/v')) ||
github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- name: Get release tag
id: get_tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
if [ "${{ inputs.test_mode }}" = "true" ]; then
# Add test suffix for test mode
TAG="${TAG}-test"
fi
else
# Extract tag from PR branch name (e.g., release/v2024.12.1 -> v2024.12.1)
TAG="${{ github.head_ref }}"
TAG="${TAG#release/}"
fi
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
echo "test_mode=${{ inputs.test_mode || 'false' }}" >> $GITHUB_OUTPUT
echo "pypi_test=${{ inputs.pypi_test || 'false' }}" >> $GITHUB_OUTPUT
echo "Processing release: $TAG"

- name: Verify version consistency
run: |
VERSION="${{ steps.get_tag.outputs.version }}"
echo "Expected version: $VERSION"

# The setup.py uses RELEASE_VERSION environment variable, so we just need to verify
# that the code was properly synced. We can check for any version files if they exist.
echo "✅ Version will be set via RELEASE_VERSION environment variable during build"

- name: Create and push Git tag
if: steps.get_tag.outputs.test_mode != 'true'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"

# Check if tag already exists
if git rev-parse "${{ steps.get_tag.outputs.tag_name }}" >/dev/null 2>&1; then
echo "Tag ${{ steps.get_tag.outputs.tag_name }} already exists, skipping tag creation"
else
git tag ${{ steps.get_tag.outputs.tag_name }}
git push origin ${{ steps.get_tag.outputs.tag_name }}
echo "Created and pushed tag: ${{ steps.get_tag.outputs.tag_name }}"
fi

- name: Create test Git tag
if: steps.get_tag.outputs.test_mode == 'true'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"

echo "🧪 Test mode: Creating temporary test tag"
# Force create/update the test tag (will be cleaned up)
git tag -f ${{ steps.get_tag.outputs.tag_name }}
git push -f origin ${{ steps.get_tag.outputs.tag_name }}
echo "Created test tag: ${{ steps.get_tag.outputs.tag_name }}"

- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.tag_name }}
release_name: zUtil ${{ steps.get_tag.outputs.tag_name }}${{ steps.get_tag.outputs.test_mode == 'true' && ' (TEST)' || '' }}
body: |
## zUtil Release ${{ steps.get_tag.outputs.tag_name }}${{ steps.get_tag.outputs.test_mode == 'true' && ' (TEST)' || '' }}

${{ steps.get_tag.outputs.test_mode == 'true' && '🧪 **This is a TEST release for validation purposes**' || '🎉 This release will be automatically published to PyPI!' }}

### Install this version:
```bash
${{ steps.get_tag.outputs.pypi_test == 'true' && 'pip install --index-url https://test.pypi.org/simple/ zutil==' || 'pip install zutil==' }}${{ steps.get_tag.outputs.version }}
```

### Changes:
This release was automatically synced from the zCFD repository.

${{ steps.get_tag.outputs.test_mode == 'true' && 'The PyPI package will be published to Test PyPI for validation.' || 'The PyPI package will be built and published automatically by the existing python-publish.yml workflow.' }}
draft: ${{ steps.get_tag.outputs.test_mode == 'true' }}
prerelease: ${{ steps.get_tag.outputs.test_mode == 'true' }}

- name: Cleanup test tag
if: steps.get_tag.outputs.test_mode == 'true'
run: |
echo "🧹 Test mode: Cleaning up test tag after 5 minutes"
sleep 300 # Wait 5 minutes for testing
git push origin --delete ${{ steps.get_tag.outputs.tag_name }} || echo "Test tag already cleaned up"

- name: Cleanup release branch
if: github.event.pull_request.merged == true
run: |
# Delete the release branch after successful merge and release creation
BRANCH_NAME="${{ github.head_ref }}"
git push origin --delete "$BRANCH_NAME" || echo "Branch already deleted"
echo "🧹 Cleaned up release branch: $BRANCH_NAME"
Loading
Loading