diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..b142a1b --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,113 @@ +name: Python CI/CD with Automatic and Manual Versioning + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + version: + description: 'Version to release (e.g., 2024.2.11)' + required: false + default: '' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + pip install -r requirements.txt + + - name: Run tests + run: | + python -m pip install pytest + pytest + + deploy: + runs-on: ubuntu-latest + + needs: build + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Determine Version to Release + id: determine_version + run: | + if [ -z "${{ github.event.inputs.version }}" ]; then + # No version provided, use version.txt + VERSION=$(cat version.txt) + else + # Use the manually provided version + VERSION="${{ github.event.inputs.version }}" + fi + echo "version=$VERSION" >> $GITHUB_ENV + + - name: Build distribution + run: | + python setup.py sdist bdist_wheel + + - name: Deploy to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + - name: Tag Release in GitHub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION=${{ env.version }} + git tag -a "$VERSION" -m "Release $VERSION" + git push origin "$VERSION" + + increment-version: + runs-on: ubuntu-latest + + needs: deploy + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Increment Version + id: increment_version + run: | + VERSION=${{ env.version }} + YEAR=$(date +%Y) + RELEASE=$(echo $VERSION | cut -d '.' -f 2) + + # Increment the release version after deployment + NEW_VERSION="$YEAR.$((RELEASE + 1)).1" + + echo $NEW_VERSION > version.txt + echo "new_version=$NEW_VERSION" >> $GITHUB_ENV + + sed -i "s/version=.*,/version='$NEW_VERSION',/" setup.py + + - name: Commit and Push Incremented Version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + git add version.txt setup.py + git commit -m "Increment version to ${{ env.new_version }}" + git push origin main diff --git a/.github/workflows/python-pr.yml b/.github/workflows/python-pr.yml new file mode 100644 index 0000000..c9a5537 --- /dev/null +++ b/.github/workflows/python-pr.yml @@ -0,0 +1,34 @@ +name: Test Pull Request + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run Tests + run: | + python -m pip install pytest + pytest + + - name: Report Test Results + if: failure() + run: | + echo "::error::Some tests failed. Check the logs for details." diff --git a/setup.py b/setup.py index 17bc4e0..e745ccb 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,12 @@ with open("README.md", "r") as f: long_description = f.read() +with open("version.txt", "r") as f: + version = f.read() + setup( name="watergate_local_api", # Replace with your own username - version="2024.2.1", + version=version, author="Watergate", author_email="hi@watergate.ai", description="Python package to interact with the Watergate Local API.", diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..4bb304e --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +2024.3.1 \ No newline at end of file