Skip to content

Commit 227b62e

Browse files
committed
Add version input handling for manual workflow triggers in CI
This commit enhances the GitHub Actions workflow by adding an input parameter for the package version during manual triggers. It includes logic to extract the version from release tags or use the provided input, ensuring that the version is set correctly for releases. This change improves the flexibility and usability of the publishing process.
1 parent 513ecbb commit 227b62e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on:
44
release:
55
types: [published]
66
workflow_dispatch: # Enable manual trigger.
7+
inputs:
8+
version:
9+
description: 'Package version to publish (e.g., 4.0.1). Required for manual triggers.'
10+
required: true
11+
type: string
712

813
jobs:
914
build-and-publish:
@@ -58,6 +63,40 @@ jobs:
5863
rm -rf dist/
5964
echo "✓ Cleaned dist/ directory"
6065
66+
- name: Extract version from release tag or input
67+
id: version
68+
run: |
69+
if [ "${{ github.event_name }}" = "release" ]; then
70+
# Extract from release tag
71+
VERSION="${{ github.event.release.tag_name }}"
72+
# Strip 'v' prefix if present
73+
VERSION="${VERSION#v}"
74+
echo "version=$VERSION" >> $GITHUB_OUTPUT
75+
echo "Extracted version from release tag: $VERSION"
76+
else
77+
# For workflow_dispatch, use the provided input
78+
VERSION="${{ github.event.inputs.version }}"
79+
if [ -z "$VERSION" ]; then
80+
echo "Error: Version is required for manual workflow_dispatch triggers"
81+
exit 1
82+
fi
83+
# Strip 'v' prefix if present (user might include it)
84+
VERSION="${VERSION#v}"
85+
echo "version=$VERSION" >> $GITHUB_OUTPUT
86+
echo "Using version from workflow input: $VERSION"
87+
fi
88+
89+
- name: Set version for release
90+
if: steps.version.outputs.version != ''
91+
run: |
92+
python -c "
93+
from pathlib import Path
94+
from python_package_folder.version import VersionManager
95+
version_manager = VersionManager(project_root=Path('.'))
96+
version_manager.set_version('${{ steps.version.outputs.version }}')
97+
print(f'✓ Set version to ${{ steps.version.outputs.version }}')
98+
"
99+
61100
- name: Build package
62101
run: uv build
63102

0 commit comments

Comments
 (0)