Skip to content

Commit

Permalink
Merge pull request #2085 from solliancenet/jdh-python-publishing
Browse files Browse the repository at this point in the history
Python package versioning and publishing
  • Loading branch information
ciprianjichici authored Dec 16, 2024
2 parents 2f44e1e + ddcbdad commit 0e6e1f7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Publish NuGet Packages
name: Publish NuGet & PyPi Packages

on:
workflow_dispatch:

env:
DOTNET_VERSION: '8.0.x'
PYTHON_VERSION: '3.11.x'

jobs:
build-and-publish:
Expand All @@ -27,10 +28,16 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Run versioning script
run: bash ./versioning.sh
id: versioning

# .NET Build and Pack Steps
- name: Build Common
working-directory: ./src/dotnet/Common
run: dotnet build --configuration Release -p:GITHUB_ACTIONS=true
Expand Down Expand Up @@ -63,6 +70,7 @@ jobs:
working-directory: ./src/dotnet/ManagementClient
run: dotnet pack --configuration Release /p:PackageVersion=${{ steps.versioning.outputs.version }} -p:GITHUB_ACTIONS=true --output ./nupkg

# .NET Publish Steps
- name: Publish Common to NuGet
working-directory: ./src/dotnet/Common
run: dotnet nuget push ./nupkg/*.Common.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
Expand All @@ -78,3 +86,19 @@ jobs:
- name: Publish ManagementClient to NuGet
working-directory: ./src/dotnet/ManagementClient
run: dotnet nuget push ./nupkg/*.Client.Management.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

# Python Build and Publish Steps
- name: Build Python Package
run: |
cd ./src/python/PythonSDK
python -m pip install --upgrade build
python -m build
- name: Publish Python Package to PyPI
working-directory: ./src/python/PythonSDK/dist
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_KEY }}
run: |
python -m pip install --upgrade twine
python -m twine upload --repository-url https://upload.pypi.org/legacy/ *.tar.gz *.whl
2 changes: 1 addition & 1 deletion src/python/PythonSDK/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "foundationallm"
version = "0.9.1a5"
version = "0.0.0"
authors = [
{ name="FoundationaLLM", email="[email protected]" },
]
Expand Down
24 changes: 21 additions & 3 deletions versioning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ else
VERSION="0.0.0"
fi

# Output version for GitHub Actions or other CI systems
# Convert .NET versioning to Python versioning
PYTHON_VERSION="$VERSION"
if [[ "$VERSION" =~ ([0-9]+\.[0-9]+\.[0-9]+)-alpha([0-9]+)$ ]]; then
PYTHON_VERSION="${BASH_REMATCH[1]}a${BASH_REMATCH[2]}"
elif [[ "$VERSION" =~ ([0-9]+\.[0-9]+\.[0-9]+)-beta([0-9]+)$ ]]; then
PYTHON_VERSION="${BASH_REMATCH[1]}b${BASH_REMATCH[2]}"
elif [[ "$VERSION" =~ ([0-9]+\.[0-9]+\.[0-9]+)-rc([0-9]+)$ ]]; then
PYTHON_VERSION="${BASH_REMATCH[1]}rc${BASH_REMATCH[2]}"
fi

# Output versions for GitHub Actions
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"
echo "python_version=$PYTHON_VERSION" >> "$GITHUB_OUTPUT"

echo "NuGet Version: $VERSION"
echo "Python Version: $PYTHON_VERSION"

# Replace the version placeholders in the .csproj files
# Replace the version placeholders in the .csproj files for .NET projects
for csproj in $(find . -name '*.csproj'); do
sed -i "s/<Version>0.0.0<\/Version>/<Version>$VERSION<\/Version>/" "$csproj"
sed -i "s/<FileVersion>0.0.0<\/FileVersion>/<FileVersion>${VERSION%-*}<\/FileVersion>/" "$csproj"
sed -i "s/<AssemblyVersion>0.0.0<\/AssemblyVersion>/<AssemblyVersion>${VERSION%-*}<\/AssemblyVersion>/" "$csproj"
done

# Replace the version in pyproject.toml files for Python projects
for toml in $(find . -name 'pyproject.toml'); do
sed -i "s/^version = \".*\"/version = \"$PYTHON_VERSION\"/" "$toml"
done

0 comments on commit 0e6e1f7

Please sign in to comment.