Skip to content

Commit

Permalink
feat: add change detection and version bump for pypi package
Browse files Browse the repository at this point in the history
  • Loading branch information
petscheit committed Sep 3, 2024
1 parent 42eb5d8 commit 271f670
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[bumpversion]
current_version = 0.0.7
commit = True
tag = True

[bumpversion:file:version.py]
55 changes: 47 additions & 8 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
name: Build, Push Docker Image, and Deploy Python Package
name: Build Docker and Push Python Package

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all history and tags

- name: Fetch all branches
run: |
git fetch --all
git fetch --tags
- name: Log in to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -61,19 +65,54 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools wheel twine bumpversion
- name: Check for package changes
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# Fetch base branch to compare with PR branch
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only ${{ github.base_ref }}...HEAD)
else
# Compare current commit with the previous commit
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
fi
echo "Changed files: $CHANGED_FILES"
if echo "$CHANGED_FILES" | grep -qE '(tools/|contract_bootloader/|compiled_contracts/|setup.py)'; then
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
else
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
fi
echo "Changes detected: $CHANGES_DETECTED"
- name: Debug output
run: |
echo "Event name: ${{ github.event_name }}"
echo "GitHub ref: ${{ github.ref }}"
echo "Changes detected: ${{ env.CHANGES_DETECTED }}"
- name: Bump version
if: env.CHANGES_DETECTED == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
bumpversion patch --allow-dirty
git push --tags
git push
- name: Build Python package
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
python setup.py sdist bdist_wheel
- name: Check PyPI package (dry run)
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
twine check dist/*
echo "Package check completed. In a real publish, the package would be uploaded to PyPI."
- name: Publish package to PyPI
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: steps.check_changes.outputs.changes_detected == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from setuptools import setup
from setuptools.command.install import install

from pathlib import Path

# Read version from version.py
version = {}
with open("version.py") as fp:
exec(fp.read(), version)

this_directory = Path(__file__).parent
long_description = (this_directory / "package.md").read_text()


class PostInstallCommand(install):
"""Custom post-installation for installation mode."""

def run(self):
# Run the standard install process first
install.run(self)


# Read the requirements from the requirements.txt file
with open("tools/make/requirements.txt") as requirements_file:
requirements = requirements_file.read().splitlines()
Expand All @@ -23,7 +23,7 @@ def run(self):
name="hdp-cairo-dev",
long_description=long_description,
long_description_content_type="text/markdown",
version="0.0.7",
version=version['__version__'],
packages=[
"tools",
"contract_bootloader",
Expand Down
1 change: 1 addition & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.7"

0 comments on commit 271f670

Please sign in to comment.