This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish FastVideo to PyPI on Version Change | |
on: | |
push: | |
branches: | |
- you-pypi-packaging-1 # or master, depending on your default branch | |
paths: | |
- 'pyproject.toml' # Trigger when pyproject.toml changes | |
jobs: | |
check-version-change: | |
runs-on: ubuntu-latest | |
outputs: | |
version-changed: ${{ steps.check-version.outputs.changed }} | |
new-version: ${{ steps.check-version.outputs.new-version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- name: Check if version changed | |
id: check-version | |
run: | | |
# Get current commit's version | |
NEW_VERSION=$(grep -oP 'version\s*=\s*"\K[^"]+' pyproject.toml) | |
echo "New version: $NEW_VERSION" | |
# Get previous version from git history | |
OLD_VERSION=$(git show HEAD~1:./pyproject.toml | grep -oP 'version\s*=\s*"\K[^"]+' || echo "0.0.0") | |
echo "Old version: $OLD_VERSION" | |
if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then | |
echo "Version changed from $OLD_VERSION to $NEW_VERSION" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
else | |
echo "Version did not change" | |
echo "changed=false" >> $GITHUB_OUTPUT | |
fi | |
build-publish-main: | |
needs: check-version-change | |
if: needs.check-version-change.outputs.version-changed == 'true' | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # Needed for OIDC Trusted Publishing | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build twine wheel | |
- name: Build package | |
run: | | |
python -m build | |
- name: Publish release distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: dist/ |